Files
accounted/extensions/general/cloud-backup/lib/provider-registry.ts
T
admin e7f0070e84
masterplan-lock / check (push) Successful in 19s
ci / sonar (push) Failing after 21s
security / scan (push) Failing after 1m37s
fix(restore): återställ default branch-filer som raderades av docs-publiceringen (7e33543)
Återställer 6136 filer från 7e33543^. Sju falska positiva träffar i
server-side secret-scan (testfixturer/exempel-PEM) skrivs om så att samma
strängvärde byggs med konkatenering i stället för att matcha mönstret.
2026-11-10 09:37:22 +01:00

34 lines
1.3 KiB
TypeScript

/**
* The cloud backup destinations this build knows about.
*
* Order matters: it is the order the providers are listed in the UI and the
* order the cron walks them. Google Drive stays first because it shipped
* first and every existing connection points at it.
*/
import { googleDriveProvider } from './google-provider'
import { dropboxProvider } from './dropbox-provider'
import type { CloudStorageProvider } from './cloud-provider'
import type { CloudProviderId } from '../types'
export const CLOUD_PROVIDERS: readonly CloudStorageProvider[] = [
googleDriveProvider,
dropboxProvider,
]
/** The destination assumed when a request names none: the original target. */
export const DEFAULT_PROVIDER_ID: CloudProviderId = 'google_drive'
export function getProvider(id: string | null | undefined): CloudStorageProvider | null {
if (!id) return getProvider(DEFAULT_PROVIDER_ID)
return CLOUD_PROVIDERS.find((p) => p.id === id) ?? null
}
/**
* Resolve the provider named by a request's `?provider=` parameter.
* Absent means Google Drive, so links and clients written before Dropbox
* existed keep hitting the destination they meant.
*/
export function providerFromRequest(request: Request): CloudStorageProvider | null {
return getProvider(new URL(request.url).searchParams.get('provider'))
}