diff --git a/SharpbinV3.Client/src/lib/components/PasteCommentItem.svelte b/SharpbinV3.Client/src/lib/components/PasteCommentItem.svelte
new file mode 100644
index 0000000..1115bba
--- /dev/null
+++ b/SharpbinV3.Client/src/lib/components/PasteCommentItem.svelte
@@ -0,0 +1,236 @@
+
+
+
+
+
+ {#if node.author}
+ {#if node.author.isBanned}
+
BANNED
+ {/if}
+
+ {authorDisplay}
+
+ {/if}
+ {#if node.updatedAt}
+
edited
+ {/if}
+
+
{dateToRelativeString(new Date(node.createdAt * 1000), true, false, now, 2)}
+
+
+
+
+ {#if expanded || !isLongComment}
+
+ {@html parsedHtml}
+ {:else}
+
+
+ {@html parsedHtml}
+
+ {/if}
+
+ {#if isLongComment}
+
+ {/if}
+
+
+
+
+
+ {#if $user}
+ {#if !replyOpen}
+
+ {/if}
+
+ {/if}
+
+
+ {#if replyOpen}
+
+ {#if replyError}
+
{replyError}
+ {/if}
+ {/if}
+
+ {#if node.children.length > 0}
+
+ {#if depth >= 3 && !showDeepReplies}
+
+ {:else}
+
+ {#each node.children as child (child.id)}
+
+ {/each}
+
+ {/if}
+
+ {/if}
+
diff --git a/SharpbinV3.Client/src/lib/components/PasteComments.svelte b/SharpbinV3.Client/src/lib/components/PasteComments.svelte
new file mode 100644
index 0000000..a2a2676
--- /dev/null
+++ b/SharpbinV3.Client/src/lib/components/PasteComments.svelte
@@ -0,0 +1,246 @@
+
+
+
diff --git a/SharpbinV3.Client/src/lib/components/RichTextEditor.svelte b/SharpbinV3.Client/src/lib/components/RichTextEditor.svelte
new file mode 100644
index 0000000..c451cc3
--- /dev/null
+++ b/SharpbinV3.Client/src/lib/components/RichTextEditor.svelte
@@ -0,0 +1,217 @@
+
+
+
+ {#if mode === 'raw'}
+
+ {:else}
+
+ {#if value.trim().length === 0}
+
{placeholder}
+ {:else}
+
+
+ {@html parsedHtml}
+
+ {/if}
+
+ {/if}
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/SharpbinV3.Client/src/lib/types/comment.ts b/SharpbinV3.Client/src/lib/types/comment.ts
new file mode 100644
index 0000000..cce5fba
--- /dev/null
+++ b/SharpbinV3.Client/src/lib/types/comment.ts
@@ -0,0 +1,35 @@
+import type { Author } from './author';
+
+export type CommentReaction = 1 | 2 | null;
+
+export interface CommentAuthor extends Author {
+ displayName?: string | null;
+ roles?: number;
+ isBanned?: boolean;
+}
+
+export interface PasteComment {
+ id: number;
+ parentCommentID: number | null;
+ content: string | null;
+ storedSize: number;
+ originalSize: number;
+ isCompressed: boolean;
+ createdAt: number;
+ updatedAt: number | null;
+ likes: number;
+ dislikes: number;
+ userReaction: CommentReaction;
+ author: CommentAuthor | null;
+}
+
+export interface CommentReactionResult {
+ commentID: number;
+ likes: number;
+ dislikes: number;
+ userReaction: CommentReaction;
+}
+
+export interface CommentTreeNode extends PasteComment {
+ children: CommentTreeNode[];
+}
diff --git a/SharpbinV3.Client/src/lib/types/paste.ts b/SharpbinV3.Client/src/lib/types/paste.ts
index 67a57eb..bc5b41c 100644
--- a/SharpbinV3.Client/src/lib/types/paste.ts
+++ b/SharpbinV3.Client/src/lib/types/paste.ts
@@ -1,18 +1,23 @@
import type { Author } from './author';
+export type PasteReaction = 1 | 2 | null;
+
export interface Paste {
id: string;
uuid: string;
createdAt: number;
title: string | null;
- size: number;
- trueSize: number;
+ sizeStored: number;
+ originalSize: number;
isCompressed: boolean;
views: number;
syntax: string;
visibility: 0 | 1 | 2;
expiresAt: number;
editedAt: number | null;
+ likes: number;
+ dislikes: number;
+ userReaction: PasteReaction;
reportCount: number | null;
author: Author | null;
}
diff --git a/SharpbinV3.Client/src/lib/types/report.ts b/SharpbinV3.Client/src/lib/types/report.ts
index f027efa..243fb0b 100644
--- a/SharpbinV3.Client/src/lib/types/report.ts
+++ b/SharpbinV3.Client/src/lib/types/report.ts
@@ -28,4 +28,4 @@ export const reportTypeLabels = ['CopyrightViolation', 'IllegalContent', 'Fraud'
export const reportStatusLabels = ['Open', 'Closed'] as const;
-export const reportTargetLabels = ['Paste', 'User'] as const;
+export const reportTargetLabels = ['Paste', 'User', 'Comment'] as const;
diff --git a/SharpbinV3.Client/src/lib/utils/markdown.ts b/SharpbinV3.Client/src/lib/utils/markdown.ts
index 8324403..c11385e 100644
--- a/SharpbinV3.Client/src/lib/utils/markdown.ts
+++ b/SharpbinV3.Client/src/lib/utils/markdown.ts
@@ -2,6 +2,7 @@ import { marked } from 'marked';
import createDOMPurify from 'dompurify';
import type { WindowLike } from 'dompurify';
import { trustedDomains } from '$lib/consts';
+import { escapeHtml } from './html';
export const externalMediaWarningStorageKey = 'sharpbin:ignore-external-media-warning';
@@ -138,3 +139,195 @@ export async function parseMarkdown(
return DOMPurify.sanitize(html);
}
+
+export function parseCommentMarkdown(text: string): string {
+ const lines = text.replace(/\r\n?/g, '\n').split('\n');
+ const output: string[] = [];
+ let index = 0;
+
+ while (index < lines.length) {
+ const codeBlock = tryParseCodeBlock(lines, index);
+ if (codeBlock) {
+ output.push(codeBlock.html);
+ index = codeBlock.nextIndex;
+ continue;
+ }
+
+ const spoilerBlock = tryParseSpoilerBlock(lines, index);
+ if (spoilerBlock) {
+ output.push(spoilerBlock.html);
+ index = spoilerBlock.nextIndex;
+ continue;
+ }
+
+ const quoteBlock = tryParseQuoteBlock(lines, index);
+ if (quoteBlock) {
+ output.push(quoteBlock.html);
+ index = quoteBlock.nextIndex;
+ continue;
+ }
+
+ if (/^\s*---\s*$/.test(lines[index])) {
+ output.push('
');
+ index += 1;
+ continue;
+ }
+
+ output.push(parseInlineElements(lines[index]));
+ index += 1;
+ }
+
+ return output.join('');
+}
+
+interface ParsedCommentBlock {
+ html: string;
+ nextIndex: number;
+}
+
+function tryParseCodeBlock(lines: string[], startIndex: number): ParsedCommentBlock | null {
+ const firstLine = lines[startIndex];
+ if (!firstLine.startsWith('```')) return null;
+
+ const inlineCloseIndex = firstLine.indexOf('```', 3);
+ if (inlineCloseIndex > -1) {
+ const code = firstLine.slice(3, inlineCloseIndex);
+ const trailing = firstLine.slice(inlineCloseIndex + 3).trim();
+ const html = renderCodeBlock(code);
+ if (trailing.length === 0) {
+ return { html, nextIndex: startIndex + 1 };
+ }
+ return {
+ html: `${html}\n${parseInlineElements(trailing)}`,
+ nextIndex: startIndex + 1
+ };
+ }
+
+ const codeLines: string[] = [];
+ let index = startIndex + 1;
+
+ while (index < lines.length && !lines[index].startsWith('```')) {
+ codeLines.push(lines[index]);
+ index += 1;
+ }
+
+ if (index < lines.length) index += 1;
+
+ return {
+ html: renderCodeBlock(codeLines.join('\n')),
+ nextIndex: index
+ };
+}
+
+function tryParseSpoilerBlock(lines: string[], startIndex: number): ParsedCommentBlock | null {
+ const spoilerOpenMatch = lines[startIndex].match(/^\[Spoiler(?:="([^"]*)")?\](.*)$/i);
+ if (!spoilerOpenMatch) return null;
+
+ const title = spoilerOpenMatch[1]?.trim() || 'Spoiler';
+ const contentParts: string[] = [];
+ let remainder = spoilerOpenMatch[2] ?? '';
+ let index = startIndex;
+
+ while (true) {
+ const closeMatch = /\[\/spoiler\]/i.exec(remainder);
+ if (closeMatch && closeMatch.index !== undefined) {
+ const beforeClose = remainder.slice(0, closeMatch.index);
+ if (beforeClose.length > 0) contentParts.push(beforeClose);
+
+ const contentHtml = contentParts.map((line) => parseInlineElements(line)).join('
');
+ let html = `
${escapeHtml(title)}
${contentHtml}
`;
+
+ const afterClose = remainder.slice(closeMatch.index + closeMatch[0].length).trim();
+ if (afterClose.length > 0) {
+ html += `\n${parseInlineElements(afterClose)}`;
+ }
+
+ return {
+ html,
+ nextIndex: index + 1
+ };
+ }
+
+ if (remainder.length > 0) contentParts.push(remainder);
+ index += 1;
+ if (index >= lines.length) return null;
+ remainder = lines[index];
+ }
+}
+
+function tryParseQuoteBlock(lines: string[], startIndex: number): ParsedCommentBlock | null {
+ if (!lines[startIndex].startsWith('>')) return null;
+
+ const quoteLines: string[] = [];
+ let index = startIndex;
+
+ while (index < lines.length && lines[index].startsWith('>')) {
+ quoteLines.push(parseInlineElements(lines[index].replace(/^>\s?/, '')));
+ index += 1;
+ }
+
+ return {
+ html: `
${quoteLines.join('
')}
`,
+ nextIndex: index
+ };
+}
+
+function renderCodeBlock(code: string): string {
+ return `
${escapeHtml(code)}
`;
+}
+
+function normalizeCommentLink(rawUrl: string): string | null {
+ const url = rawUrl.trim();
+ if (url.length === 0) return null;
+ if (url.startsWith('/')) return url;
+
+ try {
+ const parsed = new URL(url);
+ if (parsed.protocol === 'http:' || parsed.protocol === 'https:') {
+ return parsed.toString();
+ }
+ return null;
+ } catch {
+ return null;
+ }
+}
+
+function parseInlineElements(text: string): string {
+ const inlinePattern =
+ /```([\s\S]*?)```|\*\*\*([^*\n]+)\*\*\*|\*\*([^*\n]+)\*\*|\*([^*\n]+)\*|`([^`\n]+)`|\[([^\]\n]+)\]\(([^)\n]+)\)|@([a-zA-Z0-9_-]+)/g;
+
+ let output = '';
+ let lastIndex = 0;
+
+ for (const match of text.matchAll(inlinePattern)) {
+ const index = match.index ?? 0;
+ output += escapeHtml(text.slice(lastIndex, index));
+
+ if (match[1] !== undefined) {
+ output += renderCodeBlock(match[1]);
+ } else if (match[2] !== undefined) {
+ output += `
${escapeHtml(match[2])}`;
+ } else if (match[3] !== undefined) {
+ output += `
${escapeHtml(match[3])}`;
+ } else if (match[4] !== undefined) {
+ output += `
${escapeHtml(match[4])}`;
+ } else if (match[5] !== undefined) {
+ output += `
${escapeHtml(match[5])}`;
+ } else if (match[6] !== undefined && match[7] !== undefined) {
+ const safeUrl = normalizeCommentLink(match[7]);
+ if (safeUrl) {
+ output += `
${escapeHtml(match[6])}`;
+ } else {
+ output += escapeHtml(match[0]);
+ }
+ } else if (match[8] !== undefined) {
+ const username = match[8];
+ output += `
@${escapeHtml(username)}`;
+ }
+
+ lastIndex = index + match[0].length;
+ }
+
+ output += escapeHtml(text.slice(lastIndex));
+ return output;
+}
diff --git a/SharpbinV3.Client/src/routes/[id].jpg/+server.ts b/SharpbinV3.Client/src/routes/[id].jpg/+server.ts
index 7076212..b35fee7 100644
--- a/SharpbinV3.Client/src/routes/[id].jpg/+server.ts
+++ b/SharpbinV3.Client/src/routes/[id].jpg/+server.ts
@@ -161,7 +161,7 @@ export const GET: RequestHandler = async ({ params, fetch }) => {
const content = rawContent || 'No content available.';
const created = paste.createdAt ? new Date(paste.createdAt) : extractDateFromUUIDv7(paste.uuid);
const metadata: PasteEmbedProps['metadata'] = [
- { icon: 'size', value: formatBytes(paste.trueSize) },
+ { icon: 'size', value: formatBytes(paste.originalSize) },
{
icon: 'views',
value: `${formatNumber(paste.views)} view${paste.views === 1 ? '' : 's'}`
diff --git a/SharpbinV3.Client/src/routes/[id]/+page.server.ts b/SharpbinV3.Client/src/routes/[id]/+page.server.ts
index 2617d34..119b60d 100644
--- a/SharpbinV3.Client/src/routes/[id]/+page.server.ts
+++ b/SharpbinV3.Client/src/routes/[id]/+page.server.ts
@@ -1,5 +1,6 @@
import type { PageServerLoad } from './$types';
import type { Paste } from '$lib/types/paste';
+import type { PasteComment } from '$lib/types/comment';
import { getServerToken } from '$lib/utils/auth';
import { apiUrl, viewInternalApiKey } from '$lib/server/api';
import { error } from '@sveltejs/kit';
@@ -46,12 +47,22 @@ export const load: PageServerLoad = async ({ params, fetch, url, cookies, parent
const pasteContent = await fetch(`${apiUrl}/api/paste/${id}/raw`, { headers: clientHeaders });
const pasteOptions = await fetch(`${apiUrl}/api/paste/info`, { headers: clientHeaders });
+ const commentsRes = await fetch(`${apiUrl}/api/paste/${id}/comments`, { headers: clientHeaders });
const options = await pasteOptions.json();
const content = await pasteContent.text();
+ let comments: PasteComment[] = [];
+
+ if (commentsRes.ok) {
+ const commentsJson = await commentsRes.json().catch(() => ({}));
+ comments = Array.isArray(commentsJson?.comments)
+ ? (commentsJson.comments as PasteComment[])
+ : [];
+ }
return {
paste,
content,
+ comments,
options,
authOptions:
parentData && typeof parentData === 'object' && parentData !== null && 'options' in parentData
diff --git a/SharpbinV3.Client/src/routes/[id]/+page.svelte b/SharpbinV3.Client/src/routes/[id]/+page.svelte
index dec4a12..8363436 100644
--- a/SharpbinV3.Client/src/routes/[id]/+page.svelte
+++ b/SharpbinV3.Client/src/routes/[id]/+page.svelte
@@ -24,7 +24,10 @@
CalendarCog,
Flag,
ArrowUp,
- HatGlasses
+ HatGlasses,
+ MessageCircle,
+ ThumbsUp,
+ ThumbsDown
} from '@lucide/svelte/icons/index';
import {
formatBytes,
@@ -47,8 +50,9 @@
import { getToken, hasRole } from '$lib/utils/auth';
import { user } from '$lib/stores/user';
import Dropdown from '$lib/components/Dropdown.svelte';
+ import PasteComments from '$lib/components/PasteComments.svelte';
import { openModal } from '$lib/stores/modal';
- import type { Paste } from '$lib/types/paste';
+ import type { Paste, PasteReaction } from '$lib/types/paste';
import HighlightWorker from '$lib/workers/highlight.worker?worker';
interface Props {
data: PageData;
@@ -56,6 +60,24 @@
let { data = $bindable() }: Props = $props();
+ function updatePasteState(patch: Partial
) {
+ if (!data?.paste) return;
+ data = {
+ ...data,
+ paste: {
+ ...data.paste,
+ ...patch
+ }
+ };
+ }
+
+ function updatePageContent(content: string) {
+ data = {
+ ...data,
+ content
+ };
+ }
+
let reportSiteKey = $derived(
(data as unknown as { authOptions?: { cf_turnstile_site_key?: string | null } }).authOptions
?.cf_turnstile_site_key ?? null
@@ -73,9 +95,11 @@
let contentRendered = $state(false);
let downloadedPaste = $state(false);
let copiedPaste = $state(false);
+ let reactingToPaste = $state(false);
let highlightWorker: Worker | null = null;
let highlightRequestId = 0;
let ignoreExternalMediaWarning = false;
+ let iconsOnly = $state(false);
let scrollY = $state(0);
@@ -293,7 +317,7 @@
editLoading = false;
return;
}
- data.content = rawContent;
+ updatePageContent(rawContent);
decryptedContent = rawContent;
await renderPaste(rawContent);
}
@@ -324,10 +348,13 @@
return;
}
const resJson = await res.json();
- data.paste.syntax = resJson.paste.syntax ?? data.paste.syntax;
- data.paste.expiresAt = resJson.paste.expiresAt ?? data.paste.expiresAt;
- data.paste.visibility = resJson.paste.visibility ?? data.paste.visibility;
- data.paste.title = resJson.paste.title ?? data.paste.title;
+ updatePasteState({
+ syntax: resJson.paste.syntax ?? data.paste.syntax,
+ expiresAt: resJson.paste.expiresAt ?? data.paste.expiresAt,
+ visibility: resJson.paste.visibility ?? data.paste.visibility,
+ title: resJson.paste.title ?? data.paste.title
+ });
+ editMetadata = data.paste ? { ...data.paste } : null;
}
} catch {
editError = 'An error occurred while updating.';
@@ -338,6 +365,48 @@
}
}
+ async function reactToPaste(target: 1 | 2) {
+ if (!data?.paste || reactingToPaste) return;
+
+ const token = getToken();
+ if (!token) {
+ return;
+ }
+
+ reactingToPaste = true;
+ const currentReaction = (data.paste.userReaction ?? null) as PasteReaction;
+ const nextReaction: PasteReaction = currentReaction === target ? null : target;
+
+ try {
+ const res = await fetch(`/api/paste/${data.paste.id}/reaction`, {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ Authorization: `Bearer ${token}`
+ },
+ body: JSON.stringify({ reaction: nextReaction })
+ });
+
+ if (!res.ok) {
+ return;
+ }
+
+ const json = await res.json();
+ const reaction = json?.reaction;
+ if (!reaction) {
+ return;
+ }
+
+ updatePasteState({
+ likes: reaction.likes ?? data.paste.likes,
+ dislikes: reaction.dislikes ?? data.paste.dislikes,
+ userReaction: reaction.userReaction ?? null
+ });
+ } finally {
+ reactingToPaste = false;
+ }
+ }
+
async function promptUser(mode: 'decrypt' | 'encrypt' | 'confirm' | 'report' = 'decrypt') {
const title = modalTitleMap[mode];
if (mode === 'confirm') {
@@ -599,7 +668,9 @@
- {formatBytes(data.paste.trueSize)}
+ {formatBytes(data.paste.originalSize)}
@@ -745,6 +816,32 @@
? 's'
: ''}
+ {#if $user && $user.uuid !== data.paste?.author?.uuid}
+
Comments ({comments.length})
+ +