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",
"version": "1.2.0",
"version": "1.3.0",
"domain": "peer.paste",
"enabled": true,
"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 = {
'marked.min.js': {
path: pathMod.join(PROJECT_ROOT, 'node_modules', 'marked', 'lib', 'marked.umd.js'),
type: 'application/javascript; charset=utf-8'
},
'highlight-dark.css': {
path: pathMod.join(PROJECT_ROOT, 'node_modules', 'highlight.js', 'styles', 'github-dark.min.css'),
type: 'text/css; charset=utf-8'
},
'highlight/es/core.js': {
path: pathMod.join(PROJECT_ROOT, 'node_modules', 'highlight.js', 'es', 'core.js'),
type: 'application/javascript; charset=utf-8'
},
'highlight/es/languages/javascript.js': {
path: pathMod.join(PROJECT_ROOT, 'node_modules', 'highlight.js', 'es', 'languages', 'javascript.js'),
type: 'application/javascript; charset=utf-8'
},
'highlight/es/languages/json.js': {
path: pathMod.join(PROJECT_ROOT, 'node_modules', 'highlight.js', 'es', 'languages', 'json.js'),
type: 'application/javascript; charset=utf-8'
},
'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'
const MARKED_UMD = pathMod.join(PROJECT_ROOT, 'node_modules', 'marked', 'lib', 'marked.umd.js');
const HIGHLIGHT_ES_ROOT = pathMod.join(PROJECT_ROOT, 'node_modules', 'highlight.js', 'es');
const HIGHLIGHT_STYLES_ROOT = pathMod.join(PROJECT_ROOT, 'node_modules', 'highlight.js', 'styles');
function contentTypeForAsset(filePath) {
if (filePath.endsWith('.js') || filePath.endsWith('.mjs')) return 'application/javascript; charset=utf-8';
if (filePath.endsWith('.css')) return 'text/css; charset=utf-8';
return 'application/octet-stream';
}
function resolveVendorAssetPath(key) {
if (key === 'marked.min.js') return MARKED_UMD;
if (key === 'highlight-dark.css') return pathMod.join(HIGHLIGHT_STYLES_ROOT, 'github-dark.min.css');
if (key.startsWith('highlight/es/')) {
const subPath = key.slice('highlight/es/'.length);
const normalized = pathMod.normalize(subPath).replace(/^(\.\.(\/|\\|$))+/, '');
const resolved = pathMod.resolve(HIGHLIGHT_ES_ROOT, normalized);
if (!resolved.startsWith(HIGHLIGHT_ES_ROOT)) return null;
return resolved;
}
return null;
}
};
async function serveVendorAsset(res, key) {
const asset = VENDOR_ASSETS[key];
if (!asset) return false;
const assetPath = resolveVendorAssetPath(key);
if (!assetPath) return false;
try {
const content = await fs.readFile(asset.path);
const content = await fs.readFile(assetPath);
res.writeHead(200, {
'Content-Type': asset.type,
'Content-Type': contentTypeForAsset(assetPath),
'Cache-Control': 'public, max-age=86400'
});
res.end(content);