This commit is contained in:
2026-11-18 17:13:44 -05:00
parent a58d9af781
commit dc3b66cc58
5 changed files with 205 additions and 160 deletions
+33
View File
@@ -0,0 +1,33 @@
package main
import (
"net/http"
"gorm.io/gorm"
)
func newRouter(db *gorm.DB, cfg Config, pages *Pages, tracker *AccessTracker) http.Handler {
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 /{$}", homeHandler(pages, cfg))
mux.HandleFunc("GET /tos", staticPage(pages, "tos.html"))
mux.HandleFunc("GET /privacy", staticPage(pages, "privacy.html"))
mux.HandleFunc("GET /faq", faqHandler(pages, cfg))
uploads := http.NewServeMux()
uploads.HandleFunc("GET /{id}", contentHandler(db, cfg, tracker))
uploads.HandleFunc("GET /{id}/info", contentInfoHandler(db, tracker))
mux.Handle("/", uploads)
mux.HandleFunc("POST /upload", uploadHandler(db, cfg, pages))
mux.HandleFunc("PUT /upload", uploadHandler(db, cfg, pages))
mux.HandleFunc("DELETE /{id}", deleteHandler(db, cfg))
mux.HandleFunc("POST /{id}/delete", deleteHandler(db, cfg))
mux.HandleFunc("GET /health", health)
return mux
}