MCPcopy Create free account
hub / github.com/OpenListTeam/OpenList / FsGetDirectUploadInfo

Function FsGetDirectUploadInfo

server/handles/direct_upload.go:24–70  ·  view source on GitHub ↗

FsGetDirectUploadInfo returns the direct upload info if supported by the driver If the driver does not support direct upload, returns null for upload_info

(c *gin.Context)

Source from the content-addressed store, hash-verified

22// FsGetDirectUploadInfo returns the direct upload info if supported by the driver
23// If the driver does not support direct upload, returns null for upload_info
24func FsGetDirectUploadInfo(c *gin.Context) {
25 var req FsGetDirectUploadInfoReq
26 if err := c.ShouldBind(&req); err != nil {
27 common.ErrorResp(c, err, 400)
28 return
29 }
30 // Decode path
31 path, err := url.PathUnescape(req.Path)
32 if err != nil {
33 common.ErrorResp(c, err, 400)
34 return
35 }
36 // Get user and join path
37 user := c.Request.Context().Value(conf.UserKey).(*model.User)
38 path, err = user.JoinPath(path)
39 if err != nil {
40 common.ErrorResp(c, err, 403)
41 return
42 }
43 if err := checkRelativePath(req.FileName); err != nil {
44 common.ErrorResp(c, err, 403)
45 return
46 }
47 overwrite := c.GetHeader("Overwrite") != "false"
48 dstPath := stdpath.Join(path, req.FileName)
49 if !overwrite {
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 {
56 common.ErrorStrResp(c, "file exists", 403)
57 return
58 }
59 }
60 directUploadInfo, err := fs.GetDirectUploadInfo(c, req.Tool, path, req.FileName, req.FileSize, overwrite)
61 if err != nil {
62 if !overwrite && errs.IsObjectAlreadyExists(err) {
63 common.ErrorStrResp(c, "file exists", 403)
64 return
65 }
66 common.ErrorResp(c, err, 500)
67 return
68 }
69 common.SuccessResp(c, directUploadInfo)
70}

Callers

nothing calls this directly

Calls 9

ErrorRespFunction · 0.92
GetFunction · 0.92
IsObjectNotFoundFunction · 0.92
ErrorStrRespFunction · 0.92
GetDirectUploadInfoFunction · 0.92
IsObjectAlreadyExistsFunction · 0.92
SuccessRespFunction · 0.92
checkRelativePathFunction · 0.85
JoinPathMethod · 0.80

Tested by

no test coverage detected