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

Function directObjectURL

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

Source from the content-addressed store, hash-verified

38}
39
40func directObjectURL(r *http.Request, authPairs map[string]string) (string, bool) {
41 if r.Method != http.MethodGet {
42 return "", false
43 }
44 if hasNonObjectQuery(r) || !s3RequestAuthorized(r, authPairs) {
45 return "", false
46 }
47 bucketName, objectName, ok := parseObjectPath(r.URL.Path)
48 if !ok {
49 return "", false
50 }
51 bucket, err := getBucketByName(bucketName)
52 if err != nil {
53 return "", false
54 }
55 reqPath := path.Join(bucket.Path, objectName)
56 meta, _ := op.GetNearestMeta(reqPath)
57 ctx := context.WithValue(r.Context(), conf.MetaKey, meta)
58 storage, err := fs.GetStorage(reqPath, &fs.GetStoragesArgs{})
59 if err != nil || common.ShouldProxy(storage, path.Base(reqPath)) {
60 return "", false
61 }
62 link, file, err := fs.Link(ctx, reqPath, model.LinkArgs{
63 IP: utils.ClientIP(r),
64 Header: r.Header,
65 Redirect: true,
66 })
67 if err != nil {
68 return "", false
69 }
70 defer link.Close()
71 if file == nil || file.IsDir() || link.URL == "" || link.RangeReader != nil {
72 return "", false
73 }
74 return link.URL, true
75}
76
77func directUploadURL(r *http.Request, authPairs map[string]string) (string, bool) {
78 if r.Method != http.MethodPut || r.ContentLength < 0 {

Callers 1

redirectHandlerFunction · 0.85

Calls 11

GetNearestMetaFunction · 0.92
GetStorageFunction · 0.92
ShouldProxyFunction · 0.92
LinkFunction · 0.92
ClientIPFunction · 0.92
hasNonObjectQueryFunction · 0.85
s3RequestAuthorizedFunction · 0.85
parseObjectPathFunction · 0.85
getBucketByNameFunction · 0.85
CloseMethod · 0.65
IsDirMethod · 0.65

Tested by

no test coverage detected