From 2c342f63b337d7cb24cf996f93c8d92668887a1e Mon Sep 17 00:00:00 2001 From: whoswhip Date: Thu, 12 Nov 2026 22:30:36 -0500 Subject: [PATCH] every file sharing service needs qts honestly this code might be kind of shit, and it needs to used on the other page(s) as well but im too lazy, fixed a styling issue with the upload result page though --- handlers.go | 1 + main.go | 30 ++++++++++++++++++++++++++++++ static/css/main.css | 11 +++++++++++ templates/home.html | 7 +++++++ templates/upload.html | 2 +- 5 files changed, 50 insertions(+), 1 deletion(-) diff --git a/handlers.go b/handlers.go index f2f5e1d..7f433bb 100644 --- a/handlers.go +++ b/handlers.go @@ -25,6 +25,7 @@ import ( type HomePageData struct { Expiries []Expiry + Qt string } func health(w http.ResponseWriter, r *http.Request) { diff --git a/main.go b/main.go index d17b522..a94eb49 100644 --- a/main.go +++ b/main.go @@ -1,10 +1,14 @@ package main import ( + "errors" "html/template" "log" + "math/rand/v2" "net/http" + "net/url" "os" + "path/filepath" "strings" ) @@ -39,16 +43,42 @@ func main() { log.Fatal(err) } + qtFiles, err := os.ReadDir("qts") + if err != nil && !errors.Is(err, os.ErrNotExist) { + log.Fatal(err) + } + + var qts []string + for _, qt := range qtFiles { + if qt.IsDir() { + continue + } + + switch strings.ToLower(filepath.Ext(qt.Name())) { + case ".jpeg", "jpg", ".jxl", ".png", ".webp", "avif", ".gif": + qts = append(qts, "/qts/"+url.PathEscape(qt.Name())) + } + } + mux := http.NewServeMux() fs := http.FileServer(http.Dir("static")) mux.Handle("GET /css/", fs) mux.Handle("GET /js/", fs) mux.Handle("GET /static/", http.StripPrefix("/static/", fs)) + mux.Handle("GET /qts/", http.StripPrefix( + "/qts/", + http.FileServer((http.Dir("qts"))), + )) mux.HandleFunc("GET /{$}", func(w http.ResponseWriter, r *http.Request) { data := HomePageData{ Expiries: config.Expiries, } + if len(qts) > 0 { + log.Println(len(qts)) + data.Qt = qts[rand.IntN(len(qts))] + } + w.Header().Set("Content-Type", "text/html; charset=utf-8") if err := pages.ExecuteTemplate(w, "home.html", data); err != nil { diff --git a/static/css/main.css b/static/css/main.css index 38977e5..df2c466 100644 --- a/static/css/main.css +++ b/static/css/main.css @@ -13,11 +13,16 @@ } body { + min-height: 100vh; background-color: var(--bg); color: var(--text); margin: 0; font-family: Consolas, monospace; font-size: 14px; + background-image:var(--qt-url); + background-repeat: no-repeat; + background-position: bottom right; + background-size: auto 256px; } h1, @@ -173,6 +178,12 @@ option { font: inherit; } +img, +video, +audio { + max-width: 100%; +} + .upload-links { margin-top: 12px; display: flex; diff --git a/templates/home.html b/templates/home.html index c633bf8..9527c82 100644 --- a/templates/home.html +++ b/templates/home.html @@ -6,6 +6,13 @@ minibin + {{if .Qt}} + + {{end}} diff --git a/templates/upload.html b/templates/upload.html index 4d691c7..0634b12 100644 --- a/templates/upload.html +++ b/templates/upload.html @@ -3,7 +3,7 @@ - minibin + {{.ID}} | minibin