mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-06 02:48:43 +00:00
refactor: implement renderPaste to call per syntax rendering functions
This commit is contained in:
@@ -113,33 +113,39 @@
|
|||||||
return html.replace(code, numbered);
|
return html.replace(code, numbered);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function renderCode(content: string | null = null) {
|
async function renderPaste(content: string | null = null) {
|
||||||
if (!data?.paste) return;
|
if (!data?.paste) return;
|
||||||
let code = content ?? decryptedContent ?? data.content ?? '';
|
|
||||||
|
|
||||||
const encoder = new TextEncoder();
|
let contentToRender = content ?? decryptedContent ?? data.content ?? '';
|
||||||
const buffer = encoder.encode(code).buffer;
|
|
||||||
isBinary = isBinaryData(buffer);
|
isBinary = isBinaryData(new TextEncoder().encode(contentToRender).buffer);
|
||||||
if (isBinary) {
|
if (isBinary) {
|
||||||
contentRendered = true;
|
contentRendered = true;
|
||||||
decryptStatus = '';
|
decryptStatus = '';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch (data.paste.syntax) {
|
||||||
|
case 'markdown':
|
||||||
|
pasteContent = await parseMarkdown(contentToRender);
|
||||||
|
contentRendered = true;
|
||||||
|
decryptStatus = '';
|
||||||
|
break;
|
||||||
|
case 'csv':
|
||||||
|
await renderCsv(contentToRender);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
await renderCode(contentToRender);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function renderCode(content: string | null = null) {
|
||||||
|
if (!data?.paste) return;
|
||||||
|
let code = content ?? decryptedContent ?? data.content ?? '';
|
||||||
|
|
||||||
const lang = (data.paste.syntax ?? '').toLowerCase();
|
const lang = (data.paste.syntax ?? '').toLowerCase();
|
||||||
|
|
||||||
if (lang === 'markdown') {
|
|
||||||
pasteContent = await parseMarkdown(code);
|
|
||||||
contentRendered = true;
|
|
||||||
decryptStatus = '';
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lang === 'csv') {
|
|
||||||
await renderCsv(code);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let highlighted = '';
|
let highlighted = '';
|
||||||
try {
|
try {
|
||||||
if (lang === 'plaintext') {
|
if (lang === 'plaintext') {
|
||||||
@@ -260,7 +266,7 @@
|
|||||||
}
|
}
|
||||||
data.content = rawContent;
|
data.content = rawContent;
|
||||||
decryptedContent = rawContent;
|
decryptedContent = rawContent;
|
||||||
await renderCode(rawContent);
|
await renderPaste(rawContent);
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
(metadata?.syntax !== data.paste.syntax ||
|
(metadata?.syntax !== data.paste.syntax ||
|
||||||
@@ -415,14 +421,14 @@
|
|||||||
decryptError = 'Incorrect password. Please try again.';
|
decryptError = 'Incorrect password. Please try again.';
|
||||||
decryptStatus = 'Decryption failed.';
|
decryptStatus = 'Decryption failed.';
|
||||||
} else {
|
} else {
|
||||||
await renderCode();
|
await renderPaste();
|
||||||
history.replaceState(null, '', window.location.pathname + window.location.search);
|
history.replaceState(null, '', window.location.pathname + window.location.search);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
decryptStatus = 'Decryption canceled.';
|
decryptStatus = 'Decryption canceled.';
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
await renderCode();
|
await renderPaste();
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -435,22 +441,22 @@
|
|||||||
decryptError = 'Incorrect password. Please try again.';
|
decryptError = 'Incorrect password. Please try again.';
|
||||||
decryptStatus = 'Decryption failed.';
|
decryptStatus = 'Decryption failed.';
|
||||||
} else {
|
} else {
|
||||||
await renderCode();
|
await renderPaste();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
decryptStatus = 'Decryption canceled.';
|
decryptStatus = 'Decryption canceled.';
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
decryptStatus = 'Rendering content...';
|
decryptStatus = 'Rendering content...';
|
||||||
await renderCode();
|
await renderPaste();
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
decryptStatus = 'Rendering content...';
|
decryptStatus = 'Rendering content...';
|
||||||
await renderCode();
|
await renderPaste();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$: if (data?.paste && (data.paste.visibility !== 2 || decryptedContent !== null)) renderCode();
|
$: if (data?.paste && (data.paste.visibility !== 2 || decryptedContent !== null)) renderPaste();
|
||||||
$: reportSiteKey =
|
$: reportSiteKey =
|
||||||
(data as unknown as { authOptions?: { cf_turnstile_site_key?: string | null } }).authOptions
|
(data as unknown as { authOptions?: { cf_turnstile_site_key?: string | null } }).authOptions
|
||||||
?.cf_turnstile_site_key ?? null;
|
?.cf_turnstile_site_key ?? null;
|
||||||
|
|||||||
Reference in New Issue
Block a user