refactor: Update type annotations for database queries and improve button state handling in download page
This commit is contained in:
@@ -28,7 +28,7 @@ export async function POST(request: Request) {
|
|||||||
|
|
||||||
const connection = await pool.getConnection();
|
const connection = await pool.getConnection();
|
||||||
try {
|
try {
|
||||||
const [result]: any = await connection.query(
|
const [result]: [{ affectedRows: number }, unknown] = await connection.query(
|
||||||
'UPDATE files SET token_hash = ?, expires_at = ? WHERE id = ?',
|
'UPDATE files SET token_hash = ?, expires_at = ? WHERE id = ?',
|
||||||
[tokenHash, expiresAt, file_id]
|
[tokenHash, expiresAt, file_id]
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,6 +1,14 @@
|
|||||||
import { NextResponse } from 'next/server';
|
import { NextResponse } from 'next/server';
|
||||||
import pool from '@/lib/db';
|
import pool from '@/lib/db';
|
||||||
|
|
||||||
|
interface FileId {
|
||||||
|
id: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface FilePart {
|
||||||
|
discord_message_id: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
if (!process.env.DISCORD_BOT_TOKEN || !process.env.DISCORD_CHANNEL_ID || !process.env.CRON_SECRET) {
|
if (!process.env.DISCORD_BOT_TOKEN || !process.env.DISCORD_CHANNEL_ID || !process.env.CRON_SECRET) {
|
||||||
throw new Error('Discord or Cron secret environment variables are not configured');
|
throw new Error('Discord or Cron secret environment variables are not configured');
|
||||||
}
|
}
|
||||||
@@ -21,7 +29,7 @@ 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]: any[] = await connection.query(
|
const [incompleteFiles]: [FileId[], 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]
|
||||||
);
|
);
|
||||||
@@ -30,7 +38,7 @@ export async function POST(request: Request) {
|
|||||||
for (const file of incompleteFiles) {
|
for (const file of incompleteFiles) {
|
||||||
const file_id = file.id;
|
const file_id = file.id;
|
||||||
|
|
||||||
const [parts]: any[] = await connection.query('SELECT discord_message_id FROM file_parts WHERE file_id = ?', [file_id]);
|
const [parts]: [FilePart[], unknown] = await connection.query('SELECT discord_message_id FROM file_parts WHERE file_id = ?', [file_id]);
|
||||||
|
|
||||||
if (parts.length > 0) {
|
if (parts.length > 0) {
|
||||||
for (const part of parts) {
|
for (const part of parts) {
|
||||||
@@ -58,7 +66,7 @@ export async function POST(request: Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// --- 2. Cleanup for EXPIRED files ---
|
// --- 2. Cleanup for EXPIRED files ---
|
||||||
const [expiredFiles]: any[] = await connection.query(
|
const [expiredFiles]: [FileId[], 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'
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -66,7 +74,7 @@ export async function POST(request: Request) {
|
|||||||
for (const file of expiredFiles) {
|
for (const file of expiredFiles) {
|
||||||
const file_id = file.id;
|
const file_id = file.id;
|
||||||
|
|
||||||
const [partsRows]: any[] = await connection.query(
|
const [partsRows]: [FilePart[], 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]
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -243,10 +243,10 @@ export default function DownloadPage() {
|
|||||||
{deleteState === 'idle' && (
|
{deleteState === 'idle' && (
|
||||||
<button
|
<button
|
||||||
onClick={handleDelete}
|
onClick={handleDelete}
|
||||||
disabled={downloadState === 'downloading' || downloadState === 'decrypting' || deleteState === 'deleting'}
|
disabled={downloadState === 'downloading' || downloadState === 'decrypting'}
|
||||||
className="w-full bg-red-600 hover:bg-red-700 text-white font-bold py-3 px-4 rounded-lg transition duration-300 disabled:bg-gray-600 disabled:cursor-not-allowed"
|
className="w-full bg-red-600 hover:bg-red-700 text-white font-bold py-3 px-4 rounded-lg transition duration-300 disabled:bg-gray-600 disabled:cursor-not-allowed"
|
||||||
>
|
>
|
||||||
{deleteState === 'deleting' ? 'Deleting...' : 'Delete File'}
|
{'Delete File'}
|
||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
{deleteState === 'deleting' && (
|
{deleteState === 'deleting' && (
|
||||||
|
|||||||
Reference in New Issue
Block a user