feat(feeds): add opt-in Gecko relay and folder shortcuts
Document engine redistribution requirements; exclude upstream engine assets and keep the viewer disabled by default.
This commit is contained in:
1 parent
b23e63d4c6
commit
5321d613b4
37 files changed
+2051
-29
No files matched your search
@@ -0,0 +1,20 @@
|
||||
// Per-viewer volatile profile. Never use the SDK's default persistent OPFS
|
||||
// profile: article cookies/history must disappear when the iframe is removed.
|
||||
export function memoryProfile(limit = 32 * 1024 * 1024) {
|
||||
const entries = new Map([['', null]]); let bytes = 0;
|
||||
const path = value => {
|
||||
if(typeof value !== 'string' || value.length > 2048 || value.startsWith('/') || value.includes('\\') || value.includes('\0') || value.split('/').some(v => v === '..' || v === '.')) throw Error('Invalid profile path');
|
||||
return value.replace(/\/$/, '');
|
||||
};
|
||||
const parent = p => p.slice(0, Math.max(0, p.lastIndexOf('/')));
|
||||
const requireParent = p => { if(entries.get(parent(p)) !== null) throw Error('Missing profile directory'); };
|
||||
return {
|
||||
async stat(value) { const p = path(value); return !entries.has(p) ? null : {size: entries.get(p)?.length || 0, isDir: entries.get(p) === null}; },
|
||||
async readdir(value) { const p = path(value); if(entries.get(p) !== null) throw Error('Not a directory'); const prefix = p ? p+'/' : ''; return [...entries].filter(([k])=>k!==p && k.startsWith(prefix) && !k.slice(prefix.length).includes('/')).map(([k,v])=>k.slice(prefix.length)+(v===null?'/':'')); },
|
||||
async readFile(value) { const data = entries.get(path(value)); if(!data) throw Error('Profile file not found'); return data.slice(); },
|
||||
async writeFile(value,data) { const p = path(value); requireParent(p); if(entries.get(p)===null || !(data instanceof Uint8Array)) throw Error('Invalid profile file'); const next = bytes-(entries.get(p)?.length||0)+data.length; if(next>limit || (!entries.has(p)&&entries.size>=2048)) throw Error('Profile limit reached'); entries.set(p,data.slice()); bytes=next; },
|
||||
async mkdir(value) { const p = path(value); if(entries.get(p)===null)return; requireParent(p); if(entries.has(p)||entries.size>=2048)throw Error('Profile limit reached'); entries.set(p,null); },
|
||||
async unlink(value) { const p=path(value); if(!p)throw Error('Invalid profile path'); for(const [k,v] of entries)if(k===p||k.startsWith(p+'/')){bytes-=v?.length||0;entries.delete(k);} },
|
||||
async rename(from,to) { const a=path(from),b=path(to); if(!a||!b||!entries.has(a)||b.startsWith(a+'/'))throw Error('Invalid profile rename'); if(a===b)return; requireParent(b); const moved=[...entries].filter(([k])=>k===a||k.startsWith(a+'/')); await this.unlink(b); for(const [k]of moved)entries.delete(k); for(const [k,v]of moved)entries.set(b+k.slice(a.length),v); }
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user