chore: 导入清理前的完整工程状态(含 Capacitor 原生壳,作为回滚备份点)
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import type { CloudbaseFunctionCaller } from './yunlefunAuth'
|
||||
import type { UserDataRemote } from '~/utils/userDataSync'
|
||||
|
||||
export const USER_DATA_FUNCTION = 'cook-user-data'
|
||||
|
||||
interface FunctionResult {
|
||||
code?: string
|
||||
document?: unknown
|
||||
ok?: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* Talks to the `cook-user-data` cloud function, which stores one document per
|
||||
* account. The function takes the account from the verified session, so the
|
||||
* client never names a uid.
|
||||
*/
|
||||
export function createCloudbaseUserDataRemote(callFunction: CloudbaseFunctionCaller): UserDataRemote {
|
||||
async function call(data: Record<string, unknown>): Promise<FunctionResult> {
|
||||
const result = await callFunction(USER_DATA_FUNCTION, data) as FunctionResult | null
|
||||
if (!result || result.ok !== true)
|
||||
throw new Error(`${USER_DATA_FUNCTION} failed: ${result?.code ?? 'unknown'}`)
|
||||
return result
|
||||
}
|
||||
|
||||
return {
|
||||
read: async () => (await call({ action: 'get' })).document ?? null,
|
||||
write: async (_uid, document) => {
|
||||
await call({ action: 'set', document: { ...document } })
|
||||
},
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user