(ctx *gin.Context)
| 152 | } |
| 153 | |
| 154 | func (h *GitHTTPHandler) LfsBatch(ctx *gin.Context) { |
| 155 | var batchRequest types.BatchRequest |
| 156 | if err := ctx.ShouldBindJSON(&batchRequest); err != nil { |
| 157 | slog.Error("Bad request format", "error", err) |
| 158 | httpbase.BadRequest(ctx, err.Error()) |
| 159 | return |
| 160 | } |
| 161 | batchRequest.CurrentUser = httpbase.GetCurrentUser(ctx) |
| 162 | batchRequest.Authorization = ctx.Request.Header.Get("Authorization") |
| 163 | batchRequest.Namespace = ctx.GetString("namespace") |
| 164 | batchRequest.Name = ctx.GetString("name") |
| 165 | batchRequest.RepoType = types.RepositoryType(ctx.GetString("repo_type")) |
| 166 | |
| 167 | var isUpload bool |
| 168 | if batchRequest.Operation == "upload" { |
| 169 | isUpload = true |
| 170 | } else if batchRequest.Operation == "download" { |
| 171 | isUpload = false |
| 172 | } else { |
| 173 | slog.Error("Invalid lfs batch operation", slog.String("operation", batchRequest.Operation)) |
| 174 | httpbase.BadRequest(ctx, fmt.Sprintf("Invalid lfs batch operation: %s", batchRequest.Operation)) |
| 175 | return |
| 176 | } |
| 177 | |
| 178 | s3Internal := ctx.GetHeader("X-OPENCSG-S3-Internal") |
| 179 | if s3Internal == "true" { |
| 180 | ctx.Set("X-OPENCSG-S3-Internal", true) |
| 181 | } |
| 182 | |
| 183 | objectResponse, err := h.c.BuildObjectResponse(ctx, batchRequest, isUpload) |
| 184 | if err != nil { |
| 185 | if errors.Is(err, component.ErrUnauthorized) { |
| 186 | ctx.Header("WWW-Authenticate", "Basic realm=opencsg-git") |
| 187 | ctx.PureJSON(http.StatusUnauthorized, nil) |
| 188 | return |
| 189 | } |
| 190 | |
| 191 | if errors.Is(err, component.ErrForbidden) { |
| 192 | ctx.PureJSON(http.StatusForbidden, gin.H{ |
| 193 | "error": "You do not have permission to access this repository.", |
| 194 | }) |
| 195 | return |
| 196 | } |
| 197 | httpbase.ServerError(ctx, err) |
| 198 | return |
| 199 | } |
| 200 | ctx.Header("Content-Type", types.LfsMediaType) |
| 201 | ctx.PureJSON(http.StatusOK, objectResponse) |
| 202 | } |
| 203 | |
| 204 | func (h *GitHTTPHandler) LfsUpload(ctx *gin.Context) { |
| 205 | var err error |
nothing calls this directly
no test coverage detected