teldrive/pkg/models/file.go

44 lines
1.2 KiB
Go
Raw Normal View History

2023-08-07 03:32:46 +08:00
package models
import (
2023-08-13 04:15:19 +08:00
"database/sql/driver"
"encoding/json"
2023-08-07 03:32:46 +08:00
"time"
)
type File struct {
2023-08-14 04:58:06 +08:00
ID string `gorm:"type:text;primaryKey;default:generate_uid(16)"`
Name string `gorm:"type:text;not null"`
Type string `gorm:"type:text;not null"`
MimeType string `gorm:"type:text;not null"`
Path string `gorm:"type:text;index"`
2023-12-03 03:47:23 +08:00
Size *int64 `gorm:"type:bigint"`
Starred bool `gorm:"default:false"`
2023-08-13 04:15:19 +08:00
Depth *int `gorm:"type:integer"`
2023-12-08 05:46:06 +08:00
Encrypted bool `gorm:"default:false"`
2023-08-22 23:00:14 +08:00
UserID int64 `gorm:"type:bigint;not null"`
2023-08-14 04:58:06 +08:00
Status string `gorm:"type:text"`
ParentID string `gorm:"type:text;index"`
Parts *Parts `gorm:"type:jsonb"`
ChannelID *int64 `gorm:"type:bigint"`
2023-08-13 04:15:19 +08:00
CreatedAt time.Time `gorm:"default:timezone('utc'::text, now())"`
UpdatedAt time.Time `gorm:"default:timezone('utc'::text, now())"`
}
type Parts []Part
type Part struct {
ID int64 `json:"id"`
Salt string `json:"salt,omitempty"`
2023-08-13 04:15:19 +08:00
}
func (a Parts) Value() (driver.Value, error) {
return json.Marshal(a)
}
func (a *Parts) Scan(value interface{}) error {
if err := json.Unmarshal(value.([]byte), &a); err != nil {
return err
}
return nil
2023-08-07 03:32:46 +08:00
}