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

Function directUploadURL

server/s3/redirect.go:77–118  ·  view source on GitHub ↗
(r *http.Request, authPairs map[string]string)

Source from the content-addressed store, hash-verified

75}
76
77func directUploadURL(r *http.Request, authPairs map[string]string) (string, bool) {
78 if r.Method != http.MethodPut || r.ContentLength < 0 {
79 return "", false
80 }
81 if hasNonObjectQuery(r) || !s3RequestAuthorized(r, authPairs) {
82 return "", false
83 }
84 if r.Header.Get("X-Amz-Copy-Source") != "" ||
85 r.Header.Get("X-Amz-Content-Sha256") == "STREAMING-AWS4-HMAC-SHA256-PAYLOAD" {
86 return "", false
87 }
88 bucketName, objectName, ok := parseObjectPath(r.URL.Path)
89 if !ok || strings.HasSuffix(objectName, "/") {
90 return "", false
91 }
92 bucket, err := getBucketByName(bucketName)
93 if err != nil {
94 return "", false
95 }
96 reqPath := path.Join(bucket.Path, objectName)
97 storage, dstDirActualPath, err := op.GetStorageAndActualPath(path.Dir(reqPath))
98 if err != nil || storage.Config().NoUpload {
99 return "", false
100 }
101 info, err := op.GetDirectUploadInfo(r.Context(), "HttpDirect", storage, dstDirActualPath, path.Base(reqPath), r.ContentLength, true)
102 if err != nil {
103 return "", false
104 }
105 httpInfo, ok := asHTTPDirectUploadInfo(info)
106 if !ok {
107 return "", false
108 }
109 method := httpInfo.Method
110 if method == "" {
111 method = http.MethodPut
112 }
113 if !strings.EqualFold(method, http.MethodPut) || httpInfo.UploadURL == "" ||
114 httpInfo.ChunkSize > 0 || len(httpInfo.Headers) > 0 {
115 return "", false
116 }
117 return httpInfo.UploadURL, true
118}
119
120func asHTTPDirectUploadInfo(info any) (*model.HttpDirectUploadInfo, bool) {
121 switch v := info.(type) {

Callers 1

redirectHandlerFunction · 0.85

Calls 9

GetStorageAndActualPathFunction · 0.92
GetDirectUploadInfoFunction · 0.92
hasNonObjectQueryFunction · 0.85
s3RequestAuthorizedFunction · 0.85
parseObjectPathFunction · 0.85
getBucketByNameFunction · 0.85
asHTTPDirectUploadInfoFunction · 0.85
GetMethod · 0.65
ConfigMethod · 0.65

Tested by

no test coverage detected