initial import: random background api
This commit is contained in:
22
functions/api/list.js
Normal file
22
functions/api/list.js
Normal file
@@ -0,0 +1,22 @@
|
||||
import { getVariantPayload, loadManifest } from '../lib/background.js';
|
||||
|
||||
export async function onRequestGet(context) {
|
||||
const { request } = context;
|
||||
const manifest = await loadManifest(request);
|
||||
|
||||
return Response.json(
|
||||
{
|
||||
generated_at: manifest?.generated_at || null,
|
||||
variants: {
|
||||
mobile: summarizeVariant(manifest, 'mobile'),
|
||||
desktop: summarizeVariant(manifest, 'desktop'),
|
||||
},
|
||||
},
|
||||
{ headers: { 'Cache-Control': 'no-store, max-age=0', 'Access-Control-Allow-Origin': '*' } },
|
||||
);
|
||||
}
|
||||
|
||||
function summarizeVariant(manifest, variant) {
|
||||
const { folder, images } = getVariantPayload(manifest, variant);
|
||||
return { folder, count: images.length, images };
|
||||
}
|
||||
Reference in New Issue
Block a user