diff options
Diffstat (limited to 'cmd/git-lfs-server')
| -rw-r--r-- | cmd/git-lfs-server/main.go | 32 |
1 files changed, 7 insertions, 25 deletions
diff --git a/cmd/git-lfs-server/main.go b/cmd/git-lfs-server/main.go index 5e99288..c76c5d9 100644 --- a/cmd/git-lfs-server/main.go +++ b/cmd/git-lfs-server/main.go | |||
| @@ -14,7 +14,6 @@ import ( | |||
| 14 | "path" | 14 | "path" |
| 15 | "regexp" | 15 | "regexp" |
| 16 | "slices" | 16 | "slices" |
| 17 | "strconv" | ||
| 18 | "strings" | 17 | "strings" |
| 19 | "time" | 18 | "time" |
| 20 | "unicode" | 19 | "unicode" |
| @@ -54,29 +53,13 @@ type batchRequest struct { | |||
| 54 | HashAlgo hashAlgo `json:"hash_algo,omitempty"` | 53 | HashAlgo hashAlgo `json:"hash_algo,omitempty"` |
| 55 | } | 54 | } |
| 56 | 55 | ||
| 57 | type RFC3339SecondsTime time.Time | ||
| 58 | |||
| 59 | func (t RFC3339SecondsTime) MarshalJSON() ([]byte, error) { | ||
| 60 | b := make([]byte, 0, len(time.RFC3339)+len(`""`)) | ||
| 61 | b = append(b, '"') | ||
| 62 | b = time.Time(t).AppendFormat(b, time.RFC3339) | ||
| 63 | b = append(b, '"') | ||
| 64 | return b, nil | ||
| 65 | } | ||
| 66 | |||
| 67 | type SecondDuration time.Duration | ||
| 68 | |||
| 69 | func (d SecondDuration) MarshalJSON() ([]byte, error) { | ||
| 70 | var b []byte | ||
| 71 | b = strconv.AppendInt(b, int64(time.Duration(d).Seconds()), 10) | ||
| 72 | return b, nil | ||
| 73 | } | ||
| 74 | |||
| 75 | type batchAction struct { | 56 | type batchAction struct { |
| 76 | HRef string `json:"href"` | 57 | HRef string `json:"href"` |
| 77 | Header map[string]string `json:"header,omitempty"` | 58 | Header map[string]string `json:"header,omitempty"` |
| 78 | ExpiresIn *SecondDuration `json:"expires_in,omitempty"` | 59 | // In seconds. |
| 79 | ExpiresAt *RFC3339SecondsTime `json:"expires_at,omitempty"` | 60 | ExpiresIn int64 `json:"expires_in,omitempty"` |
| 61 | // expires_at (RFC3339) could also be used, but we leave it out since we | ||
| 62 | // don't use it. | ||
| 80 | } | 63 | } |
| 81 | 64 | ||
| 82 | type batchError struct { | 65 | type batchError struct { |
| @@ -148,7 +131,6 @@ func makeObjError(obj parsedBatchObject, message string, code int) batchResponse | |||
| 148 | func (h *handler) handleDownloadObject(ctx context.Context, repo string, obj parsedBatchObject) batchResponseObject { | 131 | func (h *handler) handleDownloadObject(ctx context.Context, repo string, obj parsedBatchObject) batchResponseObject { |
| 149 | fullPath := path.Join(repo+".git", "lfs/objects", obj.firstByte, obj.secondByte, obj.fullHash) | 132 | fullPath := path.Join(repo+".git", "lfs/objects", obj.firstByte, obj.secondByte, obj.fullHash) |
| 150 | expiresIn := time.Hour * 24 | 133 | expiresIn := time.Hour * 24 |
| 151 | expiresInSeconds := SecondDuration(expiresIn) | ||
| 152 | 134 | ||
| 153 | info, err := h.mc.StatObject(ctx, h.bucket, fullPath, minio.StatObjectOptions{Checksum: true}) | 135 | info, err := h.mc.StatObject(ctx, h.bucket, fullPath, minio.StatObjectOptions{Checksum: true}) |
| 154 | if err != nil { | 136 | if err != nil { |
| @@ -184,7 +166,7 @@ func (h *handler) handleDownloadObject(ctx context.Context, repo string, obj par | |||
| 184 | Actions: map[operation]batchAction{ | 166 | Actions: map[operation]batchAction{ |
| 185 | operationDownload: { | 167 | operationDownload: { |
| 186 | HRef: presigned.String(), | 168 | HRef: presigned.String(), |
| 187 | ExpiresIn: &expiresInSeconds, | 169 | ExpiresIn: int64(expiresIn.Seconds()), |
| 188 | }, | 170 | }, |
| 189 | }, | 171 | }, |
| 190 | } | 172 | } |