/** * Storage REST API routes using Hono * * Supports multi-backend routing via `StorageRegistry`. Each endpoint * accepts an optional `storageId` parameter (query string or form field) * to target a named storage backend. When omitted, the default backend * is used. */ import { Hono } from "hono"; import { StorageController } from "./types"; import type { StorageRegistry } from "./storage-registry"; import { type StorageSourceDefinition, type AuthAdapter } from "@rebasepro/types"; import { HonoEnv } from "../api/types"; export interface StorageRoutesConfig { /** * Single storage controller (backward-compatible). * Used as fallback when no `registry` is provided. */ controller?: StorageController; /** * Full storage registry for multi-backend routing. * When provided, endpoints resolve the controller from `storageId` * parameter. Takes precedence over `controller`. */ registry?: StorageRegistry; /** * Declared storage sources, surfaced by `GET /sources` so the client can * bootstrap its registry. Carries the frontend `transport` (server vs * direct) and human-readable labels. Server-transport sources are also * derived from the registry; `direct` sources (e.g. Firebase Storage) only * exist here since the backend does not proxy them. */ sources?: StorageSourceDefinition[]; /** Base path for storage routes (default: '/api/storage') */ basePath?: string; /** Require authentication for write operations (default: true) */ requireAuth?: boolean; /** Allow unauthenticated read access to stored files (default: false). * When false and requireAuth is true, reads also require authentication. */ publicRead?: boolean; /** * When provided, storage routes delegate auth to this adapter instead * of the built-in JWT module. This mirrors how data routes use * `createAdapterAuthMiddleware()` and avoids the "JWT secret not * configured" crash when `configureJwt()` was never called. */ authAdapter?: AuthAdapter; } /** * Extract the wildcard portion of a route path from the full request path. * * Hono's `c.req.param('*')` does not work reliably in sub-routers mounted * via `app.route(prefix, subRouter)`. Instead we derive the wildcard value * from the fully-resolved `c.req.path` and `c.req.routePath`. * * For a route `/metadata/*` mounted at `/api/storage`, a request to * `/api/storage/metadata/default/file.jpg` yields routePath * `/api/storage/metadata/*`. We strip the prefix (everything before `/*`) * plus one character for the trailing `/` to obtain `default/file.jpg`. */ export declare function extractWildcardPath(c: { req: { path: string; routePath: string; }; }): string; /** * Create storage REST API routes */ export declare function createStorageRoutes(config: StorageRoutesConfig): Hono;