让我们将其转换为RPC,这是一个建议:
type WebDavConfig = {
type: 'webdav',
endpoint: string,
username: string,
password: string
}
type UpstashConfig = {
type: 'upstash',
endpoint: string,
username: STORAGE_KEY,
apiKey: string
}
type SyncAction = {
type: 'check'
} | {
type: 'get',
key: string,
} | {
type: 'set',
key: string,
value: string
}
type SyncPayload = {
config: WebDavConfig | UpstashConfig,
action: SyncAction
}
// client side
function createUpstashClient() {
return async check() {
return await call('/api/sync', { /* webdav config */ })
},
// get(key), set(key, value)
}
// server side, /api/sync/route.ts
async function handle(req) {
const payload = JSON.parse(await req.json()) as SyncPayload;
// dispatch payload to server side check/get/set actions
}
主要思路是将之前在客户端完成的所有同步操作转移到服务器端。缺点是,除非我们保留内置的官方同步端点,否则桌面应用程序无法再使用同步功能。
- 最初由@Yidadaa在#4285(评论)中发布*
2条答案
按热度按时间vfwfrxfs1#
对于Web版本来说,这个特性是不可能实现的。
qlzsbp2j2#
对于
Tauri/desktop applications
,它更安全可靠,开发者可以轻松利用其功能(例如laverage feature that not possible for web version
),尤其是由于它是用Rust编写的。