(r *http.Request, authPairs map[string]string)
| 38 | } |
| 39 | |
| 40 | func 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 | |
| 77 | func directUploadURL(r *http.Request, authPairs map[string]string) (string, bool) { |
| 78 | if r.Method != http.MethodPut || r.ContentLength < 0 { |
no test coverage detected