Routes sets up the proxy routes
(r chi.Router)
| 394 | |
| 395 | // Routes sets up the proxy routes |
| 396 | func (h *Handler) Routes(r chi.Router) { |
| 397 | // Proxy route with API key parameter |
| 398 | proxyRoute := httphelpers.JoinBasePath(h.basePath, "/proxy/{api-key}") |
| 399 | proxyRouter := r.With(ClientAPIKeyMiddleware(h.clientAPIKeyStore)) |
| 400 | |
| 401 | // Scoped proxy routes retain API key middleware and prepare proxy context |
| 402 | proxyRouter.Route(proxyRoute, func(pr chi.Router) { |
| 403 | // Apply proxy context middleware (adds instance info to context) |
| 404 | pr.Use(h.prepareProxyContextMiddleware) |
| 405 | |
| 406 | pr.Post("/api/v2/torrents/reannounce", h.handleReannounce) |
| 407 | |
| 408 | // Register intercepted endpoints (these use qui's sync manager or special handling) |
| 409 | pr.Post("/api/v2/auth/login", h.handleAuthLogin) |
| 410 | pr.Get("/api/v2/sync/maindata", h.handleSyncMainData) |
| 411 | pr.Get("/api/v2/sync/torrentPeers", h.handleTorrentPeers) |
| 412 | pr.Get("/api/v2/torrents/info", h.handleTorrentsInfo) |
| 413 | pr.Get("/api/v2/torrents/categories", h.handleCategories) |
| 414 | pr.Get("/api/v2/torrents/tags", h.handleTags) |
| 415 | pr.Get("/api/v2/torrents/properties", h.handleTorrentProperties) |
| 416 | pr.Get("/api/v2/torrents/trackers", h.handleTorrentTrackers) |
| 417 | pr.Get("/api/v2/torrents/files", h.handleTorrentFiles) |
| 418 | pr.Get("/api/v2/torrents/search", h.handleTorrentSearch) |
| 419 | pr.Get("/api/v2/torrents/mediainfo", h.handleTorrentMediaInfo) |
| 420 | |
| 421 | // Intercepted write operations for cache invalidation |
| 422 | pr.Post("/api/v2/torrents/setLocation", h.handleSetLocation) |
| 423 | pr.Post("/api/v2/torrents/renameFile", h.handleRenameFile) |
| 424 | pr.Post("/api/v2/torrents/renameFolder", h.handleRenameFolder) |
| 425 | pr.Post("/api/v2/torrents/delete", h.handleDeleteTorrents) |
| 426 | |
| 427 | // Handle the base proxy path and any nested paths requested through the proxy |
| 428 | pr.HandleFunc("/", h.ServeHTTP) |
| 429 | pr.HandleFunc("/*", h.ServeHTTP) |
| 430 | }) |
| 431 | } |
| 432 | |
| 433 | func (h *Handler) prepareProxyContext(r *http.Request) (*proxyContext, error) { |
| 434 | ctx := r.Context() |
no test coverage detected