Supra_App/src/routes/api/catalog-banner-image/+server.ts

25 lines
811 B
TypeScript
Raw Normal View History

import { error } from '@sveltejs/kit';
import type { RequestHandler } from './$types';
import { env } from '$env/dynamic/public';
const GET_IMAGE = env.PUBLIC_GET_IMAGE;
// Server-side fetch of a banner image so the browser can read its bytes
// (to push to the machine via ADB) without hitting CORS on the image server.
export const GET: RequestHandler = async ({ url }) => {
const path = url.searchParams.get('path');
if (!path) throw error(400, 'Missing path');
const target = `${GET_IMAGE}/${path}`;
const res = await fetch(target);
if (!res.ok) throw error(res.status, 'Banner fetch failed');
const buf = await res.arrayBuffer();
return new Response(buf, {
headers: {
'content-type': res.headers.get('content-type') || 'application/octet-stream',
'cache-control': 'no-store'
}
});
};