add a redirect query for no javascript
This commit is contained in:
+10
@@ -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{
|
||||
|
||||
+2
-2
@@ -8,13 +8,13 @@
|
||||
<body>
|
||||
<h1>{{.Title}}</h1>
|
||||
<p>{{.Description}}</p>
|
||||
<form action="/upload" method="post">
|
||||
<form action="/upload?redirect=true" method="post">
|
||||
<label for="content">paste content</label>
|
||||
<textarea id="content" name="content" rows="10" required></textarea>
|
||||
<button type="submit">upload paste</button>
|
||||
</form>
|
||||
|
||||
<form action="/upload" method="post" enctype="multipart/form-data">
|
||||
<form action="/upload?redirect=true" method="post" enctype="multipart/form-data">
|
||||
<input type="file" required name="file"/>
|
||||
<button type="submit">upload File</button>
|
||||
</form>
|
||||
|
||||
Reference in New Issue
Block a user