add return type query on upload, will eventually use to have an after upload page

This commit is contained in:
2026-11-12 19:13:37 -05:00
parent 505cb7f757
commit 490f010999
2 changed files with 20 additions and 17 deletions
+10 -7
View File
@@ -64,9 +64,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
returnType := strings.TrimSpace(r.URL.Query().Get("return"))
if returnType == "" {
returnType = "json"
}
expLabel := r.URL.Query().Get("expiry")
@@ -238,11 +239,11 @@ func uploadHandler(db *gorm.DB, cfg Config) http.HandlerFunc {
}
saved = true
if redirect {
switch returnType {
// html & maybe xml? cant think of other return types
case "redirect":
http.Redirect(w, r, "/"+id, http.StatusSeeOther)
return
}
default:
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusCreated)
if err := json.NewEncoder(w).Encode(UploadResponse{
@@ -254,6 +255,8 @@ func uploadHandler(db *gorm.DB, cfg Config) http.HandlerFunc {
log.Println("failed to encode response:", err)
}
}
}
}
func contentHandler(db *gorm.DB, cfg Config) http.HandlerFunc {
+2 -2
View File
@@ -16,7 +16,7 @@
<input type="radio" name="upload-type" id="type-paste" />
<label for="type-paste">paste</label>
<div class="file-panel">
<form action="/upload?redirect=true" method="post" enctype="multipart/form-data">
<form action="/upload?return=redirect" method="post" enctype="multipart/form-data">
<label for="file-expiry">expiry</label>
<select id="paste-expiry" name="expiry">
{{range .Expiries}}
@@ -28,7 +28,7 @@
</form>
</div>
<div class="paste-panel">
<form action="/upload?redirect=true" method="post">
<form action="/upload?return=redirect" method="post">
<label for="paste-expiry">expiry</label>
<select id="paste-expiry" name="expiry">