added privacy policy page and about section, improved dir check, fixed crash when idexer is disabled

This commit is contained in:
partisan 2025-01-05 19:23:53 +01:00
parent 61266c461a
commit 5ae97da6d0
18 changed files with 698 additions and 107 deletions

45
main.go
View file

@ -221,6 +221,7 @@ func runServer() {
http.HandleFunc("/save-settings", handleSaveSettings)
http.HandleFunc("/image/", handleImageServe)
http.HandleFunc("/image_status", handleImageStatus)
http.HandleFunc("/privacy", handlePrivacyPage)
http.HandleFunc("/opensearch.xml", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/opensearchdescription+xml")
http.ServeFile(w, r, "static/opensearch.xml")
@ -235,6 +236,7 @@ func runServer() {
http.HandleFunc("/save-settings", handleWebsiteDisabled)
http.HandleFunc("/image/", handleWebsiteDisabled)
http.HandleFunc("/image_status", handleWebsiteDisabled)
http.HandleFunc("/privacy", handleWebsiteDisabled)
http.HandleFunc("/opensearch.xml", handleWebsiteDisabled)
printInfo("Website functionality disabled.")
}
@ -252,3 +254,46 @@ func handleWebsiteDisabled(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusServiceUnavailable)
_, _ = w.Write([]byte("The website functionality is currently disabled."))
}
func handlePrivacyPage(w http.ResponseWriter, r *http.Request) {
settings := loadUserSettings(w, r)
iconPathSVG, iconPathPNG := GetIconPath()
// Define the data structure for the template
data := struct {
Theme string
IconPathSVG string
IconPathPNG string
IsThemeDark bool
CookieRows []CookieRow
CurrentLang string
Safe string
LanguageOptions []LanguageOption
}{
Theme: settings.Theme,
IconPathSVG: iconPathSVG,
IconPathPNG: iconPathPNG,
IsThemeDark: settings.IsThemeDark,
CookieRows: generateCookieTable(r),
CurrentLang: settings.SiteLanguage,
Safe: settings.SafeSearch,
LanguageOptions: languageOptions,
}
// Parse the template
tmpl, err := template.New("privacy.html").ParseFiles("templates/privacy.html")
if err != nil {
log.Printf("Error parsing template: %v", err)
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
return
}
// Set the response content type
w.Header().Set("Content-Type", "text/html; charset=utf-8")
// Execute the template
if err := tmpl.Execute(w, data); err != nil {
log.Printf("Error executing template: %v", err)
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
}
}