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
This commit is contained in:
@@ -25,6 +25,7 @@ import (
|
||||
|
||||
type HomePageData struct {
|
||||
Expiries []Expiry
|
||||
Qt string
|
||||
}
|
||||
|
||||
func health(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -6,6 +6,13 @@
|
||||
<title>minibin</title>
|
||||
<link rel="stylesheet" href="/css/main.css" />
|
||||
<script defer src="/js/dnd.js"></script>
|
||||
{{if .Qt}}
|
||||
<style>
|
||||
:root {
|
||||
--qt-url: url("{{.Qt}}");
|
||||
}
|
||||
</style>
|
||||
{{end}}
|
||||
</head>
|
||||
|
||||
<body class="home-page" id="home-page">
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>minibin</title>
|
||||
<title>{{.ID}} | minibin</title>
|
||||
<link rel="stylesheet" href="/css/main.css" />
|
||||
</head>
|
||||
<script src="/js/copy.js" defer></script>
|
||||
|
||||
Reference in New Issue
Block a user