mirror of
https://github.com/halejohn/Cloudreve.git
synced 2026-01-26 09:34:57 +08:00
Feat: mount storage policy for folders in WebDAV
This commit is contained in:
@@ -113,6 +113,10 @@ func (handler Driver) Delete(ctx context.Context, files []string) ([]string, err
|
||||
failed = append(failed, v.Key)
|
||||
}
|
||||
|
||||
if len(failed) == 0 {
|
||||
return failed, nil
|
||||
}
|
||||
|
||||
return failed, errors.New("删除失败")
|
||||
}
|
||||
|
||||
|
||||
@@ -190,6 +190,9 @@ func (fs *FileSystem) Delete(ctx context.Context, dirs, files []uint) error {
|
||||
return ErrDBDeleteObjects.WithError(err)
|
||||
}
|
||||
|
||||
// 删除文件记录对应的分享记录
|
||||
model.DeleteShareBySourceIDs(allFileIDs, false)
|
||||
|
||||
// 归还容量
|
||||
var total uint64
|
||||
for _, value := range totalStorage {
|
||||
@@ -207,6 +210,9 @@ func (fs *FileSystem) Delete(ctx context.Context, dirs, files []uint) error {
|
||||
return ErrDBDeleteObjects.WithError(err)
|
||||
}
|
||||
|
||||
// 删除目录记录对应的分享记录
|
||||
model.DeleteShareBySourceIDs(allFolderIDs, true)
|
||||
|
||||
if notDeleted := len(fs.FileTarget) - len(deletedFileIDs); notDeleted > 0 {
|
||||
return serializer.NewError(
|
||||
serializer.CodeNotFullySuccess,
|
||||
|
||||
@@ -172,7 +172,7 @@ func (fs *FileSystem) GetUploadToken(ctx context.Context, path string, size uint
|
||||
serializer.UploadSession{
|
||||
Key: callbackKey,
|
||||
UID: fs.User.ID,
|
||||
PolicyID: fs.User.GetPolicyID(),
|
||||
PolicyID: fs.User.GetPolicyID(0),
|
||||
VirtualPath: path,
|
||||
Name: name,
|
||||
Size: size,
|
||||
|
||||
@@ -48,8 +48,8 @@ func moveFiles(ctx context.Context, fs *filesystem.FileSystem, src FileInfo, dst
|
||||
} else {
|
||||
err = fs.Move(
|
||||
ctx,
|
||||
fileIDs,
|
||||
folderIDs,
|
||||
fileIDs,
|
||||
src.GetPosition(),
|
||||
path.Dir(dst),
|
||||
)
|
||||
@@ -81,7 +81,7 @@ func copyFiles(ctx context.Context, fs *filesystem.FileSystem, src FileInfo, dst
|
||||
return http.StatusInternalServerError, err
|
||||
}
|
||||
} else {
|
||||
err := fs.Copy(ctx, []uint{src.(*model.File).ID}, []uint{}, src.(*model.File).Position, dst)
|
||||
err := fs.Copy(ctx, []uint{}, []uint{src.(*model.File).ID}, src.(*model.File).Position, path.Dir(dst))
|
||||
if err != nil {
|
||||
return http.StatusInternalServerError, err
|
||||
}
|
||||
|
||||
@@ -356,6 +356,17 @@ func (h *Handler) handlePut(w http.ResponseWriter, r *http.Request, fs *filesyst
|
||||
fs.Use("AfterValidateFailed", filesystem.HookGiveBackCapacity)
|
||||
ctx = context.WithValue(ctx, fsctx.FileModelCtx, *originFile)
|
||||
} else {
|
||||
// 检查父目录指定存储策略
|
||||
if exist, folder := fs.IsPathExist(filePath); exist {
|
||||
if folder.PolicyID != 0 {
|
||||
// 尝试获取并重设存储策略
|
||||
if policy, err := model.GetPolicyByID(fs.User.GetPolicyID(folder.PolicyID)); err == nil {
|
||||
fs.User.Policy = policy
|
||||
fs.DispatchHandler()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 给文件系统分配钩子
|
||||
fs.Use("BeforeUpload", filesystem.HookValidateFile)
|
||||
fs.Use("BeforeUpload", filesystem.HookValidateCapacity)
|
||||
|
||||
Reference in New Issue
Block a user