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" { if r.URL.Query().Get("idlength") == "short" {
idLength = 10 idLength = 10
} }
redirect := false
if r.URL.Query().Get("redirect") == "true" { returnType := strings.TrimSpace(r.URL.Query().Get("return"))
redirect = true if returnType == "" {
returnType = "json"
} }
expLabel := r.URL.Query().Get("expiry") expLabel := r.URL.Query().Get("expiry")
@@ -238,11 +239,11 @@ func uploadHandler(db *gorm.DB, cfg Config) http.HandlerFunc {
} }
saved = true saved = true
if redirect { switch returnType {
// html & maybe xml? cant think of other return types
case "redirect":
http.Redirect(w, r, "/"+id, http.StatusSeeOther) http.Redirect(w, r, "/"+id, http.StatusSeeOther)
return default:
}
w.Header().Set("Content-Type", "application/json") w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusCreated) w.WriteHeader(http.StatusCreated)
if err := json.NewEncoder(w).Encode(UploadResponse{ 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) log.Println("failed to encode response:", err)
} }
} }
}
} }
func contentHandler(db *gorm.DB, cfg Config) http.HandlerFunc { 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" /> <input type="radio" name="upload-type" id="type-paste" />
<label for="type-paste">paste</label> <label for="type-paste">paste</label>
<div class="file-panel"> <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> <label for="file-expiry">expiry</label>
<select id="paste-expiry" name="expiry"> <select id="paste-expiry" name="expiry">
{{range .Expiries}} {{range .Expiries}}
@@ -28,7 +28,7 @@
</form> </form>
</div> </div>
<div class="paste-panel"> <div class="paste-panel">
<form action="/upload?redirect=true" method="post"> <form action="/upload?return=redirect" method="post">
<label for="paste-expiry">expiry</label> <label for="paste-expiry">expiry</label>
<select id="paste-expiry" name="expiry"> <select id="paste-expiry" name="expiry">