import{a as e,c as t,d as n,f as r,l as i,o as a,s as o,u as s}from"./index-7yDgay5u.js";import{f as c,r as l}from"./attachment-encryption-DTWbJYgF.js";var u=`local`,d=`memory`,f=e({channel:`host`,key:`calendar-display-order`,schema:a([`newest-first`,`oldest-first`]),defaultValue:`oldest-first`}),p=e({channel:`host`,key:`message-link-detection`,schema:o(),defaultValue:!0}),m=e({channel:`host`,key:`cloud-sync`,schema:t(`provider`,[n({provider:i(`s3`),endpoint:r(),region:r(),bucket:r(),accessKeyId:r(),secretAccessKey:r(),prefix:r(),forcePathStyle:o(),recoveryKey:r().optional(),recoveryKeyHash:r().optional(),updatedAt:s()}),n({provider:i(`webdav`),url:r(),username:r(),password:r(),prefix:r(),recoveryKey:r().optional(),recoveryKeyHash:r().optional(),updatedAt:s()})]).optional(),defaultValue:void 0});function h(e){return{...e,updatedAt:Date.now()}}async function g(e,t){if(e===`memory`)return d;if(!t)return u;let n=await _(t);return n?`sync-${n}`:u}async function _(e){let t=await b(e);if(t)return(await x(JSON.stringify([e.provider,...v(e),c(e.prefix),t.trim().toLowerCase()]))).slice(0,32)}function v(e){return e.provider===`webdav`?[y(e.url)]:[y(e.endpoint),e.bucket.trim()]}function y(e){let t=e.trim().replace(/\/+$/,``);try{let e=new URL(t);return e.hash=``,e.search=``,`${e.origin}${e.pathname.replace(/\/+$/,``)}`}catch{return t.toLowerCase()}}async function b(e){let t=e.recoveryKeyHash?.trim();if(t)return t;let n=e.recoveryKey?.trim();if(n)return l(n)}async function x(e){let t=await crypto.subtle.digest(`SHA-256`,new TextEncoder().encode(e));return S(new Uint8Array(t))}function S(e){return Array.from(e).map(e=>e.toString(16).padStart(2,`0`)).join(``)}export{g as a,h as i,p as n,m as r,f as t};
//# sourceMappingURL=appPreferences-BKR9KWGS.js.map