hgd
This commit is contained in:
@@ -13,6 +13,18 @@ const getGlobalfilter = () => {
|
|||||||
return filteredTags.length ? filteredTags.map(n => `tag_id = ${n}`).join(" or ") : null;
|
return filteredTags.length ? filteredTags.map(n => `tag_id = ${n}`).join(" or ") : null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const resolveNumericItemId = async (itemIdOrSlug) => {
|
||||||
|
if (!itemIdOrSlug) return null;
|
||||||
|
if (typeof itemIdOrSlug === 'number') return itemIdOrSlug;
|
||||||
|
if (/^\d+$/.test(String(itemIdOrSlug))) return parseInt(itemIdOrSlug, 10);
|
||||||
|
try {
|
||||||
|
const rows = await db`SELECT id FROM items WHERE slug = ${String(itemIdOrSlug)} LIMIT 1`;
|
||||||
|
return rows[0]?.id || null;
|
||||||
|
} catch (e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// All MIME types that map to the 'swf' extension in config (e.g. application/x-shockwave-flash, application/vnd.adobe.flash.movie)
|
// All MIME types that map to the 'swf' extension in config (e.g. application/x-shockwave-flash, application/vnd.adobe.flash.movie)
|
||||||
const flashMimes = Object.entries(cfg.mimes || {}).filter(([, ext]) => ext === 'swf').map(([mime]) => mime);
|
const flashMimes = Object.entries(cfg.mimes || {}).filter(([, ext]) => ext === 'swf').map(([mime]) => mime);
|
||||||
|
|
||||||
@@ -1217,7 +1229,8 @@ export default {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
getComments: async (itemId, sort = 'new', process = true) => {
|
getComments: async (itemId, sort = 'new', process = true) => {
|
||||||
if (!itemId) return [];
|
const numericId = await resolveNumericItemId(itemId);
|
||||||
|
if (!numericId) return [];
|
||||||
const tStart = Date.now();
|
const tStart = Date.now();
|
||||||
try {
|
try {
|
||||||
const comments = await db`
|
const comments = await db`
|
||||||
@@ -1230,7 +1243,7 @@ export default {
|
|||||||
FROM comments c
|
FROM comments c
|
||||||
JOIN "user" u ON c.user_id = u.id
|
JOIN "user" u ON c.user_id = u.id
|
||||||
LEFT JOIN user_options uo ON uo.user_id = u.id
|
LEFT JOIN user_options uo ON uo.user_id = u.id
|
||||||
WHERE c.item_id = ${itemId} AND c.is_deleted = false
|
WHERE c.item_id = ${numericId} AND c.is_deleted = false
|
||||||
ORDER BY COALESCE(c.is_pinned, false) DESC,
|
ORDER BY COALESCE(c.is_pinned, false) DESC,
|
||||||
CASE WHEN ${sort !== 'new'} THEN c.created_at END ASC,
|
CASE WHEN ${sort !== 'new'} THEN c.created_at END ASC,
|
||||||
CASE WHEN ${sort === 'new'} THEN c.created_at END DESC
|
CASE WHEN ${sort === 'new'} THEN c.created_at END DESC
|
||||||
@@ -1373,11 +1386,12 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
getSubscriptionStatus: async (userId, itemId) => {
|
getSubscriptionStatus: async (userId, itemId) => {
|
||||||
if (!userId || !itemId) return false;
|
const numericId = await resolveNumericItemId(itemId);
|
||||||
|
if (!userId || !numericId) return false;
|
||||||
const tStart = Date.now();
|
const tStart = Date.now();
|
||||||
try {
|
try {
|
||||||
const sub = await db`SELECT 1 FROM comment_subscriptions WHERE user_id = ${userId} AND item_id = ${itemId} AND is_subscribed = true`;
|
const sub = await db`SELECT 1 FROM comment_subscriptions WHERE user_id = ${userId} AND item_id = ${numericId} AND is_subscribed = true`;
|
||||||
console.log(`[${new Date().toISOString()}] [GETSUB] Checked sub for item ${itemId} in ${Date.now() - tStart}ms`);
|
console.log(`[${new Date().toISOString()}] [GETSUB] Checked sub for item ${numericId} in ${Date.now() - tStart}ms`);
|
||||||
return sub.length > 0;
|
return sub.length > 0;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return false;
|
return false;
|
||||||
@@ -1385,9 +1399,10 @@ export default {
|
|||||||
},
|
},
|
||||||
processMentions,
|
processMentions,
|
||||||
markNotificationsRead: async (userId, itemId) => {
|
markNotificationsRead: async (userId, itemId) => {
|
||||||
if (!userId || !itemId) return;
|
const numericId = await resolveNumericItemId(itemId);
|
||||||
|
if (!userId || !numericId) return;
|
||||||
try {
|
try {
|
||||||
await db`UPDATE notifications SET is_read = true WHERE user_id = ${userId} AND item_id = ${itemId} AND is_read = false`;
|
await db`UPDATE notifications SET is_read = true WHERE user_id = ${userId} AND item_id = ${numericId} AND is_read = false`;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('[F0CKLIB] Error marking notifications as read:', e);
|
console.error('[F0CKLIB] Error marking notifications as read:', e);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user