2023-03-22 22:45:17 +08:00
|
|
|
package model
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"net/url"
|
|
|
|
"octopus/internal/dal"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/rs/xid"
|
|
|
|
"gorm.io/gorm"
|
|
|
|
)
|
|
|
|
|
|
|
|
const TableNameDocFolder = "doc_folders"
|
|
|
|
const TableNameDoc = "docs"
|
|
|
|
|
|
|
|
type DocFolder struct {
|
|
|
|
Base
|
|
|
|
Name string `gorm:"column:name;type:varchar;not null"` // 文件夹名称
|
|
|
|
IsDeletable bool `gorm:"column:is_deletable;type:boolean;not null;default:true"` // 是否允许被删除
|
|
|
|
IsEditable bool `gorm:"column:is_editable;type:boolean;not null;default:true"` // 是否允许被修改
|
|
|
|
Path string `gorm:"column:path;type:varchar;index:idx_path"` // 路径索引
|
|
|
|
CreatedBy string `gorm:"column:created_by;type:varchar;not null"` // 创建人
|
|
|
|
}
|
|
|
|
|
|
|
|
func (*DocFolder) TableName() string {
|
|
|
|
return TableNameDocFolder
|
|
|
|
}
|
|
|
|
func (df *DocFolder) BeforeCreate(*gorm.DB) error {
|
|
|
|
df.ID = xid.New().String()
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type Doc struct {
|
|
|
|
Base
|
|
|
|
Name string `gorm:"column:name;type:varchar;not null"` // 文件夹名称
|
|
|
|
IsDeletable bool `gorm:"column:is_deletable;type:boolean;not null;default:true"` // 是否允许被删除
|
|
|
|
IsEditable bool `gorm:"column:is_editable;type:boolean;not null;default:true"` // 是否允许编辑名称
|
|
|
|
FolderID string `gorm:"column:folder_id;type:varchar;index:idx_folder_id"` // 文件夹ID
|
2023-03-23 13:52:44 +08:00
|
|
|
ObjectName string `gorm:"column:object_name;type:varchar"` // 对象存储中对应的object_name
|
2023-03-22 22:45:17 +08:00
|
|
|
CreatedBy string `gorm:"column:created_by;type:varchar;not null"` // 创建人
|
|
|
|
|
|
|
|
Folder *DocFolder `gorm:"foreignKey:FolderID;references:ID"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (df *Doc) PresignedURL(ctx context.Context) (*url.URL, error) {
|
2023-03-23 13:52:44 +08:00
|
|
|
return dal.GetStorage().PresignedGetObject(ctx, df.ObjectName, time.Hour)
|
2023-03-22 22:45:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (*Doc) TableName() string {
|
|
|
|
return TableNameDocFolder
|
|
|
|
}
|
|
|
|
func (df *Doc) BeforeCreate(*gorm.DB) error {
|
|
|
|
df.ID = xid.New().String()
|
|
|
|
return nil
|
|
|
|
}
|