fix: proxy default header fix

Signed-off-by: Varun Raj <mailme@varunraj.in>
This commit is contained in:
Varun Raj
2024-09-04 19:56:31 +05:30
parent 1465486de4
commit 2d2781bbdc
2 changed files with 9 additions and 4 deletions
+1 -1
View File
@@ -9,7 +9,7 @@ export const getUserHeaders = (user: IUser, otherHeaders?: {
'x-api-key'?: string;
'Authorization'?: string
} = {
'Content-Type': 'application/octet-stream',
'Content-Type': 'application/json',
}
if (user.isUsingAPIKey) {
headers['x-api-key'] = ENV.IMMICH_API_KEY
@@ -1,6 +1,8 @@
// pages/api/proxy.js
import { ENV } from '@/config/environment';
import { getCurrentUser } from '@/handlers/serverUtils/user.utils';
import { getUserHeaders } from '@/helpers/user.helper';
import { NextApiRequest, NextApiResponse } from 'next'
export const config = {
@@ -17,14 +19,17 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
const { id } = req.query;
const targetUrl = `${ENV.IMMICH_URL}/api/assets/${id}/original`;
const user = await getCurrentUser(req);
if (!user) {
return res.status(403).json({ message: 'Unauthorized' })
}
try {
// Forward the request to the target API
const response = await fetch(targetUrl, {
method: 'GET',
headers: {
headers: getUserHeaders(user, {
'Content-Type': 'application/octet-stream',
'x-api-key': ENV.IMMICH_API_KEY,
},
}),
})
if (!response.ok) {