(w http.ResponseWriter, r *http.Request)
| 23 | ) |
| 24 | |
| 25 | func (h *handler) UploadPackageFile(w http.ResponseWriter, r *http.Request) { |
| 26 | file, fileHeader, err := r.FormFile("content") |
| 27 | |
| 28 | if err != nil { |
| 29 | h.HandleError(r.Context(), w, err) |
| 30 | return |
| 31 | } |
| 32 | |
| 33 | defer file.Close() |
| 34 | |
| 35 | contextInfo := request.ArtifactInfoFrom(r.Context()) |
| 36 | info, ok := contextInfo.(*pythontype.ArtifactInfo) |
| 37 | if !ok { |
| 38 | h.HandleError(r.Context(), w, fmt.Errorf("failed to fetch info from context")) |
| 39 | return |
| 40 | } |
| 41 | |
| 42 | // TODO: Can we extract this out to ArtifactInfoProvider |
| 43 | if info.Filename == "" { |
| 44 | info.Filename = fileHeader.Filename |
| 45 | request.WithArtifactInfo(r.Context(), info) |
| 46 | } |
| 47 | |
| 48 | response := h.controller.UploadPackageFile(r.Context(), *info, file, fileHeader) |
| 49 | |
| 50 | if response.GetError() != nil { |
| 51 | h.HandleError(r.Context(), w, response.GetError()) |
| 52 | return |
| 53 | } |
| 54 | |
| 55 | response.ResponseHeaders.WriteToResponse(w) |
| 56 | _, err = w.Write([]byte(fmt.Sprintf("Pushed.\nSha256: %s", response.Sha256))) |
| 57 | if err != nil { |
| 58 | h.HandleError(r.Context(), w, err) |
| 59 | return |
| 60 | } |
| 61 | } |
nothing calls this directly
no test coverage detected