@@ -2,8 +2,10 @@ package handles
22
33import (
44 "net/url"
5+ stdpath "path"
56
67 "github.com/OpenListTeam/OpenList/v4/internal/conf"
8+ "github.com/OpenListTeam/OpenList/v4/internal/errs"
79 "github.com/OpenListTeam/OpenList/v4/internal/fs"
810 "github.com/OpenListTeam/OpenList/v4/internal/model"
911 "github.com/OpenListTeam/OpenList/v4/server/common"
@@ -38,15 +40,29 @@ func FsGetDirectUploadInfo(c *gin.Context) {
3840 common .ErrorResp (c , err , 403 )
3941 return
4042 }
43+ if err := checkRelativePath (req .FileName ); err != nil {
44+ common .ErrorResp (c , err , 403 )
45+ return
46+ }
4147 overwrite := c .GetHeader ("Overwrite" ) != "false"
48+ dstPath := stdpath .Join (path , req .FileName )
4249 if ! overwrite {
43- if res , _ := fs .Get (c .Request .Context (), path , & fs.GetArgs {NoLog : true }); res != nil {
50+ res , err := fs .Get (c .Request .Context (), dstPath , & fs.GetArgs {NoLog : true })
51+ if err != nil && ! errs .IsObjectNotFound (err ) {
52+ common .ErrorResp (c , err , 500 )
53+ return
54+ }
55+ if res != nil {
4456 common .ErrorStrResp (c , "file exists" , 403 )
4557 return
4658 }
4759 }
48- directUploadInfo , err := fs .GetDirectUploadInfo (c , req .Tool , path , req .FileName , req .FileSize )
60+ directUploadInfo , err := fs .GetDirectUploadInfo (c , req .Tool , path , req .FileName , req .FileSize , overwrite )
4961 if err != nil {
62+ if ! overwrite && errs .IsObjectAlreadyExists (err ) {
63+ common .ErrorStrResp (c , "file exists" , 403 )
64+ return
65+ }
5066 common .ErrorResp (c , err , 500 )
5167 return
5268 }
0 commit comments