feat(backend): file-scoped content tokens for media URLs
Opening an original by URL (?access_token=) baked in the 15-minute access token, so a long video opened in a new tab stopped streaming once that token expired mid-playback: the access token can't be refreshed in an already-opened tab, and its next Range request 401'd. Add a content token: a signed, single-file capability (typ=content, fid claim) with its own longer TTL (CONTENT_TOKEN_TTL, default 6h) and — crucially — no session id, so it survives refresh rotation and outlives the short access TTL. POST /files/:id/content-token mints one after the same view-ACL check content serving does; GET /files/:id/content now runs under content-aware auth that accepts either a normal access token or a content token scoped to that file. View permission is still enforced against the token's user, so the token only changes when a file may be read by URL, never which files. It's a bearer capability for that one file until expiry, hence the bounded, configurable TTL. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
package handler
|
||||
|
||||
import "testing"
|
||||
|
||||
// TestNewRouterRegisters builds the router with typed-nil dependencies to assert
|
||||
// route registration itself succeeds. Gin panics on a route conflict (e.g. a
|
||||
// duplicated method+path or an inconsistent wildcard name) during registration,
|
||||
// before any handler runs — so this catches such mistakes without a database.
|
||||
// Handlers are never invoked here; method values on nil pointers are fine.
|
||||
func TestNewRouterRegisters(t *testing.T) {
|
||||
r, err := NewRouter(
|
||||
(*AuthMiddleware)(nil), (*AuthHandler)(nil),
|
||||
(*FileHandler)(nil), (*TagHandler)(nil), (*CategoryHandler)(nil), (*PoolHandler)(nil),
|
||||
(*UserHandler)(nil), (*ACLHandler)(nil), (*AuditHandler)(nil),
|
||||
"", nil,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("NewRouter: %v", err)
|
||||
}
|
||||
if r == nil {
|
||||
t.Fatal("NewRouter returned nil engine")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user