aboutsummaryrefslogtreecommitdiffstats
path: root/api
diff options
context:
space:
mode:
Diffstat (limited to 'api')
-rw-r--r--api/handler/site.go31
-rw-r--r--api/mux.go16
2 files changed, 47 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)
+ }
+}
diff --git a/api/mux.go b/api/mux.go
new file mode 100644
index 0000000..90e0ec7
--- /dev/null
+++ b/api/mux.go
@@ -0,0 +1,16 @@
+package api
+
+import (
+ "net/http"
+
+ "github.com/LMBishop/scrapbook/api/handler"
+ "github.com/LMBishop/scrapbook/pkg/config"
+ "github.com/LMBishop/scrapbook/pkg/index"
+)
+
+func NewMux(cfg *config.MainConfig, siteIndex *index.SiteIndex) *http.ServeMux {
+ mux := http.NewServeMux()
+ mux.HandleFunc("POST /site/{site}/upload", handler.UploadSiteVersion(cfg, siteIndex))
+
+ return mux
+}