diff --git a/handlers.go b/handlers.go index 363f3da..cd5632b 100644 --- a/handlers.go +++ b/handlers.go @@ -62,6 +62,10 @@ func uploadHandler(db *gorm.DB, cfg Config) http.HandlerFunc { if r.URL.Query().Get("idlength") == "short" { idLength = 10 } + redirect := false + if r.URL.Query().Get("redirect") == "true" { + redirect = true + } var input UploadInput switch mediaType { @@ -202,6 +206,12 @@ func uploadHandler(db *gorm.DB, cfg Config) http.HandlerFunc { return } saved = true + + if redirect { + http.Redirect(w, r, "/"+id, http.StatusSeeOther) + return + } + w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusCreated) if err := json.NewEncoder(w).Encode(UploadResponse{ diff --git a/templates/home.html b/templates/home.html index c57c529..dec7047 100644 --- a/templates/home.html +++ b/templates/home.html @@ -8,13 +8,13 @@

{{.Title}}

{{.Description}}

-
+
-
+