Partial working form and announcements settings.
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
This commit is contained in:
parent
e614ab79fa
commit
9a504d1638
@ -21,14 +21,24 @@ var (
|
||||
func CheckAnn() {
|
||||
if resAnn == "true" {
|
||||
Announcements()
|
||||
AnnPage()
|
||||
} else {
|
||||
log.Println("Announcements disabled")
|
||||
http.HandleFunc("/api/announcements", func(w http.ResponseWriter, r *http.Request) {
|
||||
http.HandleFunc("/announcements", func(w http.ResponseWriter, r *http.Request) {
|
||||
http.Error(w, "Announcements are disabled.", http.StatusNotFound)
|
||||
})
|
||||
http.HandleFunc("/api/announcements", func(w http.ResponseWriter, r *http.Request) {
|
||||
http.Error(w, "{\"enabled\": \"false\"}", http.StatusNotFound)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func AnnPage() {
|
||||
http.HandleFunc("/announcements", func(w http.ResponseWriter, r *http.Request) {
|
||||
http.ServeFile(w, r, "static/announcements.html")
|
||||
})
|
||||
}
|
||||
|
||||
func Announcements() {
|
||||
http.HandleFunc("/api/announcements", getAnnouncements)
|
||||
http.HandleFunc("/api/announcements/post", handleAnnouncements)
|
||||
|
18
api/form.go
18
api/form.go
@ -6,6 +6,7 @@ import (
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
"github.com/ProjectSegfault/segfautils/config"
|
||||
"github.com/ProjectSegfault/segfautils/utils"
|
||||
@ -22,6 +23,7 @@ var (
|
||||
|
||||
func FormCheck() {
|
||||
if resForm == "true" {
|
||||
FormPage()
|
||||
Form()
|
||||
} else {
|
||||
log.Println("Forms disabled")
|
||||
@ -31,6 +33,22 @@ func FormCheck() {
|
||||
}
|
||||
}
|
||||
|
||||
func FormPage() {
|
||||
type StaticThing struct {
|
||||
HCaptchaSiteKey string
|
||||
}
|
||||
|
||||
tmpl_form := template.Must(template.ParseFiles("static/form.html"))
|
||||
http.HandleFunc("/form/", func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
hcaptcha_site_key := config.HCaptchaSiteKey()
|
||||
data := StaticThing{
|
||||
HCaptchaSiteKey: hcaptcha_site_key,
|
||||
}
|
||||
tmpl_form.Execute(w, data)
|
||||
})
|
||||
}
|
||||
|
||||
func Form() {
|
||||
http.HandleFunc("/api/form", client.HandlerFunc(theActualFormCode))
|
||||
}
|
||||
|
26
main.go
26
main.go
@ -12,18 +12,13 @@ import (
|
||||
)
|
||||
|
||||
type StaticThingy struct {
|
||||
Port string
|
||||
HCaptchaSiteKey string
|
||||
Port string
|
||||
}
|
||||
|
||||
var port string
|
||||
var shit bool
|
||||
|
||||
func main() {
|
||||
log.Println("[Segfautils] Starting")
|
||||
utils.CheckConfig()
|
||||
log.Println("[HTTP] Starting server")
|
||||
hcaptcha_site_key := config.HCaptchaSiteKey()
|
||||
|
||||
tmpl := template.Must(template.ParseFiles("static/index.html"))
|
||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
data := StaticThingy{
|
||||
@ -32,22 +27,15 @@ func main() {
|
||||
tmpl.Execute(w, data)
|
||||
})
|
||||
|
||||
tmpl_form := template.Must(template.ParseFiles("static/form.html"))
|
||||
http.HandleFunc("/form/", func(w http.ResponseWriter, r *http.Request) {
|
||||
data := StaticThingy{
|
||||
HCaptchaSiteKey: hcaptcha_site_key,
|
||||
}
|
||||
tmpl_form.Execute(w, data)
|
||||
})
|
||||
log.Println("[HTTP] Starting server")
|
||||
api.CheckAnn()
|
||||
api.FormCheck()
|
||||
|
||||
http.HandleFunc("/api/", func(w http.ResponseWriter, r *http.Request) {
|
||||
io.WriteString(w, "welcome to hell")
|
||||
})
|
||||
http.HandleFunc("/announcements", func(w http.ResponseWriter, r *http.Request) {
|
||||
http.ServeFile(w, r, "static/announcements.html")
|
||||
})
|
||||
api.FormCheck()
|
||||
api.CheckAnn()
|
||||
|
||||
api.Form()
|
||||
log.Println("[HTTP] HTTP server is now running at " + config.Port() + "!")
|
||||
log.Println(http.ListenAndServe(":"+config.Port(), nil))
|
||||
}
|
||||
|
Reference in New Issue
Block a user