#12 first commit

This commit is contained in:
2026-05-16 20:11:51 +02:00
parent fbd47636d1
commit 552c239677
16 changed files with 962 additions and 12 deletions

View File

@@ -45,6 +45,7 @@ const resolvePath = (defaultRel) => {
config.paths = {
a: resolvePath('public/a'),
b: resolvePath('public/b'),
c: resolvePath('public/c'),
t: resolvePath('public/t'),
ca: resolvePath('public/ca'),
s: path.join(base, 'public/s'),

View File

@@ -309,7 +309,11 @@
"comments": {
"write_comment": "Kommentar schreiben...",
"post": "Abschnalzen",
"cancel": "Abbrechen"
"cancel": "Abbrechen",
"attach_file": "Datei anhängen",
"uploading_file": "Wird hochgeladen...",
"remove_file": "Datei entfernen",
"file_too_large": "Datei zu groß"
},
"upload_btn": {
"select_file": "Datei auswählen",

View File

@@ -309,7 +309,11 @@
"comments": {
"write_comment": "Write a comment...",
"post": "Post",
"cancel": "Cancel"
"cancel": "Cancel",
"attach_file": "Attach file",
"uploading_file": "Uploading...",
"remove_file": "Remove file",
"file_too_large": "File too large"
},
"upload_btn": {
"select_file": "Select a file",

View File

@@ -309,7 +309,11 @@
"comments": {
"write_comment": "Schrijf een opmerking...",
"post": "Plaatsen",
"cancel": "Annuleren"
"cancel": "Annuleren",
"attach_file": "Bestand bijvoegen",
"uploading_file": "Uploaden...",
"remove_file": "Bestand verwijderen",
"file_too_large": "Bestand te groot"
},
"upload_btn": {
"select_file": "Selecteer een bestand",

View File

@@ -308,7 +308,11 @@
"comments": {
"write_comment": "Schreiben Sie doch einen Kommentar...",
"post": "Pfostieren",
"cancel": "Abbrechen"
"cancel": "Abbrechen",
"attach_file": "Datei anflanschen",
"uploading_file": "Wird aufladiert...",
"remove_file": "Datei entfernen",
"file_too_large": "Datei zu voluminös"
},
"upload_btn": {
"select_file": "Datei auswählen",

View File

@@ -861,6 +861,31 @@ export default {
CASE WHEN ${sort !== 'new'} THEN c.created_at END ASC,
CASE WHEN ${sort === 'new'} THEN c.created_at END DESC
`;
// Fetch comment file attachments
if (comments.length > 0) {
const commentIds = comments.map(c => c.id);
try {
const files = await db`
SELECT id, comment_id, dest, mime, size, original_filename
FROM comment_files
WHERE comment_id = ANY(${commentIds}::int[])
ORDER BY id ASC
`;
const filesMap = new Map();
for (const f of files) {
if (!filesMap.has(f.comment_id)) filesMap.set(f.comment_id, []);
filesMap.get(f.comment_id).push(f);
}
for (const c of comments) {
c.files = filesMap.get(c.id) || [];
}
} catch (e) {
// Table might not exist yet, gracefully degrade
for (const c of comments) c.files = [];
}
}
console.log(`[${new Date().toISOString()}] [GETCOMMENTS] Fetched ${comments.length} comments for item ${itemId} in ${Date.now() - tStart}ms`);
// Process mentions (now includes embeds)
@@ -886,6 +911,20 @@ export default {
LIMIT 1
`;
if (!comment.length) return null;
// Fetch comment file attachments
try {
const files = await db`
SELECT id, comment_id, dest, mime, size, original_filename
FROM comment_files
WHERE comment_id = ${id}
ORDER BY id ASC
`;
comment[0].files = files;
} catch (e) {
comment[0].files = [];
}
return process ? (await processMentions(comment))[0] : comment[0];
} catch (e) {
console.error('[F0CKLIB] Error fetching comment:', e);

View File

@@ -290,6 +290,26 @@ export default (router, tpl) => {
const commentId = parseInt(newComment[0].id, 10);
// Link uploaded files to this comment (if any)
const fileIdsRaw = body.file_ids || '';
if (fileIdsRaw) {
const fileIds = fileIdsRaw.split(',').map(id => parseInt(id, 10)).filter(id => !isNaN(id) && id > 0);
if (fileIds.length > 0) {
try {
// Only link files that belong to this user and aren't already linked
await db`
UPDATE comment_files
SET comment_id = ${commentId}
WHERE id = ANY(${fileIds}::int[])
AND user_id = ${req.session.id}
AND comment_id IS NULL
`;
} catch (err) {
console.error('[COMMENTS] Failed to link files to comment:', err);
}
}
}
// Notify Subscribers (excluding the author)
// 1. Get subscribers (active only)
const subscribers = await db`SELECT user_id FROM comment_subscriptions WHERE item_id = ${item_id} AND is_subscribed = true`;

View File

@@ -8,6 +8,11 @@ export default (router, tpl) => {
route: /^\/b\//
});
router.static({
dir: cfg.paths.c,
route: /^\/c\//
});
router.static({
dir: cfg.paths.emojis,
route: /^\/s\/emojis\//