Interactive/pkg/models/attachments.go

44 lines
1.0 KiB
Go
Raw Normal View History

2024-02-04 10:40:20 +00:00
package models
import (
"fmt"
"path/filepath"
2024-03-10 10:38:42 +00:00
"github.com/spf13/viper"
2024-02-04 10:40:20 +00:00
)
2024-03-02 17:23:11 +00:00
type AttachmentType = uint8
const (
AttachmentOthers = AttachmentType(iota)
AttachmentPhoto
AttachmentVideo
AttachmentAudio
)
2024-02-04 10:40:20 +00:00
type Attachment struct {
BaseModel
2024-03-02 17:23:11 +00:00
FileID string `json:"file_id"`
Filesize int64 `json:"filesize"`
Filename string `json:"filename"`
Mimetype string `json:"mimetype"`
2024-03-24 11:01:18 +00:00
Hashcode string `json:"hashcode"`
2024-03-02 17:23:11 +00:00
Type AttachmentType `json:"type"`
ExternalUrl string `json:"external_url"`
Author Account `json:"author"`
ArticleID *uint `json:"article_id"`
MomentID *uint `json:"moment_id"`
CommentID *uint `json:"comment_id"`
AuthorID uint `json:"author_id"`
2024-02-04 10:40:20 +00:00
}
func (v Attachment) GetStoragePath() string {
basepath := viper.GetString("content")
return filepath.Join(basepath, v.FileID)
}
func (v Attachment) GetAccessPath() string {
return fmt.Sprintf("/api/attachments/o/%s", v.FileID)
}