thunderbird2docuware/lib/store.js

42 lines
1.4 KiB
JavaScript
Raw Permalink Normal View History

// Einstellungen lesen/schreiben (browser.storage.local).
// Wichtig: Das Passwort wird NICHT gespeichert. Es wird beim Login einmalig
// abgefragt, daraus ein OAuth-Token geholt und sofort verworfen (siehe auth.js
// + background.js). In storage.local liegen nur unkritische Daten.
const DEFAULTS = {
serverUrl: "", // z.B. https://docuware.example.com (ohne /DocuWare/Platform)
organization: "",
username: "",
defaultCabinetId: "",
dialogByCabinet: {}, // gemerkter Ablagedialog je Schrank: { [cabinetId]: dialogId }
storeEml: true,
storePdf: true,
storeAttachments: true,
tagOnSuccess: true,
};
const Settings = {
async get() {
const stored = await browser.storage.local.get("settings");
return { ...DEFAULTS, ...(stored.settings || {}) };
},
async set(partial) {
const current = await this.get();
const next = { ...current, ...partial };
// Sicherheitsnetz: Passwort darf NIE persistiert werden (z.B. aus Alt-Importen).
delete next.password;
await browser.storage.local.set({ settings: next });
return next;
},
/** Basis-URL der Platform-API ohne abschließenden Slash. */
platformUrl(settings) {
const base = (settings.serverUrl || "").replace(/\/+$/, "");
if (!base) throw new Error("Keine DocuWare-Server-URL konfiguriert.");
return `${base}/DocuWare/Platform`;
},
};
if (typeof module !== "undefined") module.exports = { Settings, DEFAULTS };