2024-05-17 15:59:51 +08:00
|
|
|
package models
|
|
|
|
|
2024-08-18 12:01:41 +08:00
|
|
|
import (
|
|
|
|
"time"
|
2024-09-11 23:55:46 +08:00
|
|
|
|
2024-12-25 23:52:00 +08:00
|
|
|
"git.solsynth.dev/hypernet/nexus/pkg/nex/cruda"
|
|
|
|
|
2024-09-11 23:55:46 +08:00
|
|
|
"gorm.io/datatypes"
|
2024-08-18 12:01:41 +08:00
|
|
|
)
|
2024-05-17 15:59:51 +08:00
|
|
|
|
2024-07-28 21:03:56 +08:00
|
|
|
const (
|
2024-11-06 23:01:29 +08:00
|
|
|
AttachmentDstTemporary = 0 // The destination 0 is a reserved config for pre-upload processing
|
2024-07-28 21:03:56 +08:00
|
|
|
)
|
|
|
|
|
2024-12-28 13:31:31 +08:00
|
|
|
const (
|
|
|
|
AttachmentTypeNormal = iota
|
|
|
|
AttachmentTypeThumbnail
|
|
|
|
AttachmentTypeCompressed
|
|
|
|
)
|
|
|
|
|
2024-05-17 15:59:51 +08:00
|
|
|
type Attachment struct {
|
2024-10-27 13:13:40 +08:00
|
|
|
cruda.BaseModel
|
2024-05-17 15:59:51 +08:00
|
|
|
|
2024-08-18 14:09:52 +08:00
|
|
|
// Random ID is for accessing (appear in URL)
|
|
|
|
Rid string `json:"rid" gorm:"uniqueIndex"`
|
|
|
|
// Unique ID is for storing (appear in local file name or object name)
|
|
|
|
Uuid string `json:"uuid"`
|
|
|
|
|
2024-11-06 23:01:29 +08:00
|
|
|
Size int64 `json:"size"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Alternative string `json:"alt"`
|
|
|
|
MimeType string `json:"mimetype"`
|
|
|
|
HashCode string `json:"hash"`
|
|
|
|
Destination int `json:"destination"`
|
|
|
|
RefCount int `json:"ref_count"`
|
2024-05-17 15:59:51 +08:00
|
|
|
|
2024-08-20 17:08:40 +08:00
|
|
|
FileChunks datatypes.JSONMap `json:"file_chunks"`
|
|
|
|
|
2024-08-18 12:01:41 +08:00
|
|
|
CleanedAt *time.Time `json:"cleaned_at"`
|
|
|
|
|
2024-12-26 21:53:09 +08:00
|
|
|
Metadata datatypes.JSONMap `json:"metadata"` // This field is analyzer auto generated metadata
|
|
|
|
Usermeta datatypes.JSONMap `json:"usermeta"` // This field is user set metadata
|
|
|
|
|
2024-12-28 13:31:31 +08:00
|
|
|
ContentRating int `json:"content_rating"` // This field use to filter mature content or not
|
|
|
|
QualityRating int `json:"quality_rating"` // This field use to filter good content or not
|
2024-12-26 21:53:09 +08:00
|
|
|
|
|
|
|
IsAnalyzed bool `json:"is_analyzed"`
|
|
|
|
IsSelfRef bool `json:"is_self_ref"`
|
|
|
|
IsIndexable bool `json:"is_indexable"` // Show this attachment in the public directory api or not
|
2024-05-17 15:59:51 +08:00
|
|
|
|
2024-12-28 13:31:31 +08:00
|
|
|
UsedCount int `json:"used_count"`
|
|
|
|
|
|
|
|
Thumbnail *Attachment `json:"thumbnail"`
|
|
|
|
ThumbnailID *uint `json:"thumbnail_id"`
|
|
|
|
Compressed *Attachment `json:"compressed"`
|
|
|
|
CompressedID *uint `json:"compressed_id"`
|
|
|
|
|
2024-07-29 00:01:51 +08:00
|
|
|
Ref *Attachment `json:"ref"`
|
|
|
|
RefID *uint `json:"ref_id"`
|
|
|
|
|
2024-08-18 12:01:41 +08:00
|
|
|
Pool *AttachmentPool `json:"pool"`
|
|
|
|
PoolID *uint `json:"pool_id"`
|
|
|
|
|
2024-11-03 01:53:57 +08:00
|
|
|
AccountID uint `json:"account_id"`
|
2024-12-26 22:41:11 +08:00
|
|
|
|
|
|
|
// Outdated fields, just for backward compatibility
|
2024-12-28 13:31:31 +08:00
|
|
|
IsMature bool `json:"is_mature" gorm:"-"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// Data model for in progress multipart attachments
|
|
|
|
type AttachmentFragment struct {
|
|
|
|
cruda.BaseModel
|
|
|
|
|
|
|
|
// Random ID is for accessing (appear in URL)
|
|
|
|
Rid string `json:"rid" gorm:"uniqueIndex"`
|
|
|
|
// Unique ID is for storing (appear in local file name or object name)
|
|
|
|
Uuid string `json:"uuid"`
|
|
|
|
|
|
|
|
Size int64 `json:"size"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Alternative string `json:"alt"`
|
|
|
|
MimeType string `json:"mimetype"`
|
|
|
|
HashCode string `json:"hash"`
|
|
|
|
Fingerprint *string `json:"fingerprint"` // Client side generated hash, for continue uploading
|
|
|
|
|
|
|
|
FileChunks datatypes.JSONMap `json:"file_chunks"`
|
|
|
|
|
|
|
|
Metadata datatypes.JSONMap `json:"metadata"` // This field is analyzer auto generated metadata
|
|
|
|
Usermeta datatypes.JSONMap `json:"usermeta"` // This field is user set metadata
|
|
|
|
|
|
|
|
Pool *AttachmentPool `json:"pool"`
|
|
|
|
PoolID *uint `json:"pool_id"`
|
|
|
|
|
|
|
|
AccountID uint `json:"account_id"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v AttachmentFragment) ToAttachment() Attachment {
|
|
|
|
return Attachment{
|
|
|
|
Rid: v.Rid,
|
|
|
|
Uuid: v.Uuid,
|
|
|
|
Size: v.Size,
|
|
|
|
Name: v.Name,
|
|
|
|
Alternative: v.Alternative,
|
|
|
|
MimeType: v.MimeType,
|
|
|
|
HashCode: v.HashCode,
|
|
|
|
Metadata: v.Metadata,
|
|
|
|
Usermeta: v.Usermeta,
|
|
|
|
Destination: AttachmentDstTemporary,
|
|
|
|
Pool: v.Pool,
|
|
|
|
PoolID: v.PoolID,
|
|
|
|
AccountID: v.AccountID,
|
|
|
|
}
|
2024-05-17 15:59:51 +08:00
|
|
|
}
|