mirror of
https://github.com/halejohn/Cloudreve.git
synced 2026-01-26 17:41:57 +08:00
Modify: re-organize structure of filesystem
This commit is contained in:
34
pkg/filesystem/file.go
Normal file
34
pkg/filesystem/file.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package filesystem
|
||||
|
||||
import (
|
||||
"context"
|
||||
model "github.com/HFO4/cloudreve/models"
|
||||
)
|
||||
|
||||
/* ============
|
||||
文件相关
|
||||
============
|
||||
*/
|
||||
|
||||
// AddFile 新增文件记录
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user