fix: proxy default header fix

Signed-off-by: Varun Raj <mailme@varunraj.in>
This commit is contained in:
Varun Raj committed 2024-09-04 19:56:31 +05:30
1 parent 1465486de4
commit 2d2781bbdc
2 files changed
+9 -4

No files matched your search

+1 -1
View File
@@ -9,7 +9,7 @@ export const getUserHeaders = (user: IUser, otherHeaders?: {
'x-api-key'?: string; 'x-api-key'?: string;
'Authorization'?: string 'Authorization'?: string
} = { } = {
'Content-Type': 'application/octet-stream', 'Content-Type': 'application/json',
} }
if (user.isUsingAPIKey) { if (user.isUsingAPIKey) {
headers['x-api-key'] = ENV.IMMICH_API_KEY headers['x-api-key'] = ENV.IMMICH_API_KEY
@@ -1,6 +1,8 @@
// pages/api/proxy.js // pages/api/proxy.js
import { ENV } from '@/config/environment'; import { ENV } from '@/config/environment';
import { getCurrentUser } from '@/handlers/serverUtils/user.utils';
import { getUserHeaders } from '@/helpers/user.helper';
import { NextApiRequest, NextApiResponse } from 'next' import { NextApiRequest, NextApiResponse } from 'next'
export const config = { export const config = {
@@ -17,14 +19,17 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
const { id } = req.query; const { id } = req.query;
const targetUrl = `${ENV.IMMICH_URL}/api/assets/${id}/original`; const targetUrl = `${ENV.IMMICH_URL}/api/assets/${id}/original`;
const user = await getCurrentUser(req);
if (!user) {
return res.status(403).json({ message: 'Unauthorized' })
}
try { try {
// Forward the request to the target API // Forward the request to the target API
const response = await fetch(targetUrl, { const response = await fetch(targetUrl, {
method: 'GET', method: 'GET',
headers: { headers: getUserHeaders(user, {
'Content-Type': 'application/octet-stream', 'Content-Type': 'application/octet-stream',
'x-api-key': ENV.IMMICH_API_KEY, }),
},
}) })
if (!response.ok) { if (!response.ok) {