- Fix issues with new setup

- Fix arr setup getting thr wrong crendentials
- Add file link invalidator
- Other minor bug fixes
This commit is contained in:
Mukhtar Akere
2025-10-08 08:13:13 +01:00
parent 22dae9efad
commit 700d00b802
29 changed files with 606 additions and 465 deletions

View File

@@ -1,53 +1,58 @@
package web
import (
"github.com/go-chi/chi/v5"
"io/fs"
"net/http"
"github.com/go-chi/chi/v5"
)
func (wb *Web) Routes() http.Handler {
r := chi.NewRouter()
// Load static files from embedded filesystem
staticFS, err := fs.Sub(assetsEmbed, "assets/build")
if err != nil {
panic(err)
}
imagesFS, err := fs.Sub(imagesEmbed, "assets/images")
if err != nil {
panic(err)
}
// Static assets - always public
staticFS, _ := fs.Sub(assetsEmbed, "assets/build")
imagesFS, _ := fs.Sub(imagesEmbed, "assets/images")
r.Handle("/assets/*", http.StripPrefix("/assets/", http.FileServer(http.FS(staticFS))))
r.Handle("/images/*", http.StripPrefix("/images/", http.FileServer(http.FS(imagesFS))))
// Public routes - no auth needed
r.Get("/version", wb.handleGetVersion)
r.Get("/login", wb.LoginHandler)
r.Post("/login", wb.LoginHandler)
r.Get("/register", wb.RegisterHandler)
r.Post("/register", wb.RegisterHandler)
r.Get("/skip-auth", wb.skipAuthHandler)
r.Get("/version", wb.handleGetVersion)
r.Post("/skip-auth", wb.skipAuthHandler)
// Protected routes - require auth
r.Group(func(r chi.Router) {
r.Use(wb.authMiddleware)
r.Use(wb.setupMiddleware)
// Web pages
r.Get("/", wb.IndexHandler)
r.Get("/download", wb.DownloadHandler)
r.Get("/repair", wb.RepairHandler)
r.Get("/stats", wb.StatsHandler)
r.Get("/config", wb.ConfigHandler)
r.Get("/settings", wb.ConfigHandler)
// API routes
r.Route("/api", func(r chi.Router) {
// Arr management
r.Get("/arrs", wb.handleGetArrs)
r.Post("/add", wb.handleAddContent)
// Repair operations
r.Post("/repair", wb.handleRepairMedia)
r.Get("/repair/jobs", wb.handleGetRepairJobs)
r.Post("/repair/jobs/{id}/process", wb.handleProcessRepairJob)
r.Post("/repair/jobs/{id}/stop", wb.handleStopRepairJob)
r.Delete("/repair/jobs", wb.handleDeleteRepairJob)
// Torrent management
r.Get("/torrents", wb.handleGetTorrents)
r.Delete("/torrents/{category}/{hash}", wb.handleDeleteTorrent)
r.Delete("/torrents/", wb.handleDeleteTorrents)
r.Delete("/torrents", wb.handleDeleteTorrents) // Fixed trailing slash
// Config/Auth
r.Get("/config", wb.handleGetConfig)
r.Post("/config", wb.handleUpdateConfig)
r.Post("/refresh-token", wb.handleRefreshAPIToken)