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-05-15 11:45:49 +00:00
|
|
|
FileID string `json:"file_id"`
|
|
|
|
Filesize int64 `json:"filesize"`
|
|
|
|
Filename string `json:"filename"`
|
|
|
|
Mimetype string `json:"mimetype"`
|
|
|
|
Hashcode string `json:"hashcode"`
|
|
|
|
Type AttachmentType `json:"type"`
|
|
|
|
Author Account `json:"author"`
|
|
|
|
AuthorID uint `json:"author_id"`
|
|
|
|
|
|
|
|
PostID *uint `json:"post_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)
|
|
|
|
}
|