From 277fda3a6db3187f72ba3d3064c120d3c1351c9c Mon Sep 17 00:00:00 2001 From: Gregory Rudolph Date: Wed, 30 Dec 2020 12:47:59 -0500 Subject: [PATCH] API Endpoints for Verifications and Pending. --- main.go | 2 +- site-api.go | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 93cefb5..8a24a25 100644 --- a/main.go +++ b/main.go @@ -155,7 +155,7 @@ func runPurge(s *discordgo.Session) { func ready(s *discordgo.Session, event *discordgo.Ready) { // Set the playing status. - s.UpdateStatus(0, "DreamDaddy v1.2") + s.UpdateStatus(0, "DreamDaddy v1.3") } func guildMemberUpdate(s *discordgo.Session, m *discordgo.GuildMemberUpdate) { diff --git a/site-api.go b/site-api.go index 8c123a5..c81ec4f 100644 --- a/site-api.go +++ b/site-api.go @@ -6,6 +6,7 @@ import ( "io/ioutil" "net/http" "os" + "path/filepath" "strings" "github.com/gorilla/mux" @@ -128,6 +129,51 @@ func getPending(w http.ResponseWriter, r *http.Request) { } } +func getProbations(w http.ResponseWriter, r *http.Request) { + defer log.PanicSafe() + loggedIn, _ := detectUser(r, "getProbations") + if loggedIn { + pending, err := json.Marshal(config.Probations) + if err != nil { + log.LogErrorType(err) + notFoundPage(w, r) + } + fmt.Fprintf(w, string(pending)) + } else { + notFoundPage(w, r) + } +} +func getVerifications(w http.ResponseWriter, r *http.Request) { + defer log.PanicSafe() + loggedIn, _ := detectUser(r, "getVerifications") + if !loggedIn { + notFoundPage(w, r) + return + } + var files []string + root := "./verifications" + err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error { + files = append(files, path) + return nil + }) + if err != nil { + log.LogErrorType(err) + } + var v []Verification + for _, file := range files { + info := strings.Split(file, "-") + var ver Verification + ver.UserID = info[0] + ver.Username = info[1] + ver.Photo = info[2] + v = append(v, ver) + } + verifications, err := json.Marshal(v) + if err != nil { + log.LogErrorType(err) + } + fmt.Fprintf(w, string(verifications)) +} func runWeb() { defer log.PanicSafe() router := mux.NewRouter().StrictSlash(true) @@ -137,6 +183,8 @@ func runWeb() { router.HandleFunc("/login", loginPage) router.HandleFunc("/api/login", tryLogin) router.HandleFunc("/api/pending", getPending) + router.HandleFunc("/api/verifications", getVerifications) + router.HandleFunc("/api/probations", getProbations) router.HandleFunc("/api/passreq", reqPass) router.HandleFunc("/", greetUser) router.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir("./static"))))