56abcb4a6c
* feat(sync): S3-compatible cloud sync provider with premium-gated chooser Add a third file-sync backend for any SigV4 object store (Cloudflare R2, AWS S3, MinIO, Backblaze B2), end to end: SigV4 transport via aws4fetch (path-style addressing, ListObjectsV2 with page draining, per-key deletes, presigned streaming on Tauri, Drive-style error mapping and backoff), S3 settings slice and defaults, exclusive provider activation and cross-window flag broadcast, registry memoization, and an Integrations chooser entry plus connect form that validates the bucket with one signed listing. Shared helpers settingsKeyForBackend and cloudProviderDisplayName replace the scattered per-kind ternaries across the reader and library sync hooks, fleet detection, and the settings surfaces. The chooser now marks third-party providers with a Premium badge and enforces the paywall (CLOUD_SYNC_REQUIRES_PREMIUM on): free plans see the rows but route to the upgrade page instead of the config sub-pages, and a downgraded account's still-selected provider is paused rather than silently falling back to Readest Cloud uploads. Manual provider sync now reports "N book(s) synced" like the native cloud sync, from the engine result returned by runActiveFileLibrarySync. The S3 transport passes the same provider semantic contract as WebDAV and Google Drive. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * perf(sync): make the library row the ground truth for local file presence Every sync run re-walked all books whose file is recorded nowhere and paid two plugin:fs|exists IPC per book per run on Tauri, just to relearn "no local source", ending in 0 books synced. The library row already tracks local presence reliably (import, download, and delete all stamp downloadedAt, and the metadata merge keeps it device-local), so the file-push gate now trusts the row: a book the row marks as absent costs zero filesystem and zero remote probes, keeping incremental sync a pure metadata diff at any library size. A session-scoped per-provider memo additionally suppresses re-probes of drifted rows (the row claims a file the filesystem no longer has), keyed to the book's updatedAt so any local change re-qualifies it. Row-vs-filesystem split-brain in either direction is healed by Full Sync, which bypasses the gate, the memo, and the uploaded-file record and audits the real filesystem. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(sync): tiered request timeouts for the WebDAV client An unreachable or dead server (a LAN host that went away) left PROPFIND and HEAD requests pending indefinitely, pinning the Integrations panel on "Syncing..." and the browse pane on a spinner. Metadata round-trips (PROPFIND, HEAD, MKCOL, DELETE) answer with headers only, so they now abort after 5 seconds; GET and PUT carry book-sized bodies over possibly slow links and keep a 5 minute ceiling instead. Expiry aborts the request via AbortController and surfaces as a "Request timed out" NETWORK failure through the existing WebDAVRequestError taxonomy. Since every library sync run opens with the HEAD etag probe on library.json, a dead server now fails the whole run within seconds. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(settings): provider panel status and layout fixes Three small fixes across the provider settings panels: - A completed manual "Sync now" clears the provider's lastError so the Cloud Sync chooser row and the SettingsMenu sync row stop reading "Sync failed" after the server comes back; a failed manual run now records the error for those surfaces too. Covered by a render harness that drives the real form against a mocked engine. - The sync row shows a relative "Synced a few seconds ago" label (same wording as the SettingsMenu row) instead of an absolute timestamp. - The Google Drive configured-but-inactive state rendered its Tips above the action buttons; Tips now close the page in every provider panel state. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * chore(i18n): translate the S3 provider and premium gating strings New keys from the S3-compatible provider (form fields, chooser entry, tips), the Premium badge, and the parameterized provider tips, translated across all 33 locales. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * chore(memory): record the S3 provider and sync optimization notes Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
90 lines
3.9 KiB
TypeScript
90 lines
3.9 KiB
TypeScript
import type { SystemSettings } from '@/types/settings';
|
|
import type { EnvConfigType } from '@/services/environment';
|
|
import type { FileSyncBackendKind } from '@/services/sync/file/providerRegistry';
|
|
import type { CloudSyncProviderKind } from '@/services/sync/cloudSyncProvider';
|
|
import { useSettingsStore } from '@/store/settingsStore';
|
|
import { broadcastGlobalSettings } from '@/utils/settingsSync';
|
|
|
|
/**
|
|
* The provider argument for activation: a third-party backend, or
|
|
* 'readest' / null (both mean "no third-party provider active" — Readest
|
|
* Cloud is the derived default, never a stored flag).
|
|
*/
|
|
export type CloudSyncActivationKind = CloudSyncProviderKind | null;
|
|
|
|
const isThirdParty = (active: CloudSyncActivationKind): active is FileSyncBackendKind =>
|
|
active === 'webdav' || active === 'gdrive' || active === 's3';
|
|
|
|
/**
|
|
* Return settings with exactly one third-party cloud-sync provider active (or
|
|
* none — passing 'readest' or null). WebDAV and Google Drive are mutually
|
|
* exclusive — only one syncs the library at a time — so enabling one always
|
|
* disables the other. Provider config (WebDAV creds, the Drive keychain
|
|
* token) is left untouched, so switching back to a previously-configured
|
|
* provider needs no re-entry; only an explicit Disconnect tears a provider's
|
|
* config down.
|
|
*
|
|
* Activating a provider (disabled -> enabled) also turns its `syncBooks` on
|
|
* and stamps `providerSelectedAt`: the selected provider owns the book-file
|
|
* channel — native Readest Cloud uploads gate off — so leaving syncBooks at
|
|
* its `false` default would back books up nowhere, and the timestamp anchors
|
|
* the mixed-fleet detection probe. An explicit syncBooks opt-out while the
|
|
* provider stays active is respected (re-activation changes nothing).
|
|
*/
|
|
export const withActiveCloudProvider = (
|
|
settings: SystemSettings,
|
|
active: CloudSyncActivationKind,
|
|
): SystemSettings => ({
|
|
...settings,
|
|
webdav: {
|
|
...settings.webdav,
|
|
enabled: active === 'webdav',
|
|
...(active === 'webdav' && !settings.webdav?.enabled
|
|
? { syncBooks: true, providerSelectedAt: Date.now() }
|
|
: {}),
|
|
},
|
|
googleDrive: {
|
|
...settings.googleDrive,
|
|
enabled: active === 'gdrive',
|
|
...(active === 'gdrive' && !settings.googleDrive?.enabled
|
|
? { syncBooks: true, providerSelectedAt: Date.now() }
|
|
: {}),
|
|
},
|
|
s3: {
|
|
...settings.s3,
|
|
enabled: active === 's3',
|
|
...(active === 's3' && !settings.s3?.enabled
|
|
? { syncBooks: true, providerSelectedAt: Date.now() }
|
|
: {}),
|
|
},
|
|
});
|
|
|
|
/**
|
|
* The single write path for changing the selected cloud sync provider.
|
|
* Every activation/deactivation surface (the Cloud Sync chooser, the
|
|
* WebDAV/Drive connect and disconnect flows, the Drive OAuth callback)
|
|
* routes through here so the change always (a) persists, (b) hydrates the
|
|
* settings store even on routes where it wasn't loaded yet (the OAuth
|
|
* callback), and (c) broadcasts the provider flags to other windows —
|
|
* a stale reader window would otherwise clobber the switch on its next
|
|
* whole-file save, silently resuming Readest Cloud uploads.
|
|
*
|
|
* `mutate` runs BEFORE activation so connect flows can apply credentials
|
|
* or account labels without pre-setting `enabled` (which would suppress
|
|
* the activation side effects).
|
|
*/
|
|
export const persistActiveCloudProvider = async (
|
|
envConfig: EnvConfigType,
|
|
active: CloudSyncActivationKind,
|
|
mutate: (settings: SystemSettings) => SystemSettings = (s) => s,
|
|
): Promise<SystemSettings> => {
|
|
const store = useSettingsStore.getState();
|
|
const appService = await envConfig.getAppService();
|
|
const current = store.settings?.version ? store.settings : await appService.loadSettings();
|
|
const next = withActiveCloudProvider(mutate(current), isThirdParty(active) ? active : null);
|
|
store.setSettings(next);
|
|
await appService.saveSettings(next);
|
|
void broadcastGlobalSettings(next, { includeCloudSyncProviders: true });
|
|
return next;
|
|
};
|