Introduce the `WARPBOX_DATA_DIR` environment variable to define where runtime data is stored. This directory will house uploaded files, the bbolt metadata database, and application logs. Changes include: - Added `WARPBOX_DATA_DIR` to configuration, defaulting to `./data`. - Implemented a custom logging package that writes JSONL logs to the data directory. - Updated `.gitignore` and `.env.example` to support the new data directory. - Documented the runtime data structure in `README.md`. - Updated the frontend upload script to handle form submission and display results.
38 lines
982 B
Go
38 lines
982 B
Go
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)
|
|
mux.HandleFunc("GET /d/{boxID}", a.DownloadPage)
|
|
mux.HandleFunc("GET /d/{boxID}/zip", a.DownloadZip)
|
|
mux.HandleFunc("GET /d/{boxID}/f/{fileID}", a.DownloadFile)
|
|
mux.HandleFunc("GET /healthz", a.Health)
|
|
mux.HandleFunc("GET /api/v1/health", a.Health)
|
|
mux.HandleFunc("POST /api/v1/upload", a.Upload)
|
|
mux.Handle("GET /static/", a.Static())
|
|
}
|