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 {
|
type HomePageData struct {
|
||||||
Expiries []Expiry
|
Expiries []Expiry
|
||||||
|
Qt string
|
||||||
}
|
}
|
||||||
|
|
||||||
func health(w http.ResponseWriter, r *http.Request) {
|
func health(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"html/template"
|
"html/template"
|
||||||
"log"
|
"log"
|
||||||
|
"math/rand/v2"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -39,16 +43,42 @@ func main() {
|
|||||||
log.Fatal(err)
|
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()
|
mux := http.NewServeMux()
|
||||||
fs := http.FileServer(http.Dir("static"))
|
fs := http.FileServer(http.Dir("static"))
|
||||||
mux.Handle("GET /css/", fs)
|
mux.Handle("GET /css/", fs)
|
||||||
mux.Handle("GET /js/", fs)
|
mux.Handle("GET /js/", fs)
|
||||||
mux.Handle("GET /static/", http.StripPrefix("/static/", 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) {
|
mux.HandleFunc("GET /{$}", func(w http.ResponseWriter, r *http.Request) {
|
||||||
data := HomePageData{
|
data := HomePageData{
|
||||||
Expiries: config.Expiries,
|
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")
|
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||||
|
|
||||||
if err := pages.ExecuteTemplate(w, "home.html", data); err != nil {
|
if err := pages.ExecuteTemplate(w, "home.html", data); err != nil {
|
||||||
|
|||||||
@@ -13,11 +13,16 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
|
min-height: 100vh;
|
||||||
background-color: var(--bg);
|
background-color: var(--bg);
|
||||||
color: var(--text);
|
color: var(--text);
|
||||||
margin: 0;
|
margin: 0;
|
||||||
font-family: Consolas, monospace;
|
font-family: Consolas, monospace;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
|
background-image:var(--qt-url);
|
||||||
|
background-repeat: no-repeat;
|
||||||
|
background-position: bottom right;
|
||||||
|
background-size: auto 256px;
|
||||||
}
|
}
|
||||||
|
|
||||||
h1,
|
h1,
|
||||||
@@ -173,6 +178,12 @@ option {
|
|||||||
font: inherit;
|
font: inherit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
img,
|
||||||
|
video,
|
||||||
|
audio {
|
||||||
|
max-width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
.upload-links {
|
.upload-links {
|
||||||
margin-top: 12px;
|
margin-top: 12px;
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|||||||
@@ -6,6 +6,13 @@
|
|||||||
<title>minibin</title>
|
<title>minibin</title>
|
||||||
<link rel="stylesheet" href="/css/main.css" />
|
<link rel="stylesheet" href="/css/main.css" />
|
||||||
<script defer src="/js/dnd.js"></script>
|
<script defer src="/js/dnd.js"></script>
|
||||||
|
{{if .Qt}}
|
||||||
|
<style>
|
||||||
|
:root {
|
||||||
|
--qt-url: url("{{.Qt}}");
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
{{end}}
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body class="home-page" id="home-page">
|
<body class="home-page" id="home-page">
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<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" />
|
<link rel="stylesheet" href="/css/main.css" />
|
||||||
</head>
|
</head>
|
||||||
<script src="/js/copy.js" defer></script>
|
<script src="/js/copy.js" defer></script>
|
||||||
|
|||||||
Reference in New Issue
Block a user