feat: update file handling to redirect to Telegram CDN and adjust Swagger documentation

This commit is contained in:
MythEclipse
2026-05-29 03:43:49 +07:00
parent 5425f6d33d
commit 8508b36026
5 changed files with 23 additions and 53 deletions
+4 -11
View File
@@ -109,19 +109,12 @@ export const handleFileRedirect = async (req: RequestWithParams): Promise<Respon
}
const fileInfo = await getTelegramFileInfo(file.telegramFileId, public_id);
const tgResponse = await fetch(buildTelegramFileUrl(fileInfo.file_path));
const redirectUrl = buildTelegramFileUrl(fileInfo.file_path);
if (!tgResponse.ok) {
logger.error('File download failed', { public_id, status: tgResponse.status });
return fail(502, 'Server error');
}
return new Response(tgResponse.body, {
status: 200,
return new Response(null, {
status: 302,
headers: {
'Content-Type': file.mimeType || 'application/octet-stream',
'Content-Disposition': `attachment; filename="${sanitizeFilenameHeader(file.fileName)}"`,
'Content-Length': String(file.sizeBytes),
Location: redirectUrl,
},
});
} catch (error: unknown) {
+3 -3
View File
@@ -157,11 +157,11 @@ export const handleSwaggerJson = async (): Promise<Response> => {
'/f/{public_id}': {
get: {
summary: 'Download File',
description: 'Proxies file from Telegram storage as a streamed download. Rate-limited by IP.',
description: 'Redirects to Telegram CDN for direct download. Rate-limited by IP.',
parameters: [publicIdParameter],
responses: {
'200': {
description: 'File binary stream.',
'302': {
description: 'Redirect to Telegram CDN URL.',
},
'404': {
description: 'File not found.',