Add Go rewrite with Postgres 17 and Dokploy Docker Compose
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"amnezia-share/internal/i18n"
|
||||
"amnezia-share/internal/models"
|
||||
"amnezia-share/internal/share"
|
||||
"amnezia-share/internal/web"
|
||||
)
|
||||
|
||||
func registerFAQ(a *web.App, mux *http.ServeMux) {
|
||||
mux.HandleFunc("GET /faq", FAQ(a))
|
||||
mux.HandleFunc("GET /rules", Rules(a))
|
||||
mux.HandleFunc("GET /status", Status(a))
|
||||
}
|
||||
|
||||
type faqEntry struct {
|
||||
Question string
|
||||
Answer string
|
||||
}
|
||||
|
||||
type faqView struct {
|
||||
Items []faqEntry
|
||||
}
|
||||
|
||||
// FAQ renders the guest-facing FAQ page (faq.php).
|
||||
func FAQ(a *web.App) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
lang := i18n.Resolve(r, a.Sessions)
|
||||
items := make([]faqEntry, 0, len(i18n.FAQItems))
|
||||
for _, it := range i18n.FAQItems {
|
||||
items = append(items, faqEntry{
|
||||
Question: i18n.T(lang, it.QuestionKey, nil),
|
||||
Answer: i18n.T(lang, it.AnswerKey, nil),
|
||||
})
|
||||
}
|
||||
a.Render(w, r, "page_faq", faqView{Items: items})
|
||||
}
|
||||
}
|
||||
|
||||
// Rules renders the acceptable-use rules page (rules.php).
|
||||
func Rules(a *web.App) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
a.Render(w, r, "page_rules", nil)
|
||||
}
|
||||
}
|
||||
|
||||
type serverStatus struct {
|
||||
models.ServerInfo
|
||||
Alive bool
|
||||
Ms int
|
||||
Err string
|
||||
}
|
||||
|
||||
type statusView struct {
|
||||
Servers []serverStatus
|
||||
}
|
||||
|
||||
// Status pings every configured server and reports online/offline (status.php).
|
||||
func Status(a *web.App) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
labels := a.Settings.ServerLabels(ctx)
|
||||
servers := share.BuildGuestServers(ctx, a.Settings, labels)
|
||||
baseURL := a.Settings.PanelURL(ctx)
|
||||
token := a.Settings.PanelToken(ctx)
|
||||
|
||||
list := make([]serverStatus, 0, len(servers))
|
||||
for _, s := range servers {
|
||||
st := serverStatus{ServerInfo: s}
|
||||
if baseURL != "" && token != "" {
|
||||
st.Alive, st.Ms, st.Err = a.Panel.Ping(ctx, baseURL, token, s.ID)
|
||||
}
|
||||
list = append(list, st)
|
||||
}
|
||||
a.Render(w, r, "page_status", statusView{Servers: list})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user