fixes
This commit is contained in:
@@ -1,12 +1,18 @@
|
||||
let serverUrl = '';
|
||||
|
||||
browser.storage.sync.get('serverUrl').then(r => {
|
||||
if (r.serverUrl) serverUrl = r.serverUrl.replace(/\/+$/, '');
|
||||
});
|
||||
function norm(v) {
|
||||
return (v || '').replace(/\/+$/, '');
|
||||
}
|
||||
|
||||
async function getServerUrl() {
|
||||
const r = await browser.storage.sync.get('serverUrl');
|
||||
serverUrl = norm(r.serverUrl);
|
||||
return serverUrl;
|
||||
}
|
||||
|
||||
browser.storage.onChanged.addListener(changes => {
|
||||
if (changes.serverUrl) {
|
||||
serverUrl = changes.serverUrl.newValue.replace(/\/+$/, '');
|
||||
serverUrl = norm(changes.serverUrl.newValue);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -22,10 +28,18 @@ browser.runtime.onMessage.addListener((msg, sender) => {
|
||||
});
|
||||
|
||||
async function request(path, opts) {
|
||||
if (!serverUrl) throw new Error('Server URL not configured');
|
||||
const base = await getServerUrl();
|
||||
if (!base) {
|
||||
throw new Error('Server URL not set — open snotes and click "Capture" → "Apply to Extension", or set it in Options');
|
||||
}
|
||||
opts = opts || {};
|
||||
opts.credentials = 'include';
|
||||
const res = await fetch(serverUrl + path, opts);
|
||||
let res;
|
||||
try {
|
||||
res = await fetch(base + path, opts);
|
||||
} catch (e) {
|
||||
throw new Error('Cannot reach ' + base + ' (' + e.message + ')');
|
||||
}
|
||||
if (!res.ok) {
|
||||
const err = await res.json().catch(() => ({}));
|
||||
throw new Error(err.detail || 'HTTP ' + res.status);
|
||||
|
||||
Reference in New Issue
Block a user