diff options
| author | Leonardo Bishop <me@leonardobishop.net> | 2025-07-08 23:26:05 +0100 |
|---|---|---|
| committer | Leonardo Bishop <me@leonardobishop.net> | 2025-07-08 23:26:05 +0100 |
| commit | cdb75d3fcbc9339b897f8c6ff4d69a577f017393 (patch) | |
| tree | 5e757cd236540c2cea9874c1bc09f19548db05d5 /api/handler | |
| parent | b56101f1a11552067f594679a497ebd4cf7427d4 (diff) | |
Rewrite in Go
Diffstat (limited to 'api/handler')
| -rw-r--r-- | api/handler/site.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/api/handler/site.go b/api/handler/site.go new file mode 100644 index 0000000..0a2ac85 --- /dev/null +++ b/api/handler/site.go @@ -0,0 +1,31 @@ +package handler + +import ( + "fmt" + "net/http" + + "github.com/LMBishop/scrapbook/pkg/config" + "github.com/LMBishop/scrapbook/pkg/index" + "github.com/LMBishop/scrapbook/pkg/upload" +) + +func UploadSiteVersion(mainConfig *config.MainConfig, index *index.SiteIndex) func(http.ResponseWriter, *http.Request) { + return func(w http.ResponseWriter, r *http.Request) { + site := r.PathValue("site") + reader, err := r.MultipartReader() + if err != nil { + w.WriteHeader(http.StatusInternalServerError) + fmt.Fprintf(w, "could not read stream: %s", err.Error()) + return + } + + version, err := upload.HandleUpload(site, reader, index) + if err != nil { + w.WriteHeader(http.StatusInternalServerError) + fmt.Fprint(w, err.Error()) + return + } + + fmt.Fprintf(w, "version created: %s", version) + } +} |
