fuck. list expiries + accept post form expiry
This commit is contained in:
+4
-2
@@ -23,8 +23,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type HomePageData struct {
|
type HomePageData struct {
|
||||||
Title string
|
Expiries []Expiry
|
||||||
Description string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func health(w http.ResponseWriter, r *http.Request) {
|
func health(w http.ResponseWriter, r *http.Request) {
|
||||||
@@ -71,6 +70,9 @@ func uploadHandler(db *gorm.DB, cfg Config) http.HandlerFunc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
expLabel := r.URL.Query().Get("expiry")
|
expLabel := r.URL.Query().Get("expiry")
|
||||||
|
if expLabel == "" {
|
||||||
|
expLabel = r.PostFormValue("expiry") // html form request
|
||||||
|
}
|
||||||
if expLabel == "" {
|
if expLabel == "" {
|
||||||
expLabel = cfg.Expiries[0].Label
|
expLabel = cfg.Expiries[0].Label
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,8 +35,7 @@ func main() {
|
|||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
mux.HandleFunc("GET /{$}", func(w http.ResponseWriter, r *http.Request) {
|
mux.HandleFunc("GET /{$}", func(w http.ResponseWriter, r *http.Request) {
|
||||||
data := HomePageData{
|
data := HomePageData{
|
||||||
Title: "minibin",
|
Expiries: config.Expiries,
|
||||||
Description: "simple file and paste hosting",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||||
|
|||||||
+9
-3
@@ -3,14 +3,20 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
<title>{{.Title}}</title>
|
<title>minibin</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>{{.Title}}</h1>
|
<h1>minibin</h1>
|
||||||
<p>{{.Description}}</p>
|
<p>simple file and paste hosting service</p>
|
||||||
<form action="/upload?redirect=true" 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>
|
||||||
|
<label for="paste-expiry">Expiry</label>
|
||||||
|
<select id="paste-expiry" name="expiry">
|
||||||
|
{{range .Expiries}}
|
||||||
|
<option value="{{.Label}}">{{.Label}}</option>
|
||||||
|
{{end}}
|
||||||
|
</select>
|
||||||
<button type="submit">upload paste</button>
|
<button type="submit">upload paste</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user