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
|
@ -1,56 +0,0 @@
|
|||
package view
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"arimelody-web/global"
|
||||
music "arimelody-web/music/controller"
|
||||
"arimelody-web/music/model"
|
||||
"arimelody-web/templates"
|
||||
)
|
||||
|
||||
// HTTP HANDLER METHODS
|
||||
|
||||
func Handler() http.Handler {
|
||||
mux := http.NewServeMux()
|
||||
|
||||
mux.Handle("/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path == "/" {
|
||||
ServeCatalog().ServeHTTP(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
release, err := music.GetRelease(global.DB, r.URL.Path[1:], true)
|
||||
if err != nil {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
ServeGateway(release).ServeHTTP(w, r)
|
||||
}))
|
||||
|
||||
return mux
|
||||
}
|
||||
|
||||
func ServeCatalog() http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
releases, err := music.GetAllReleases(global.DB, true, 0, true)
|
||||
if err != nil {
|
||||
fmt.Printf("FATAL: Failed to pull releases for catalog: %s\n", err)
|
||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
for _, release := range releases {
|
||||
if !release.IsReleased() {
|
||||
release.ReleaseType = model.Upcoming
|
||||
}
|
||||
}
|
||||
|
||||
err = templates.Pages["music"].Execute(w, releases)
|
||||
if err != nil {
|
||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||
}
|
||||
})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue