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" {
|
if r.URL.Query().Get("idlength") == "short" {
|
||||||
idLength = 10
|
idLength = 10
|
||||||
}
|
}
|
||||||
|
redirect := false
|
||||||
|
if r.URL.Query().Get("redirect") == "true" {
|
||||||
|
redirect = true
|
||||||
|
}
|
||||||
|
|
||||||
var input UploadInput
|
var input UploadInput
|
||||||
switch mediaType {
|
switch mediaType {
|
||||||
@@ -202,6 +206,12 @@ func uploadHandler(db *gorm.DB, cfg Config) http.HandlerFunc {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
saved = true
|
saved = true
|
||||||
|
|
||||||
|
if redirect {
|
||||||
|
http.Redirect(w, r, "/"+id, http.StatusSeeOther)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
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{
|
||||||
|
|||||||
+2
-2
@@ -8,13 +8,13 @@
|
|||||||
<body>
|
<body>
|
||||||
<h1>{{.Title}}</h1>
|
<h1>{{.Title}}</h1>
|
||||||
<p>{{.Description}}</p>
|
<p>{{.Description}}</p>
|
||||||
<form action="/upload" method="post">
|
<form action="/upload?redirect=true" method="post">
|
||||||
<label for="content">paste content</label>
|
<label for="content">paste content</label>
|
||||||
<textarea id="content" name="content" rows="10" required></textarea>
|
<textarea id="content" name="content" rows="10" required></textarea>
|
||||||
<button type="submit">upload paste</button>
|
<button type="submit">upload paste</button>
|
||||||
</form>
|
</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"/>
|
<input type="file" required name="file"/>
|
||||||
<button type="submit">upload File</button>
|
<button type="submit">upload File</button>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
Reference in New Issue
Block a user