File: examples/plugins/webdav-browser/plugin.js (64 lines)
// webdav-browser: web setup for an XML (WebDAV PROPFIND) catalog.
//
// device.json has no way to compute base64, so this page does it once and
// stores the ready-made header value as cfg.auth ("Basic {cfg.auth}").
// The raw user/pass are also stored, for the file GET's HTTP Basic auth
// (download.username / download.password).
CrossPoint.registerPlugin(async (container, api) => {
const $ = (s) => container.querySelector(s);
const b64 = (t) => { let s = ''; for (const c of new TextEncoder().encode(t)) s += String.fromCharCode(c); return btoa(s); };
const write = (name, obj) => api.writeFile(`${api.dir}/${name}`, b64(JSON.stringify(obj)));
const read = async (name) => {
try { const r = await fetch(api.pluginFile(name)); return r.ok ? await r.json() : {}; } catch (e) { return {}; }
};
const PROPFIND_BODY = '<?xml version="1.0"?><d:propfind xmlns:d="DAV:"><d:prop><d:resourcetype/><d:displayname/></d:prop></d:propfind>';