diff --git a/editor.go b/editor.go index 1676f9f..ceddb74 100644 --- a/editor.go +++ b/editor.go @@ -16,7 +16,8 @@ func serveEditor(w http.ResponseWriter, r *http.Request) { func serveEditorPost(w http.ResponseWriter, r *http.Request) { if action := r.FormValue("editoraction"); action != "" { - if action == "loadupdate" { + switch action { + case "loadupdate": parsedURL, err := url.Parse(r.FormValue("url")) if err != nil { http.Error(w, err.Error(), http.StatusBadRequest) @@ -34,8 +35,7 @@ func serveEditorPost(w http.ResponseWriter, r *http.Request) { "UpdatePostContent": mf.Properties.Content[0], }, }) - return - } else if action == "updatepost" { + case "updatepost": urlValue := r.FormValue("url") content := r.FormValue("content") mf := map[string]interface{}{ @@ -58,18 +58,24 @@ func serveEditorPost(w http.ResponseWriter, r *http.Request) { return } req.Header.Set(contentType, contentTypeJSON) - editorMicropubPost(w, req) - return + editorMicropubPost(w, req, false) + case "upload": + editorMicropubPost(w, r, true) + default: + http.Error(w, "unknown editoraction", http.StatusBadRequest) } - http.Error(w, "unknown editoraction", http.StatusBadRequest) return } - editorMicropubPost(w, r) + editorMicropubPost(w, r, false) } -func editorMicropubPost(w http.ResponseWriter, r *http.Request) { +func editorMicropubPost(w http.ResponseWriter, r *http.Request, media bool) { recorder := httptest.NewRecorder() - addAllScopes(http.HandlerFunc(serveMicropubPost)).ServeHTTP(recorder, r) + if media { + addAllScopes(http.HandlerFunc(serveMicropubMedia)).ServeHTTP(recorder, r) + } else { + addAllScopes(http.HandlerFunc(serveMicropubPost)).ServeHTTP(recorder, r) + } result := recorder.Result() if location := result.Header.Get("Location"); location != "" { http.Redirect(w, r, result.Header.Get("Location"), http.StatusFound) diff --git a/micropubMedia.go b/micropubMedia.go index ad93137..398ca35 100644 --- a/micropubMedia.go +++ b/micropubMedia.go @@ -77,8 +77,7 @@ func serveMicropubMedia(w http.ResponseWriter, r *http.Request) { location = compressedLocation } } - w.Header().Add("Location", location) - w.WriteHeader(http.StatusCreated) + http.Redirect(w, r, location, http.StatusCreated) } func (mediaConf *configMicropubMedia) uploadToBunny(filename string, file multipart.File) (location string, err error) { diff --git a/templates/editor.gohtml b/templates/editor.gohtml index 5c718dc..403fde3 100644 --- a/templates/editor.gohtml +++ b/templates/editor.gohtml @@ -29,6 +29,12 @@ +

{{ string .Blog.Lang "upload" }}

+
+ + + +
{{ end }} diff --git a/templates/strings/default.yaml b/templates/strings/default.yaml index 8b06520..1358710 100644 --- a/templates/strings/default.yaml +++ b/templates/strings/default.yaml @@ -25,4 +25,5 @@ interactionslabel: "Have you published a response to this? Paste the URL here." search: "Search" editor: "Editor" create: "Create" -update: "Update" \ No newline at end of file +update: "Update" +upload: "Upload" \ No newline at end of file