feat: add webdav support

This commit is contained in:
Yidadaa
2023-09-13 02:51:02 +08:00
parent 89bc98d26b
commit 6f83fbd212
16 changed files with 751 additions and 104 deletions

33
app/utils/cloud/index.ts Normal file
View File

@@ -0,0 +1,33 @@
import { createWebDavClient } from "./webdav";
import { createUpstashClient } from "./upstash";
export enum ProviderType {
WebDAV = "webdav",
UpStash = "upstash",
}
export const SyncClients = {
[ProviderType.UpStash]: createUpstashClient,
[ProviderType.WebDAV]: createWebDavClient,
} as const;
type SyncClientConfig = {
[K in keyof typeof SyncClients]: (typeof SyncClients)[K] extends (
_: infer C,
) => any
? C
: never;
};
export type SyncClient = {
get: (key: string) => Promise<string>;
set: (key: string, value: string) => Promise<void>;
check: () => Promise<boolean>;
};
export function createSyncClient<T extends ProviderType>(
provider: T,
config: SyncClientConfig[T],
): SyncClient {
return SyncClients[provider](config as any) as any;
}