Skip to content

feat: support template bundles as zip archives #11839

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: support template bundles as zip archives
  • Loading branch information
mtojek committed Jan 26, 2024
commit 11fd5529bab87b59ce41fdf8df7bcaab005a683d
2 changes: 1 addition & 1 deletion coderd/apidoc/docs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion coderd/apidoc/swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions coderd/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

const (
tarMimeType = "application/x-tar"
zipMimeType = "application/zip"
)

// @Summary Upload file
Expand All @@ -30,7 +31,7 @@ const (
// @Produce json
// @Accept application/x-tar
// @Tags Files
// @Param Content-Type header string true "Content-Type must be `application/x-tar`" default(application/x-tar)
// @Param Content-Type header string true "Content-Type must be `application/x-tar` or `application/zip`" default(application/x-tar)
// @Param file formData file true "File to be uploaded"
// @Success 201 {object} codersdk.UploadResponse
// @Router /files [post]
Expand All @@ -41,7 +42,7 @@ func (api *API) postFile(rw http.ResponseWriter, r *http.Request) {
contentType := r.Header.Get("Content-Type")

switch contentType {
case tarMimeType:
case tarMimeType, zipMimeType:
default:
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
Message: fmt.Sprintf("Unsupported content type header %q.", contentType),
Expand Down Expand Up @@ -78,6 +79,11 @@ func (api *API) postFile(rw http.ResponseWriter, r *http.Request) {
return
}

if contentType == zipMimeType {
// FIXME Repack to .tar format.
contentType = tarMimeType
}

id := uuid.New()
file, err = api.Database.InsertFile(ctx, database.InsertFileParams{
ID: id,
Expand Down
10 changes: 5 additions & 5 deletions docs/api/files.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.