Feat: insert file record to database

This commit is contained in:
HFO4
2019-11-20 15:24:26 +08:00
parent e835dafc88
commit e09294d388
4 changed files with 35 additions and 4 deletions

View File

@@ -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
}
/* ================