refactor
This commit is contained in:
		
							parent
							
								
									86996d9563
								
							
						
					
					
						commit
						5603cb7e22
					
				|  | @ -86,7 +86,7 @@ const storageProvider: StorageProvider = { | ||||||
| 		}); | 		}); | ||||||
| 	}, | 	}, | ||||||
| 
 | 
 | ||||||
| 	cloudGets: async (ctx) => { | 	cloudGetBulk: async (ctx) => { | ||||||
| 		// TODO: 値の取得を1つのリクエストで済ませたい(バックエンド側でAPIの新設が必要)
 | 		// TODO: 値の取得を1つのリクエストで済ませたい(バックエンド側でAPIの新設が必要)
 | ||||||
| 		const fetchings = ctx.needs.map(need => storageProvider.cloudGet(need).then(res => [need.key, res] as const)); | 		const fetchings = ctx.needs.map(need => storageProvider.cloudGet(need).then(res => [need.key, res] as const)); | ||||||
| 		const cloudDatas = await Promise.all(fetchings); | 		const cloudDatas = await Promise.all(fetchings); | ||||||
|  |  | ||||||
|  | @ -79,7 +79,7 @@ export type PreferencesProfile = { | ||||||
| 
 | 
 | ||||||
| export type StorageProvider = { | export type StorageProvider = { | ||||||
| 	save: (ctx: { profile: PreferencesProfile; }) => void; | 	save: (ctx: { profile: PreferencesProfile; }) => void; | ||||||
| 	cloudGets: <K extends keyof PREF>(ctx: { needs: { key: K; scope: Scope; }[] }) => Promise<Partial<Record<K, ValueOf<K>>>>; | 	cloudGetBulk: <K extends keyof PREF>(ctx: { needs: { key: K; scope: Scope; }[] }) => Promise<Partial<Record<K, ValueOf<K>>>>; | ||||||
| 	cloudGet: <K extends keyof PREF>(ctx: { key: K; scope: Scope; }) => Promise<{ value: ValueOf<K>; } | null>; | 	cloudGet: <K extends keyof PREF>(ctx: { key: K; scope: Scope; }) => Promise<{ value: ValueOf<K>; } | null>; | ||||||
| 	cloudSet: <K extends keyof PREF>(ctx: { key: K; scope: Scope; value: ValueOf<K>; }) => Promise<void>; | 	cloudSet: <K extends keyof PREF>(ctx: { key: K; scope: Scope; value: ValueOf<K>; }) => Promise<void>; | ||||||
| }; | }; | ||||||
|  | @ -240,7 +240,7 @@ export class PreferencesManager { | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		const cloudValues = await this.storageProvider.cloudGets({ needs }); | 		const cloudValues = await this.storageProvider.cloudGetBulk({ needs }); | ||||||
| 
 | 
 | ||||||
| 		for (const _key in PREF_DEF) { | 		for (const _key in PREF_DEF) { | ||||||
| 			const key = _key as keyof PREF; | 			const key = _key as keyof PREF; | ||||||
|  |  | ||||||
|  | @ -140,7 +140,7 @@ function importProfile() { | ||||||
| export async function cloudBackup() { | export async function cloudBackup() { | ||||||
| 	if ($i == null) return; | 	if ($i == null) return; | ||||||
| 	if (!canAutoBackup()) { | 	if (!canAutoBackup()) { | ||||||
| 		throw new Error('Profile name is not set'); | 		throw new Error('cannot auto backup for this profile'); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	await misskeyApi('i/registry/set', { | 	await misskeyApi('i/registry/set', { | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue