1
0
Fork 0
mirror of https://github.com/seanmorley15/AdventureLog.git synced 2025-07-25 07:49:37 +02:00
AdventureLog/frontend/src/routes/immich/[key]/+server.ts

54 lines
1.5 KiB
TypeScript

import type { RequestHandler } from './$types';
const PUBLIC_SERVER_URL = process.env['PUBLIC_SERVER_URL'];
const endpoint = PUBLIC_SERVER_URL || 'http://localhost:8000';
export const GET: RequestHandler = async (event) => {
try {
const key = event.params.key;
// Forward the session ID from cookies
const sessionid = event.cookies.get('sessionid');
if (!sessionid) {
return new Response(JSON.stringify({ error: 'Session ID is missing' }), {
status: 401,
headers: { 'Content-Type': 'application/json' }
});
}
// Proxy the request to the backend
const res = await fetch(`${endpoint}/api/integrations/immich/get/${key}`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
Cookie: `sessionid=${sessionid}`
}
});
if (!res.ok) {
// Return an error response if the backend request fails
const errorData = await res.json();
return new Response(JSON.stringify(errorData), {
status: res.status,
headers: { 'Content-Type': 'application/json' }
});
}
// Get the image as a Blob
const image = await res.blob();
// Create a Response to pass the image back
return new Response(image, {
status: res.status,
headers: {
'Content-Type': res.headers.get('Content-Type') || 'image/jpeg'
}
});
} catch (error) {
console.error('Error proxying request:', error);
return new Response(JSON.stringify({ error: 'Failed to fetch image' }), {
status: 500,
headers: { 'Content-Type': 'application/json' }
});
}
};