refactor: Update type annotations for database query results in cleanup route
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import { NextResponse } from 'next/server';
|
import { NextResponse } from 'next/server';
|
||||||
import pool from '@/lib/db';
|
import pool from '@/lib/db';
|
||||||
|
import { RowDataPacket } from 'mysql2/promise';
|
||||||
|
|
||||||
interface FileId {
|
interface FileId {
|
||||||
id: string;
|
id: string;
|
||||||
@@ -29,19 +30,19 @@ export async function POST(request: Request) {
|
|||||||
const staleTime = new Date();
|
const staleTime = new Date();
|
||||||
staleTime.setHours(staleTime.getHours() - 24); // Older than 24 hours
|
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 <= ?',
|
'SELECT id FROM files WHERE token_hash IS NULL AND upload_at <= ?',
|
||||||
[staleTime]
|
[staleTime]
|
||||||
);
|
);
|
||||||
|
|
||||||
if (incompleteFiles.length > 0) {
|
if (incompleteFiles[0].length > 0) {
|
||||||
for (const file of incompleteFiles) {
|
for (const file of incompleteFiles[0] as FileId[]) {
|
||||||
const file_id = file.id;
|
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) {
|
if (parts[0].length > 0) {
|
||||||
for (const part of parts) {
|
for (const part of parts[0] as FilePart[]) {
|
||||||
if (!part.discord_message_id) continue;
|
if (!part.discord_message_id) continue;
|
||||||
const deleteUrl = `https://discord.com/api/v10/channels/${process.env.DISCORD_CHANNEL_ID}/messages/${part.discord_message_id}`;
|
const deleteUrl = `https://discord.com/api/v10/channels/${process.env.DISCORD_CHANNEL_ID}/messages/${part.discord_message_id}`;
|
||||||
try {
|
try {
|
||||||
@@ -66,21 +67,21 @@ export async function POST(request: Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// --- 2. Cleanup for EXPIRED files ---
|
// --- 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'
|
'SELECT id FROM files WHERE expires_at <= NOW() AND deleted = 0'
|
||||||
);
|
);
|
||||||
|
|
||||||
if (expiredFiles.length > 0) {
|
if (expiredFiles[0].length > 0) {
|
||||||
for (const file of expiredFiles) {
|
for (const file of expiredFiles[0] as FileId[]) {
|
||||||
const file_id = file.id;
|
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 = ?',
|
'SELECT discord_message_id FROM file_parts WHERE file_id = ?',
|
||||||
[file_id]
|
[file_id]
|
||||||
);
|
);
|
||||||
|
|
||||||
if (partsRows.length > 0) {
|
if (partsRows[0].length > 0) {
|
||||||
for (const part of partsRows) {
|
for (const part of partsRows[0] as FilePart[]) {
|
||||||
if (!part.discord_message_id) continue;
|
if (!part.discord_message_id) continue;
|
||||||
const deleteUrl = `https://discord.com/api/v10/channels/${process.env.DISCORD_CHANNEL_ID}/messages/${part.discord_message_id}`;
|
const deleteUrl = `https://discord.com/api/v10/channels/${process.env.DISCORD_CHANNEL_ID}/messages/${part.discord_message_id}`;
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user