Skip to content

Commit

Permalink
retry on WebDAV drive error + check url
Browse files Browse the repository at this point in the history
  • Loading branch information
tophf committed Jan 8, 2025
1 parent 6ff6cf5 commit f45471c
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/background/sync-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as chromeSync from '@/js/chrome-sync';
import * as prefs from '@/js/prefs';
import {chromeLocal} from '@/js/storage-util';
import * as STATES from '@/js/sync-util';
import {fetchWebDAV, hasOwn, t} from '@/js/util';
import {fetchWebDAV, hasOwn, t, tryURL} from '@/js/util';
import {broadcastExtension} from './broadcast';
import {uuidIndex} from './common';
import {db} from './db';
Expand Down Expand Up @@ -100,7 +100,7 @@ export async function start(name = delayedInit) {
if ((ctrl ??= initController()).then) ctrl = await ctrl;
if (curDrive) return;
curDriveName = name;
curDrive = getDrive(name); // preventing re-entry by assigning synchronously
curDrive = getDrive(name).catch(console.error); // preventing re-entry by assigning synchronously
curDrive = await curDrive;
ctrl.use(curDrive);
status.state = STATES.connecting;
Expand Down Expand Up @@ -273,6 +273,10 @@ async function getDrive(name) {
if (!hasOwn(cloudDrive, name)) throw new Error(`Unknown cloud provider: ${name}`);
const opts = await getDriveOptions(name);
const webdav = name === 'webdav';
if (webdav && !tryURL(opts.url)) {
prefs.set(PREF_ID, 'none');
throw new Error('Broken options: WebDAV server URL is missing');
}
if (!__.MV3 || !webdav) opts.getAccessToken = () => getToken(name);
if (!__.MV3 && webdav) opts.fetch = fetchWebDAV.bind(opts);
return cloudDrive[name](opts);
Expand Down

0 comments on commit f45471c

Please sign in to comment.