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:
2026-11-14 17:39:00 -05:00
parent ee454661cc
commit 53b0aac403
9 changed files with 70 additions and 24 deletions
+1 -1
View File
@@ -3,6 +3,7 @@ module git.whoswhip.dev/whoswhip/minibin
go 1.27.1 go 1.27.1
require ( require (
github.com/dustin/go-humanize v1.0.1
github.com/gabriel-vasile/mimetype v1.4.16 github.com/gabriel-vasile/mimetype v1.4.16
github.com/glebarez/sqlite v1.11.0 github.com/glebarez/sqlite v1.11.0
github.com/joho/godotenv v1.5.1 github.com/joho/godotenv v1.5.1
@@ -10,7 +11,6 @@ require (
) )
require ( require (
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/glebarez/go-sqlite v1.21.2 // indirect github.com/glebarez/go-sqlite v1.21.2 // indirect
github.com/google/uuid v1.3.0 // indirect github.com/google/uuid v1.3.0 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect github.com/jinzhu/inflection v1.0.0 // indirect
+7 -3
View File
@@ -27,6 +27,8 @@ type HomePageData struct {
Expiries []Expiry Expiries []Expiry
Qt string Qt string
PastePlaceholder string PastePlaceholder string
FileMaxSize string
PasteMaxSize string
} }
func health(w http.ResponseWriter, r *http.Request) { func health(w http.ResponseWriter, r *http.Request) {
@@ -45,6 +47,7 @@ type UploadResponse struct {
SHA256 string `json:"sha256"` SHA256 string `json:"sha256"`
DeleteToken string `json:"deleteToken"` DeleteToken string `json:"deleteToken"`
FileExtension string `json:"extension"` // useful for things like sharex to append the extension FileExtension string `json:"extension"` // useful for things like sharex to append the extension
Qt string `json:"-"`
} }
type ContentInfoResponse struct { type ContentInfoResponse struct {
Upload 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) { 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) { return func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost && r.Method != http.MethodPut { if r.Method != http.MethodPost && r.Method != http.MethodPut {
w.Header().Set("Allow", "POST,PUT") 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), SHA256: hex.EncodeToString(upload.SHA256),
DeleteToken: upload.DeleteToken, DeleteToken: upload.DeleteToken,
FileExtension: filepath.Ext(upload.Filename), FileExtension: filepath.Ext(upload.Filename),
Qt: getRandomQt(qts),
} }
switch returnType { switch returnType {
+17 -8
View File
@@ -11,6 +11,8 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
"github.com/dustin/go-humanize"
) )
func main() { func main() {
@@ -98,10 +100,9 @@ func main() {
mux.HandleFunc("GET /{$}", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("GET /{$}", func(w http.ResponseWriter, r *http.Request) {
data := HomePageData{ data := HomePageData{
Expiries: config.Expiries, Expiries: config.Expiries,
} FileMaxSize: humanize.Bytes(uint64(config.MaxFileBytes)),
PasteMaxSize: humanize.Bytes(uint64(config.MaxPasteBytes)),
if len(qts) > 0 { Qt: getRandomQt(qts),
data.Qt = qts[rand.IntN(len(qts))]
} }
if len(placeholders) > 0 { if len(placeholders) > 0 {
@@ -110,21 +111,22 @@ func main() {
render(pages, w, "home.html", data) render(pages, w, "home.html", data)
}) })
mux.HandleFunc("GET /tos", staticPage(pages, "tos.html")) mux.HandleFunc("GET /tos", staticPage(pages, "tos.html", qts))
mux.HandleFunc("GET /privacy", staticPage(pages, "privacy.html")) mux.HandleFunc("GET /privacy", staticPage(pages, "privacy.html", qts))
mux.HandleFunc("GET /faq", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("GET /faq", func(w http.ResponseWriter, r *http.Request) {
render(pages, w, "faq.html", map[string]any{ render(pages, w, "faq.html", map[string]any{
"Expiries": config.Expiries, "Expiries": config.Expiries,
"Host": config.Host, "Host": config.Host,
"NormalizeMIMETypes": config.NormalizeMIMETypes, "NormalizeMIMETypes": config.NormalizeMIMETypes,
"Qt": getRandomQt(qts),
}) })
}) })
uploads := http.NewServeMux() uploads := http.NewServeMux()
uploads.HandleFunc("GET /{id}", contentHandler(db, config, tracker)) uploads.HandleFunc("GET /{id}", contentHandler(db, config, tracker))
uploads.HandleFunc("GET /{id}/info", contentInfoHandler(db, tracker)) uploads.HandleFunc("GET /{id}/info", contentInfoHandler(db, tracker))
mux.Handle("/", uploads) mux.Handle("/", uploads)
mux.HandleFunc("POST /upload", uploadHandler(db, config, pages)) mux.HandleFunc("POST /upload", uploadHandler(db, config, pages, qts))
mux.HandleFunc("PUT /upload", uploadHandler(db, config, pages)) mux.HandleFunc("PUT /upload", uploadHandler(db, config, pages, qts))
mux.HandleFunc("DELETE /{id}", deleteHandler(db, config)) mux.HandleFunc("DELETE /{id}", deleteHandler(db, config))
mux.HandleFunc("POST /{id}/delete", deleteHandler(db, config)) mux.HandleFunc("POST /{id}/delete", deleteHandler(db, config))
mux.HandleFunc("GET /health", health) mux.HandleFunc("GET /health", health)
@@ -136,3 +138,10 @@ func main() {
log.Fatal(err) log.Fatal(err)
} }
} }
func getRandomQt(qts []string) string {
if len(qts) > 0 {
return qts[rand.IntN(len(qts))]
}
return ""
}
+1
View File
@@ -24,6 +24,7 @@ body {
background-repeat: no-repeat; background-repeat: no-repeat;
background-position: bottom right; background-position: bottom right;
background-size: auto 256px; background-size: auto 256px;
background-attachment: fixed;
} }
b { b {
+7
View File
@@ -5,6 +5,13 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>faq | minibin</title> <title>faq | minibin</title>
<link rel="stylesheet" href="/css/main.css" /> <link rel="stylesheet" href="/css/main.css" />
{{if .Qt}}
<style>
:root {
--qt-url: url("{{.Qt}}");
}
</style>
{{end}}
</head> </head>
<body> <body>
{{template "site-header"}} {{template "site-header"}}
+4
View File
@@ -26,6 +26,7 @@
<label for="type-paste">paste</label> <label for="type-paste">paste</label>
<div class="file-panel"> <div class="file-panel">
<form action="/upload?return=html" method="post" enctype="multipart/form-data"> <form action="/upload?return=html" method="post" enctype="multipart/form-data">
<div>
<label class="muted" for="file-expiry">expiry</label> <label class="muted" for="file-expiry">expiry</label>
<select id="file-expiry" name="expiry"> <select id="file-expiry" name="expiry">
{{range .Expiries}} {{range .Expiries}}
@@ -37,6 +38,9 @@
<option value="long">16 characters</option> <option value="long">16 characters</option>
<option value="short">10 characters</option> <option value="short">10 characters</option>
</select> </select>
<span style="margin-left: auto;">max {{.FileMaxSize}}</span>
</div>
<input id="upload-file" type="file" required name="file" /> <input id="upload-file" type="file" required name="file" />
<button type="submit" class="btn">upload file</button> <button type="submit" class="btn">upload file</button>
</form> </form>
+7
View File
@@ -5,6 +5,13 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>privacy | minibin</title> <title>privacy | minibin</title>
<link rel="stylesheet" href="/css/main.css" /> <link rel="stylesheet" href="/css/main.css" />
{{if .}}
<style>
:root {
--qt-url: url("{{.}}");
}
</style>
{{end}}
</head> </head>
<body> <body>
{{template "site-header"}} {{template "site-header"}}
+7
View File
@@ -5,6 +5,13 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>tos | minibin</title> <title>tos | minibin</title>
<link rel="stylesheet" href="/css/main.css" /> <link rel="stylesheet" href="/css/main.css" />
{{if .}}
<style>
:root {
--qt-url: url("{{.}}");
}
</style>
{{end}}
</head> </head>
<body> <body>
{{template "site-header"}} {{template "site-header"}}
+7
View File
@@ -5,6 +5,13 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>{{.ID}} | minibin</title> <title>{{.ID}} | minibin</title>
<link rel="stylesheet" href="/css/main.css" /> <link rel="stylesheet" href="/css/main.css" />
{{if .Qt}}
<style>
:root {
--qt-url: url("{{.Qt}}");
}
</style>
{{end}}
</head> </head>
<script src="/js/copy.js" defer></script> <script src="/js/copy.js" defer></script>
<body> <body>