qtify other pages + fixed position on qts
working on showing the max upload size, just figuring out how to make it look good and where to position it. there's probably a better way to include qts in all of these pages without having to pass all of these variables
This commit is contained in:
@@ -3,6 +3,7 @@ module git.whoswhip.dev/whoswhip/minibin
|
||||
go 1.27.1
|
||||
|
||||
require (
|
||||
github.com/dustin/go-humanize v1.0.1
|
||||
github.com/gabriel-vasile/mimetype v1.4.16
|
||||
github.com/glebarez/sqlite v1.11.0
|
||||
github.com/joho/godotenv v1.5.1
|
||||
@@ -10,7 +11,6 @@ require (
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/dustin/go-humanize v1.0.1 // indirect
|
||||
github.com/glebarez/go-sqlite v1.21.2 // indirect
|
||||
github.com/google/uuid v1.3.0 // indirect
|
||||
github.com/jinzhu/inflection v1.0.0 // indirect
|
||||
|
||||
+7
-3
@@ -27,6 +27,8 @@ type HomePageData struct {
|
||||
Expiries []Expiry
|
||||
Qt string
|
||||
PastePlaceholder string
|
||||
FileMaxSize string
|
||||
PasteMaxSize string
|
||||
}
|
||||
|
||||
func health(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -45,6 +47,7 @@ type UploadResponse struct {
|
||||
SHA256 string `json:"sha256"`
|
||||
DeleteToken string `json:"deleteToken"`
|
||||
FileExtension string `json:"extension"` // useful for things like sharex to append the extension
|
||||
Qt string `json:"-"`
|
||||
}
|
||||
type ContentInfoResponse struct {
|
||||
Upload
|
||||
@@ -59,13 +62,13 @@ func render(pages *template.Template, w http.ResponseWriter, name string, data a
|
||||
}
|
||||
}
|
||||
|
||||
func staticPage(pages *template.Template, name string) http.HandlerFunc {
|
||||
func staticPage(pages *template.Template, name string, qts []string) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
render(pages, w, name, nil)
|
||||
render(pages, w, name, getRandomQt(qts))
|
||||
}
|
||||
}
|
||||
|
||||
func uploadHandler(db *gorm.DB, cfg Config, pages *template.Template) http.HandlerFunc {
|
||||
func uploadHandler(db *gorm.DB, cfg Config, pages *template.Template, qts []string) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodPost && r.Method != http.MethodPut {
|
||||
w.Header().Set("Allow", "POST,PUT")
|
||||
@@ -273,6 +276,7 @@ func uploadHandler(db *gorm.DB, cfg Config, pages *template.Template) http.Handl
|
||||
SHA256: hex.EncodeToString(upload.SHA256),
|
||||
DeleteToken: upload.DeleteToken,
|
||||
FileExtension: filepath.Ext(upload.Filename),
|
||||
Qt: getRandomQt(qts),
|
||||
}
|
||||
|
||||
switch returnType {
|
||||
|
||||
@@ -11,6 +11,8 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/dustin/go-humanize"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -98,10 +100,9 @@ func main() {
|
||||
mux.HandleFunc("GET /{$}", func(w http.ResponseWriter, r *http.Request) {
|
||||
data := HomePageData{
|
||||
Expiries: config.Expiries,
|
||||
}
|
||||
|
||||
if len(qts) > 0 {
|
||||
data.Qt = qts[rand.IntN(len(qts))]
|
||||
FileMaxSize: humanize.Bytes(uint64(config.MaxFileBytes)),
|
||||
PasteMaxSize: humanize.Bytes(uint64(config.MaxPasteBytes)),
|
||||
Qt: getRandomQt(qts),
|
||||
}
|
||||
|
||||
if len(placeholders) > 0 {
|
||||
@@ -110,21 +111,22 @@ func main() {
|
||||
|
||||
render(pages, w, "home.html", data)
|
||||
})
|
||||
mux.HandleFunc("GET /tos", staticPage(pages, "tos.html"))
|
||||
mux.HandleFunc("GET /privacy", staticPage(pages, "privacy.html"))
|
||||
mux.HandleFunc("GET /tos", staticPage(pages, "tos.html", qts))
|
||||
mux.HandleFunc("GET /privacy", staticPage(pages, "privacy.html", qts))
|
||||
mux.HandleFunc("GET /faq", func(w http.ResponseWriter, r *http.Request) {
|
||||
render(pages, w, "faq.html", map[string]any{
|
||||
"Expiries": config.Expiries,
|
||||
"Host": config.Host,
|
||||
"NormalizeMIMETypes": config.NormalizeMIMETypes,
|
||||
"Qt": getRandomQt(qts),
|
||||
})
|
||||
})
|
||||
uploads := http.NewServeMux()
|
||||
uploads.HandleFunc("GET /{id}", contentHandler(db, config, tracker))
|
||||
uploads.HandleFunc("GET /{id}/info", contentInfoHandler(db, tracker))
|
||||
mux.Handle("/", uploads)
|
||||
mux.HandleFunc("POST /upload", uploadHandler(db, config, pages))
|
||||
mux.HandleFunc("PUT /upload", uploadHandler(db, config, pages))
|
||||
mux.HandleFunc("POST /upload", uploadHandler(db, config, pages, qts))
|
||||
mux.HandleFunc("PUT /upload", uploadHandler(db, config, pages, qts))
|
||||
mux.HandleFunc("DELETE /{id}", deleteHandler(db, config))
|
||||
mux.HandleFunc("POST /{id}/delete", deleteHandler(db, config))
|
||||
mux.HandleFunc("GET /health", health)
|
||||
@@ -136,3 +138,10 @@ func main() {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func getRandomQt(qts []string) string {
|
||||
if len(qts) > 0 {
|
||||
return qts[rand.IntN(len(qts))]
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ body {
|
||||
background-repeat: no-repeat;
|
||||
background-position: bottom right;
|
||||
background-size: auto 256px;
|
||||
background-attachment: fixed;
|
||||
}
|
||||
|
||||
b {
|
||||
|
||||
@@ -5,6 +5,13 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>faq | minibin</title>
|
||||
<link rel="stylesheet" href="/css/main.css" />
|
||||
{{if .Qt}}
|
||||
<style>
|
||||
:root {
|
||||
--qt-url: url("{{.Qt}}");
|
||||
}
|
||||
</style>
|
||||
{{end}}
|
||||
</head>
|
||||
<body>
|
||||
{{template "site-header"}}
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
<label for="type-paste">paste</label>
|
||||
<div class="file-panel">
|
||||
<form action="/upload?return=html" method="post" enctype="multipart/form-data">
|
||||
<div>
|
||||
<label class="muted" for="file-expiry">expiry</label>
|
||||
<select id="file-expiry" name="expiry">
|
||||
{{range .Expiries}}
|
||||
@@ -37,6 +38,9 @@
|
||||
<option value="long">16 characters</option>
|
||||
<option value="short">10 characters</option>
|
||||
</select>
|
||||
<span style="margin-left: auto;">max {{.FileMaxSize}}</span>
|
||||
</div>
|
||||
|
||||
<input id="upload-file" type="file" required name="file" />
|
||||
<button type="submit" class="btn">upload file</button>
|
||||
</form>
|
||||
|
||||
@@ -5,6 +5,13 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>privacy | minibin</title>
|
||||
<link rel="stylesheet" href="/css/main.css" />
|
||||
{{if .}}
|
||||
<style>
|
||||
:root {
|
||||
--qt-url: url("{{.}}");
|
||||
}
|
||||
</style>
|
||||
{{end}}
|
||||
</head>
|
||||
<body>
|
||||
{{template "site-header"}}
|
||||
|
||||
@@ -5,6 +5,13 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>tos | minibin</title>
|
||||
<link rel="stylesheet" href="/css/main.css" />
|
||||
{{if .}}
|
||||
<style>
|
||||
:root {
|
||||
--qt-url: url("{{.}}");
|
||||
}
|
||||
</style>
|
||||
{{end}}
|
||||
</head>
|
||||
<body>
|
||||
{{template "site-header"}}
|
||||
|
||||
@@ -5,6 +5,13 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>{{.ID}} | minibin</title>
|
||||
<link rel="stylesheet" href="/css/main.css" />
|
||||
{{if .Qt}}
|
||||
<style>
|
||||
:root {
|
||||
--qt-url: url("{{.Qt}}");
|
||||
}
|
||||
</style>
|
||||
{{end}}
|
||||
</head>
|
||||
<script src="/js/copy.js" defer></script>
|
||||
<body>
|
||||
|
||||
Reference in New Issue
Block a user