feat: update file handling to redirect to Telegram CDN and adjust Swagger documentation
This commit is contained in:
+4
-11
@@ -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) {
|
||||
|
||||
@@ -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.',
|
||||
|
||||
Reference in New Issue
Block a user