Fork pd_web, remove everything we don't need

This commit is contained in:
2025-09-24 15:37:57 +02:00
parent 9dcdd94b3a
commit fd5cd0bfd1
415 changed files with 146269 additions and 120786 deletions

View File

@@ -39,9 +39,6 @@ type WebController struct {
// Server hostname, displayed in the footer of every web page
hostname string
// page-specific variables
captchaSiteKey string
httpClient *http.Client
// API client to use for all requests. If the user is authenticated you
@@ -135,13 +132,7 @@ func New(r *httprouter.Router, prefix string, conf Config) (wc *WebController) {
{GET, "" /* */, wc.serveLandingPage()},
{GET, "home" /* */, wc.serveTemplate("home", handlerOpts{})},
{GET, "api" /* */, wc.serveMarkdown("api.md", handlerOpts{})},
{GET, "history" /* */, wc.serveTemplate("upload_history", handlerOpts{})},
{GET, "u/:id" /* */, wc.serveFileViewer},
{GET, "u/:id/preview" /* */, wc.serveFilePreview},
{GET, "l/:id" /* */, wc.serveListViewer},
{GET, "d/*path" /* */, wc.serveDirectory},
{GET, "t" /* */, wc.serveTemplate("text_upload", handlerOpts{})},
{GET, "donation" /* */, wc.serveMarkdown("donation.md", handlerOpts{})},
{GET, "widgets" /* */, wc.serveTemplate("widgets", handlerOpts{})},
{GET, "about" /* */, wc.serveMarkdown("about.md", handlerOpts{})},
{GET, "appearance" /* */, wc.serveTemplate("appearance", handlerOpts{})},
@@ -170,7 +161,6 @@ func New(r *httprouter.Router, prefix string, conf Config) (wc *WebController) {
{GET, "admin/*p", wc.serveTemplate("admin", handlerOpts{Auth: true})},
// Misc
{GET, "misc/sharex/pixeldrain.com.sxcu", wc.serveShareXConfig},
{GET, "theme.css", wc.themeHandler},
} {
r.Handle(h.method, prefix+"/"+h.path, middleware(h.handler))
@@ -187,10 +177,10 @@ func New(r *httprouter.Router, prefix string, conf Config) (wc *WebController) {
func middleware(handle httprouter.Handle) httprouter.Handle {
return func(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
// Redirect the user to the correct domain
if strings.HasPrefix(r.Host, "www.") {
if hostname, found := strings.CutPrefix(r.Host, "www."); found {
http.Redirect(
w, r,
"https://"+strings.TrimPrefix(r.Host, "www.")+r.URL.String(),
"https://"+hostname+r.URL.String(),
http.StatusMovedPermanently,
)
return
@@ -348,21 +338,3 @@ func (wc *WebController) getAPIKey(r *http.Request) (key string, err error) {
}
return "", errors.New("not a valid pixeldrain authentication cookie")
}
func (wc *WebController) captchaKey() string {
// This only runs on the first request
if wc.captchaSiteKey == "" {
capt, err := wc.api.GetMiscRecaptcha()
if err != nil {
log.Error("Error getting recaptcha key: %s", err)
return ""
}
if capt.SiteKey == "" {
wc.captchaSiteKey = "none"
} else {
wc.captchaSiteKey = capt.SiteKey
}
}
return wc.captchaSiteKey
}