feat(config): support *_MB env vars for upload size limits
- Add `applyMegabytesOrBytesEnv` to accept size settings in either bytes or MB - Prefer `*_BYTES` when set, otherwise convert `*_MB` to bytes with overflow guard - Add coverage for MB-based environment overrides - Introduce `static/js/upload-popups.js` to lazy-load and cache popup templatesfeat(config): support *_MB env vars for upload size limits - Add `applyMegabytesOrBytesEnv` to accept size settings in either bytes or MB - Prefer `*_BYTES` when set, otherwise convert `*_MB` to bytes with overflow guard - Add coverage for MB-based environment overrides - Introduce `static/js/upload-popups.js` to lazy-load and cache popup templates
This commit is contained in:
36
static/js/upload-popups.js
Normal file
36
static/js/upload-popups.js
Normal file
@@ -0,0 +1,36 @@
|
||||
window.WBPopups = (() => {
|
||||
const cache = new Map();
|
||||
const docs = {
|
||||
cli: { title: "CLI Guide", template: "cli" },
|
||||
faq: { title: "Help & FAQ", template: "faq" },
|
||||
dailyQuota: { title: "Upload limits", template: "upload-limits" },
|
||||
about: { title: "About WarpBox", template: "about", about: true },
|
||||
examples: { title: "Examples", template: "examples" },
|
||||
};
|
||||
|
||||
async function loadTemplate(name) {
|
||||
if (cache.has(name)) return cache.get(name);
|
||||
const response = await fetch(`/static/popups/${name}.html`, { credentials: "same-origin" });
|
||||
if (!response.ok) throw new Error(`Could not load popup template: ${name}`);
|
||||
const template = await response.text();
|
||||
cache.set(name, template);
|
||||
return template;
|
||||
}
|
||||
|
||||
async function renderTemplate(name, data = {}) {
|
||||
const template = await loadTemplate(name);
|
||||
return window.WBUtils.renderTemplate(template, data);
|
||||
}
|
||||
|
||||
async function renderDoc(name, data = {}) {
|
||||
const doc = docs[name];
|
||||
if (!doc) return null;
|
||||
return {
|
||||
title: doc.title,
|
||||
about: Boolean(doc.about),
|
||||
html: await renderTemplate(doc.template, data),
|
||||
};
|
||||
}
|
||||
|
||||
return { renderTemplate, renderDoc };
|
||||
})();
|
||||
Reference in New Issue
Block a user