package main import ( "gitea.seeseepuff.be/seeseemelk/mysqlite" "log" "net/http" ) func serveWebview(db *mysqlite.Db) { addr := "localhost:8081" log.Printf("Listening on %s", addr) http.Handle("/static/", http.StripPrefix("/static/", staticFileServer())) http.HandleFunc("/", serveIndex(db)) http.HandleFunc("/video/", serveVideo(db)) err := http.ListenAndServe(addr, nil) if err != nil { panic(err) } } func serveIndex(db *mysqlite.Db) func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) { // Query the database for the oldest unwatched episode var title, description, thumbnail string err := db.Query(`SELECT title, description, thumbnail FROM videos WHERE (watch_state IS NULL OR watch_state != 'watched') ORDER BY upload_date, episode LIMIT 1`).ScanSingle(&title, &description, &thumbnail) if err != nil { http.Error(w, "No unwatched episodes found", http.StatusNotFound) return } vm := VideoInfoVM{ Title: title, Description: description, Thumbnail: thumbnail, } err = renderTemplate(w, "index", vm) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) } } } func serveVideo(db *mysqlite.Db) func(w http.ResponseWriter, r *http.Request) { }