Update Peer.paste

This commit is contained in:
Raven Scott
2026-05-27 23:18:05 -04:00
parent bf911b5cdc
commit 83b7f210a3
2 changed files with 28 additions and 34 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "Peer Paste", "name": "Peer Paste",
"version": "1.2.0", "version": "1.3.0",
"domain": "peer.paste", "domain": "peer.paste",
"enabled": true, "enabled": true,
"description": "Temporary P2P text snippets with expiration and burn-after-read options", "description": "Temporary P2P text snippets with expiration and burn-after-read options",
+27 -33
View File
@@ -135,44 +135,38 @@ function normalizePasteInput(body = {}, existing = null) {
}; };
} }
const VENDOR_ASSETS = { const MARKED_UMD = pathMod.join(PROJECT_ROOT, 'node_modules', 'marked', 'lib', 'marked.umd.js');
'marked.min.js': { const HIGHLIGHT_ES_ROOT = pathMod.join(PROJECT_ROOT, 'node_modules', 'highlight.js', 'es');
path: pathMod.join(PROJECT_ROOT, 'node_modules', 'marked', 'lib', 'marked.umd.js'), const HIGHLIGHT_STYLES_ROOT = pathMod.join(PROJECT_ROOT, 'node_modules', 'highlight.js', 'styles');
type: 'application/javascript; charset=utf-8'
}, function contentTypeForAsset(filePath) {
'highlight-dark.css': { if (filePath.endsWith('.js') || filePath.endsWith('.mjs')) return 'application/javascript; charset=utf-8';
path: pathMod.join(PROJECT_ROOT, 'node_modules', 'highlight.js', 'styles', 'github-dark.min.css'), if (filePath.endsWith('.css')) return 'text/css; charset=utf-8';
type: 'text/css; charset=utf-8' return 'application/octet-stream';
}, }
'highlight/es/core.js': {
path: pathMod.join(PROJECT_ROOT, 'node_modules', 'highlight.js', 'es', 'core.js'), function resolveVendorAssetPath(key) {
type: 'application/javascript; charset=utf-8' if (key === 'marked.min.js') return MARKED_UMD;
}, if (key === 'highlight-dark.css') return pathMod.join(HIGHLIGHT_STYLES_ROOT, 'github-dark.min.css');
'highlight/es/languages/javascript.js': {
path: pathMod.join(PROJECT_ROOT, 'node_modules', 'highlight.js', 'es', 'languages', 'javascript.js'), if (key.startsWith('highlight/es/')) {
type: 'application/javascript; charset=utf-8' const subPath = key.slice('highlight/es/'.length);
}, const normalized = pathMod.normalize(subPath).replace(/^(\.\.(\/|\\|$))+/, '');
'highlight/es/languages/json.js': { const resolved = pathMod.resolve(HIGHLIGHT_ES_ROOT, normalized);
path: pathMod.join(PROJECT_ROOT, 'node_modules', 'highlight.js', 'es', 'languages', 'json.js'), if (!resolved.startsWith(HIGHLIGHT_ES_ROOT)) return null;
type: 'application/javascript; charset=utf-8' return resolved;
},
'highlight/es/languages/bash.js': {
path: pathMod.join(PROJECT_ROOT, 'node_modules', 'highlight.js', 'es', 'languages', 'bash.js'),
type: 'application/javascript; charset=utf-8'
},
'highlight/es/languages/markdown.js': {
path: pathMod.join(PROJECT_ROOT, 'node_modules', 'highlight.js', 'es', 'languages', 'markdown.js'),
type: 'application/javascript; charset=utf-8'
} }
};
return null;
}
async function serveVendorAsset(res, key) { async function serveVendorAsset(res, key) {
const asset = VENDOR_ASSETS[key]; const assetPath = resolveVendorAssetPath(key);
if (!asset) return false; if (!assetPath) return false;
try { try {
const content = await fs.readFile(asset.path); const content = await fs.readFile(assetPath);
res.writeHead(200, { res.writeHead(200, {
'Content-Type': asset.type, 'Content-Type': contentTypeForAsset(assetPath),
'Cache-Control': 'public, max-age=86400' 'Cache-Control': 'public, max-age=86400'
}); });
res.end(content); res.end(content);