From cdb75d3fcbc9339b897f8c6ff4d69a577f017393 Mon Sep 17 00:00:00 2001 From: Leonardo Bishop Date: Tue, 8 Jul 2025 23:26:05 +0100 Subject: Rewrite in Go --- api/handler/site.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 api/handler/site.go (limited to 'api/handler/site.go') 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) + } +} -- cgit v1.2.3-70-g09d2