Skip to content

Commit

Permalink
Merge pull request #126 from serafuku/yunochi/develop
Browse files Browse the repository at this point in the history
🐛 Proxy content-type 처리 수정
  • Loading branch information
yunochi authored Dec 21, 2024
2 parents 6852f9f + 68a1363 commit 7877d86
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/app/api/web/proxy/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,15 @@ class RemoteImageProxy {
return sendApiError(400, `Proxy Fail! Remote server Sent ${remote_res.status}`);
}
const content_length = remote_res.headers['content-length'];
const content_type = remote_res.headers['content-type'];
let content_type = remote_res.headers['content-type'];
if (isNumberString(content_length)) {
if (parseInt(content_length) > REMOTE_MEDIA_SIZE_LIMIT) {
abortController.abort();
return sendApiError(413, `Remote Content Too Large`);
}
}
if (!content_type || !content_type.startsWith('image/')) {
abortController.abort();
return sendApiError(400, 'Content is not image');
if (typeof content_type !== 'string' || !content_type.startsWith('image/')) {
content_type = 'application/octet-stream';
}
const remote_filename = new RE2(/filename="([^";]+)"/).exec(
remote_res.headers['content-disposition'] ?? '',
Expand All @@ -92,7 +91,7 @@ class RemoteImageProxy {

const resHeader = {
...(content_length ? { 'content-length': content_length } : {}),
'Content-Type': content_type ?? 'application/octet-stream',
'Content-Type': content_type,
'Content-Disposition': content_disposition,
'Cache-Control': 'public, max-age=31536000',
...(last_modified ? { 'last-modified': last_modified } : {}),
Expand Down

0 comments on commit 7877d86

Please sign in to comment.