refactor: Update type annotations and error handling for improved type safety in route and download components
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 7s
Vercel Production Deployment / Deploy-Production (push) Failing after 24s

This commit is contained in:
2025-10-16 11:28:11 +02:00
parent fde0dd7216
commit a310fe9564
4 changed files with 17 additions and 12 deletions

View File

@@ -1,7 +1,7 @@
import { NextResponse } from 'next/server';
import pool from '@/lib/db';
import bcrypt from 'bcrypt';
import { RowDataPacket, ResultSetHeader } from 'mysql2/promise';
import { RowDataPacket } from 'mysql2/promise';
interface FileData extends RowDataPacket {
token_hash: string;

View File

@@ -7,19 +7,19 @@ interface FilePart extends RowDataPacket {
}
interface RouteContext {
params: {
params: Promise<{
file_id: string;
part_index: string;
};
}>;
}
if (!process.env.DISCORD_BOT_TOKEN || !process.env.DISCORD_CHANNEL_ID) {
throw new Error('Discord bot token or channel ID is not configured');
}
export async function GET(request: NextRequest, context: { params: Record<string, string | string[]> }) {
export async function GET(request: NextRequest, context: RouteContext) {
try {
const { file_id, part_index } = params;
const { file_id, part_index } = await context.params;
// NOTE: In a real-world scenario, you MUST validate if the user has permission to download this part.
// This would involve checking the download_token against the hash in the `files` table.

View File

@@ -16,9 +16,15 @@ interface FilePartMetadata extends RowDataPacket {
size: number;
}
export async function GET(request: NextRequest, { params }: { params: { file_id: string; } }) {
interface RouteContext {
params: Promise<{
file_id: string;
}>;
}
export async function GET(request: NextRequest, context: RouteContext) {
try {
const file_id = params.file_id;
const { file_id } = await context.params;
const { searchParams } = new URL(request.url);
const token = searchParams.get('token');

View File

@@ -153,9 +153,8 @@ export default function DownloadPage() {
setDownloadState('complete');
} catch (e: any) {
setError(e.message || 'An unknown error occurred.');
setDownloadState('error');
} catch (e: unknown) {
setError(e instanceof Error ? e.message : 'An unknown error occurred.'); setDownloadState('error');
}
};
@@ -186,9 +185,9 @@ export default function DownloadPage() {
setDeleteState('deleted');
} catch (e: any) {
} catch (e: unknown) {
setDeleteState('error');
setDeleteError(e.message || 'An unknown error occurred during deletion.');
setDeleteError(e instanceof Error ? e.message : 'An unknown error occurred during deletion.');
}
};