mirror of
https://github.com/halejohn/Cloudreve.git
synced 2026-01-27 10:01:56 +08:00
Feat: insert file record to database
This commit is contained in:
@@ -79,8 +79,26 @@ func NewFileSystem(user *model.User) (*FileSystem, error) {
|
||||
*/
|
||||
|
||||
// AddFile 新增文件记录
|
||||
func (fs *FileSystem) AddFile(parent *model.Folder) error {
|
||||
return nil
|
||||
func (fs *FileSystem) AddFile(ctx context.Context, parent *model.Folder) (*model.File, error) {
|
||||
file := ctx.Value(FileHeaderCtx).(FileHeader)
|
||||
filePath := ctx.Value(SavePathCtx).(string)
|
||||
|
||||
newFile := model.File{
|
||||
Name: file.GetFileName(),
|
||||
SourceName: filePath,
|
||||
UserID: fs.User.ID,
|
||||
Size: file.GetSize(),
|
||||
FolderID: parent.ID,
|
||||
PolicyID: fs.User.Policy.ID,
|
||||
Dir: parent.PositionAbsolute,
|
||||
}
|
||||
_, err := newFile.Create()
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &newFile, nil
|
||||
}
|
||||
|
||||
/* ================
|
||||
|
||||
@@ -73,10 +73,12 @@ func GenericAfterUpload(ctx context.Context, fs *FileSystem) error {
|
||||
}
|
||||
|
||||
// 向数据库中插入记录
|
||||
err := fs.AddFile(&folder)
|
||||
_, err := fs.AddFile(ctx, &folder)
|
||||
if err != nil {
|
||||
return errors.New("无法插入文件记录")
|
||||
}
|
||||
|
||||
// 异步尝试生成缩略图
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -35,8 +35,11 @@ var colors = map[string]func(a ...interface{}) string{
|
||||
|
||||
// Println 打印
|
||||
func (ll *Logger) Println(prefix string, msg string) {
|
||||
// TODO Release时去掉
|
||||
color.NoColor = false
|
||||
|
||||
c := color.New()
|
||||
_, _ = c.Printf("%s %s %s\n", colors[prefix]("["+prefix+"]"), time.Now().Format("2006-01-02 15:04:05 -0700"), msg)
|
||||
_, _ = c.Printf("%s %s %s\n", colors[prefix]("["+prefix+"]"), time.Now().Format("2006-01-02 15:04:05"), msg)
|
||||
}
|
||||
|
||||
// Panic 极端错误
|
||||
|
||||
Reference in New Issue
Block a user