early implementation of ari melody LIVE tracker
This commit is contained in:
parent
f7b3faf8e8
commit
9274796729
10 changed files with 335 additions and 39 deletions
47
main.go
47
main.go
|
@ -22,7 +22,6 @@ import (
|
|||
"arimelody-web/cursor"
|
||||
"arimelody-web/log"
|
||||
"arimelody-web/model"
|
||||
"arimelody-web/templates"
|
||||
"arimelody-web/view"
|
||||
|
||||
"github.com/jmoiron/sqlx"
|
||||
|
@ -40,6 +39,7 @@ func main() {
|
|||
|
||||
app := model.AppState{
|
||||
Config: controller.GetConfig(),
|
||||
Twitch: nil,
|
||||
}
|
||||
|
||||
// initialise database connection
|
||||
|
@ -460,6 +460,11 @@ func main() {
|
|||
// handle DB migrations
|
||||
controller.CheckDBVersionAndMigrate(app.DB)
|
||||
|
||||
err = controller.TwitchSetup(&app)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "WARN: Failed to set up Twitch integration: %v\n", err)
|
||||
}
|
||||
|
||||
// initial invite code
|
||||
accountsCount := 0
|
||||
err = app.DB.Get(&accountsCount, "SELECT count(*) FROM account")
|
||||
|
@ -511,49 +516,13 @@ func createServeMux(app *model.AppState) *http.ServeMux {
|
|||
mux.Handle("/admin/", http.StripPrefix("/admin", admin.Handler(app)))
|
||||
mux.Handle("/api/", http.StripPrefix("/api", api.Handler(app)))
|
||||
mux.Handle("/music/", http.StripPrefix("/music", view.MusicHandler(app)))
|
||||
mux.Handle("/uploads/", http.StripPrefix("/uploads", staticHandler(filepath.Join(app.Config.DataDirectory, "uploads"))))
|
||||
mux.Handle("/uploads/", http.StripPrefix("/uploads", view.StaticHandler(filepath.Join(app.Config.DataDirectory, "uploads"))))
|
||||
mux.Handle("/cursor-ws", cursor.Handler(app))
|
||||
mux.Handle("/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method == http.MethodHead {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
return
|
||||
}
|
||||
|
||||
if r.URL.Path == "/" || r.URL.Path == "/index.html" {
|
||||
err := templates.IndexTemplate.Execute(w, nil)
|
||||
if err != nil {
|
||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||
}
|
||||
return
|
||||
}
|
||||
staticHandler("public").ServeHTTP(w, r)
|
||||
}))
|
||||
mux.Handle("/", view.IndexHandler(app))
|
||||
|
||||
return mux
|
||||
}
|
||||
|
||||
func staticHandler(directory string) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
info, err := os.Stat(filepath.Join(directory, filepath.Clean(r.URL.Path)))
|
||||
|
||||
// does the file exist?
|
||||
if err != nil {
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// is thjs a directory? (forbidden)
|
||||
if info.IsDir() {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
http.FileServer(http.Dir(directory)).ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
|
||||
var PoweredByStrings = []string{
|
||||
"nerd rage",
|
||||
"estrogen",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue