add return type query on upload, will eventually use to have an after upload page
This commit is contained in:
+18
-15
@@ -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,21 +239,23 @@ 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.WriteHeader(http.StatusCreated)
|
||||||
|
if err := json.NewEncoder(w).Encode(UploadResponse{
|
||||||
|
Upload: upload,
|
||||||
|
SHA256: hex.EncodeToString(upload.SHA256),
|
||||||
|
DeleteToken: upload.DeleteToken,
|
||||||
|
FileExtension: filepath.Ext(upload.Filename),
|
||||||
|
}); err != nil {
|
||||||
|
log.Println("failed to encode response:", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
|
||||||
w.WriteHeader(http.StatusCreated)
|
|
||||||
if err := json.NewEncoder(w).Encode(UploadResponse{
|
|
||||||
Upload: upload,
|
|
||||||
SHA256: hex.EncodeToString(upload.SHA256),
|
|
||||||
DeleteToken: upload.DeleteToken,
|
|
||||||
FileExtension: filepath.Ext(upload.Filename),
|
|
||||||
}); err != nil {
|
|
||||||
log.Println("failed to encode response:", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -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">
|
||||||
|
|||||||
Reference in New Issue
Block a user