this is immensely broken but i swear i'll fix it later
This commit is contained in:
parent
e2ec731109
commit
d5f1fcb5e0
28 changed files with 409 additions and 253 deletions
|
@ -11,8 +11,8 @@ import (
|
|||
|
||||
"arimelody-web/discord"
|
||||
"arimelody-web/global"
|
||||
musicDB "arimelody-web/music/controller"
|
||||
musicModel "arimelody-web/music/model"
|
||||
"arimelody-web/controller"
|
||||
"arimelody-web/model"
|
||||
)
|
||||
|
||||
type loginData struct {
|
||||
|
@ -24,6 +24,7 @@ func Handler() http.Handler {
|
|||
mux := http.NewServeMux()
|
||||
|
||||
mux.Handle("/login", LoginHandler())
|
||||
mux.Handle("/create-account", createAccountHandler())
|
||||
mux.Handle("/logout", MustAuthorise(LogoutHandler()))
|
||||
mux.Handle("/static/", http.StripPrefix("/static", staticHandler()))
|
||||
mux.Handle("/release/", MustAuthorise(http.StripPrefix("/release", serveRelease())))
|
||||
|
@ -41,21 +42,21 @@ func Handler() http.Handler {
|
|||
return
|
||||
}
|
||||
|
||||
releases, err := musicDB.GetAllReleases(global.DB, false, 0, true)
|
||||
releases, err := controller.GetAllReleases(global.DB, false, 0, true)
|
||||
if err != nil {
|
||||
fmt.Printf("FATAL: Failed to pull releases: %s\n", err)
|
||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
artists, err := musicDB.GetAllArtists(global.DB)
|
||||
artists, err := controller.GetAllArtists(global.DB)
|
||||
if err != nil {
|
||||
fmt.Printf("FATAL: Failed to pull artists: %s\n", err)
|
||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
tracks, err := musicDB.GetOrphanTracks(global.DB)
|
||||
tracks, err := controller.GetOrphanTracks(global.DB)
|
||||
if err != nil {
|
||||
fmt.Printf("FATAL: Failed to pull orphan tracks: %s\n", err)
|
||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||
|
@ -63,9 +64,9 @@ func Handler() http.Handler {
|
|||
}
|
||||
|
||||
type IndexData struct {
|
||||
Releases []*musicModel.Release
|
||||
Artists []*musicModel.Artist
|
||||
Tracks []*musicModel.Track
|
||||
Releases []*model.Release
|
||||
Artists []*model.Artist
|
||||
Tracks []*model.Track
|
||||
}
|
||||
|
||||
err = pages["index"].Execute(w, IndexData{
|
||||
|
@ -149,14 +150,14 @@ func GetSession(r *http.Request) *Session {
|
|||
|
||||
func LoginHandler() http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if !discord.CREDENTIALS_PROVIDED || ADMIN_ID_DISCORD == "" {
|
||||
http.Error(w, http.StatusText(http.StatusServiceUnavailable), http.StatusServiceUnavailable)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println(discord.CLIENT_ID)
|
||||
fmt.Println(discord.API_ENDPOINT)
|
||||
fmt.Println(discord.REDIRECT_URI)
|
||||
// if !discord.CREDENTIALS_PROVIDED || ADMIN_ID_DISCORD == "" {
|
||||
// http.Error(w, http.StatusText(http.StatusServiceUnavailable), http.StatusServiceUnavailable)
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// fmt.Println(discord.CLIENT_ID)
|
||||
// fmt.Println(discord.API_ENDPOINT)
|
||||
// fmt.Println(discord.REDIRECT_URI)
|
||||
|
||||
code := r.URL.Query().Get("code")
|
||||
|
||||
|
@ -239,6 +240,17 @@ func LogoutHandler() http.Handler {
|
|||
})
|
||||
}
|
||||
|
||||
func createAccountHandler() http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
err := pages["create-account"].Execute(w, nil)
|
||||
if err != nil {
|
||||
fmt.Printf("Error rendering admin crearte account page: %s\n", err)
|
||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func staticHandler() http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
info, err := os.Stat(filepath.Join("admin", "static", filepath.Clean(r.URL.Path)))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue