mirror of
				https://github.com/Yidadaa/ChatGPT-Next-Web.git
				synced 2025-10-31 21:59:19 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			34 lines
		
	
	
		
			787 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			34 lines
		
	
	
		
			787 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| 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;
 | |
| }
 |