From f533d8689622ae025893d8d85f2e25c30294c315 Mon Sep 17 00:00:00 2001 From: b3ni15 Date: Thu, 16 Oct 2025 11:17:30 +0200 Subject: [PATCH] refactor: Update type annotations for database query results in cleanup route --- src/app/api/cron/cleanup/route.ts | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/app/api/cron/cleanup/route.ts b/src/app/api/cron/cleanup/route.ts index a77f03b..6921367 100644 --- a/src/app/api/cron/cleanup/route.ts +++ b/src/app/api/cron/cleanup/route.ts @@ -1,5 +1,6 @@ import { NextResponse } from 'next/server'; import pool from '@/lib/db'; +import { RowDataPacket } from 'mysql2/promise'; interface FileId { id: string; @@ -29,19 +30,19 @@ export async function POST(request: Request) { const staleTime = new Date(); staleTime.setHours(staleTime.getHours() - 24); // Older than 24 hours - const [incompleteFiles]: [FileId[], unknown] = await connection.query( + const [incompleteFiles]: [RowDataPacket[], unknown] = await connection.query( 'SELECT id FROM files WHERE token_hash IS NULL AND upload_at <= ?', [staleTime] ); - if (incompleteFiles.length > 0) { - for (const file of incompleteFiles) { + if (incompleteFiles[0].length > 0) { + for (const file of incompleteFiles[0] as FileId[]) { const file_id = file.id; - const [parts]: [FilePart[], unknown] = await connection.query('SELECT discord_message_id FROM file_parts WHERE file_id = ?', [file_id]); + const [parts]: [RowDataPacket[], unknown] = await connection.query('SELECT discord_message_id FROM file_parts WHERE file_id = ?', [file_id]); - if (parts.length > 0) { - for (const part of parts) { + if (parts[0].length > 0) { + for (const part of parts[0] as FilePart[]) { if (!part.discord_message_id) continue; const deleteUrl = `https://discord.com/api/v10/channels/${process.env.DISCORD_CHANNEL_ID}/messages/${part.discord_message_id}`; try { @@ -66,21 +67,21 @@ export async function POST(request: Request) { } // --- 2. Cleanup for EXPIRED files --- - const [expiredFiles]: [FileId[], unknown] = await connection.query( + const [expiredFiles]: [RowDataPacket[], unknown] = await connection.query( 'SELECT id FROM files WHERE expires_at <= NOW() AND deleted = 0' ); - if (expiredFiles.length > 0) { - for (const file of expiredFiles) { + if (expiredFiles[0].length > 0) { + for (const file of expiredFiles[0] as FileId[]) { const file_id = file.id; - const [partsRows]: [FilePart[], unknown] = await connection.query( + const [partsRows]: [RowDataPacket[], unknown] = await connection.query( 'SELECT discord_message_id FROM file_parts WHERE file_id = ?', [file_id] ); - if (partsRows.length > 0) { - for (const part of partsRows) { + if (partsRows[0].length > 0) { + for (const part of partsRows[0] as FilePart[]) { if (!part.discord_message_id) continue; const deleteUrl = `https://discord.com/api/v10/channels/${process.env.DISCORD_CHANNEL_ID}/messages/${part.discord_message_id}`; try {