mirror of
https://github.com/yusufipk/OpenFrame.git
synced 2026-09-11 09:36:08 +00:00
fix: address security vulnerabilities and add image attachments
- Fix type confusion vulnerability in comment content updates - Validate pagination offsets to prevent negative values - Validate timestamp is a valid number before parsing - Exclude guestEmail from comment API responses for privacy - Fix TypeScript error in audio upload route - Add image attachment support for comments with upload API - Update admin dashboard to track image attachments - Rename cleanup functions to handle both voice and image media
This commit is contained in:
+29
-13
@@ -34,10 +34,10 @@ export const getCachedTotalStorage = unstable_cache(
|
||||
{ revalidate: 600 }
|
||||
);
|
||||
|
||||
export const getCachedUserVoiceStorage = unstable_cache(
|
||||
export const getCachedUserMediaStorage = unstable_cache(
|
||||
async () => {
|
||||
// Return a plain object so it maps cleanly out of unstable_cache across requests
|
||||
const userStorage: Record<string, number> = {};
|
||||
const userStorage: Record<string, { total: number, voice: number, image: number }> = {};
|
||||
try {
|
||||
const fileSizes = new Map<string, number>();
|
||||
let isTruncated = true;
|
||||
@@ -57,25 +57,41 @@ export const getCachedUserVoiceStorage = unstable_cache(
|
||||
continuationToken = data.NextContinuationToken;
|
||||
}
|
||||
|
||||
const voiceComments = await db.comment.findMany({
|
||||
where: { voiceUrl: { not: null }, authorId: { not: null } },
|
||||
select: { authorId: true, voiceUrl: true }
|
||||
const mediaComments = await db.comment.findMany({
|
||||
where: { OR: [{ voiceUrl: { not: null } }, { imageUrl: { not: null } }], authorId: { not: null } },
|
||||
select: { authorId: true, voiceUrl: true, imageUrl: true }
|
||||
});
|
||||
|
||||
for (const comment of voiceComments) {
|
||||
if (!comment.authorId || !comment.voiceUrl) continue;
|
||||
const keyParts = comment.voiceUrl.split('/');
|
||||
const filename = keyParts[keyParts.length - 1];
|
||||
const r2Key = `voice/${filename}`;
|
||||
const size = fileSizes.get(r2Key) || 0;
|
||||
for (const comment of mediaComments) {
|
||||
if (!comment.authorId) continue;
|
||||
|
||||
userStorage[comment.authorId] = (userStorage[comment.authorId] || 0) + size;
|
||||
if (!userStorage[comment.authorId]) {
|
||||
userStorage[comment.authorId] = { total: 0, voice: 0, image: 0 };
|
||||
}
|
||||
|
||||
if (comment.voiceUrl) {
|
||||
const keyParts = comment.voiceUrl.split('/');
|
||||
const filename = keyParts[keyParts.length - 1];
|
||||
const r2Key = `voice/${filename}`;
|
||||
const size = fileSizes.get(r2Key) || 0;
|
||||
userStorage[comment.authorId].voice += size;
|
||||
userStorage[comment.authorId].total += size;
|
||||
}
|
||||
|
||||
if (comment.imageUrl) {
|
||||
const keyParts = comment.imageUrl.split('/');
|
||||
const filename = keyParts[keyParts.length - 1];
|
||||
const r2Key = `images/${filename}`;
|
||||
const size = fileSizes.get(r2Key) || 0;
|
||||
userStorage[comment.authorId].image += size;
|
||||
userStorage[comment.authorId].total += size;
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Failed to parse user storage:', err);
|
||||
}
|
||||
return userStorage;
|
||||
},
|
||||
['admin-user-voice-storage'],
|
||||
['admin-user-media-storage'],
|
||||
{ revalidate: 600 }
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user