(ctx context.Context, rc requestContext)
| 12 | ) |
| 13 | |
| 14 | func handleObjectGet(ctx context.Context, rc requestContext) { |
| 15 | oidstr := rc.muxVar("objectID") |
| 16 | |
| 17 | if !requireUIUser(ctx, rc) { |
| 18 | http.Error(rc.w, "access denied", http.StatusForbidden) |
| 19 | return |
| 20 | } |
| 21 | |
| 22 | oid, err := object.ParseID(oidstr) |
| 23 | if err != nil { |
| 24 | http.Error(rc.w, "invalid object id", http.StatusBadRequest) |
| 25 | return |
| 26 | } |
| 27 | |
| 28 | obj, err := rc.rep.OpenObject(ctx, oid) |
| 29 | if errors.Is(err, object.ErrObjectNotFound) { |
| 30 | http.Error(rc.w, "object not found", http.StatusNotFound) |
| 31 | return |
| 32 | } |
| 33 | |
| 34 | if snapshotfs.IsDirectoryID(oid) { |
| 35 | rc.w.Header().Set("Content-Type", "application/json") |
| 36 | } |
| 37 | |
| 38 | fname := oid.String() |
| 39 | if p := rc.queryParam("fname"); p != "" { |
| 40 | fname = p |
| 41 | rc.w.Header().Set("Content-Disposition", "attachment; filename=\""+p+"\"") |
| 42 | } |
| 43 | |
| 44 | mtime := clock.Now() |
| 45 | |
| 46 | if p := rc.queryParam("mtime"); p != "" { |
| 47 | if m, err := time.Parse(time.RFC3339Nano, p); err == nil { |
| 48 | mtime = m |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | http.ServeContent(rc.w, rc.req, fname, mtime, obj) |
| 53 | } |
nothing calls this directly
no test coverage detected