2026-05-25 15:36:49 +03:00
|
|
|
package handlers
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"log/slog"
|
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
|
|
"warpbox.dev/backend/libs/config"
|
|
|
|
|
"warpbox.dev/backend/libs/services"
|
|
|
|
|
"warpbox.dev/backend/libs/web"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type App struct {
|
|
|
|
|
cfg config.Config
|
|
|
|
|
logger *slog.Logger
|
|
|
|
|
renderer *web.Renderer
|
|
|
|
|
uploadService *services.UploadService
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewApp(cfg config.Config, logger *slog.Logger, renderer *web.Renderer, uploadService *services.UploadService) *App {
|
|
|
|
|
return &App{
|
|
|
|
|
cfg: cfg,
|
|
|
|
|
logger: logger,
|
|
|
|
|
renderer: renderer,
|
|
|
|
|
uploadService: uploadService,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (a *App) RegisterRoutes(mux *http.ServeMux) {
|
|
|
|
|
mux.HandleFunc("GET /", a.Home)
|
2026-05-29 23:44:05 +03:00
|
|
|
mux.HandleFunc("GET /api", a.APIDocs)
|
2026-05-25 16:52:57 +03:00
|
|
|
mux.HandleFunc("GET /admin/login", a.AdminLogin)
|
|
|
|
|
mux.HandleFunc("POST /admin/login", a.AdminLoginPost)
|
|
|
|
|
mux.HandleFunc("POST /admin/logout", a.AdminLogout)
|
|
|
|
|
mux.HandleFunc("GET /admin", a.AdminDashboard)
|
|
|
|
|
mux.HandleFunc("GET /admin/files", a.AdminFiles)
|
2026-05-25 17:05:59 +03:00
|
|
|
mux.HandleFunc("GET /admin/boxes/{boxID}/view", a.AdminViewBox)
|
2026-05-25 16:52:57 +03:00
|
|
|
mux.HandleFunc("POST /admin/boxes/{boxID}/delete", a.AdminDeleteBox)
|
2026-05-25 16:26:47 +03:00
|
|
|
mux.HandleFunc("GET /d/{boxID}", a.DownloadPage)
|
2026-05-29 23:44:05 +03:00
|
|
|
mux.HandleFunc("GET /d/{boxID}/deleted", a.ManageDeleted)
|
|
|
|
|
mux.HandleFunc("GET /d/{boxID}/manage/{token}", a.ManageBox)
|
|
|
|
|
mux.HandleFunc("POST /d/{boxID}/manage/{token}/delete", a.ManageDeleteBox)
|
2026-05-25 16:52:57 +03:00
|
|
|
mux.HandleFunc("POST /d/{boxID}/unlock", a.UnlockBox)
|
2026-05-25 16:26:47 +03:00
|
|
|
mux.HandleFunc("GET /d/{boxID}/zip", a.DownloadZip)
|
|
|
|
|
mux.HandleFunc("GET /d/{boxID}/f/{fileID}", a.DownloadFile)
|
2026-05-25 16:52:57 +03:00
|
|
|
mux.HandleFunc("GET /d/{boxID}/f/{fileID}/download", a.DownloadFileContent)
|
|
|
|
|
mux.HandleFunc("GET /d/{boxID}/thumb/{fileID}", a.Thumbnail)
|
2026-05-25 15:36:49 +03:00
|
|
|
mux.HandleFunc("GET /healthz", a.Health)
|
|
|
|
|
mux.HandleFunc("GET /api/v1/health", a.Health)
|
2026-05-29 23:44:05 +03:00
|
|
|
mux.HandleFunc("GET /api/v1/sharex/warpbox-anonymous.sxcu", a.ShareXAnonymousConfig)
|
|
|
|
|
mux.HandleFunc("GET /api/v1/schemas/upload-request.json", a.UploadRequestSchema)
|
|
|
|
|
mux.HandleFunc("GET /api/v1/schemas/upload-response.json", a.UploadResponseSchema)
|
2026-05-25 16:26:47 +03:00
|
|
|
mux.HandleFunc("POST /api/v1/upload", a.Upload)
|
2026-05-25 15:36:49 +03:00
|
|
|
mux.Handle("GET /static/", a.Static())
|
|
|
|
|
}
|