fix: proxy default header fix
Signed-off-by: Varun Raj <mailme@varunraj.in>
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user