refactor: Update type annotations for database query results in cleanup route

This commit is contained in:
2025-10-16 11:17:30 +02:00
parent 97b10716b3
commit f533d86896

View File

@@ -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 {