From 6eb143cda881ba4dd26ab84bd85673f0fe94c1b8 Mon Sep 17 00:00:00 2001 From: Elad Rosenheim Date: Tue, 23 Apr 2024 19:48:09 +0300 Subject: Support disabling uploads + fonts fix (#11) * Inline Netlify logo, preload fonts * Support disabling blobs upload + fonts fix --- src/pages/api/blobs.ts | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) (limited to 'src/pages/api') diff --git a/src/pages/api/blobs.ts b/src/pages/api/blobs.ts index d11aa58..6c2901b 100644 --- a/src/pages/api/blobs.ts +++ b/src/pages/api/blobs.ts @@ -1,9 +1,12 @@ import type { APIRoute } from 'astro'; import { getStore } from '@netlify/blobs'; +import { uploadDisabled } from '../../utils'; export const prerender = false; export const POST: APIRoute = async ({ request }) => { + if (uploadDisabled) throw new Error('Sorry, uploads are disabled'); + const parameters = await request.json(); const blobStore = getStore('shapes'); const key = parameters.name; @@ -16,12 +19,22 @@ export const POST: APIRoute = async ({ request }) => { }; export const GET: APIRoute = async ({ request }) => { - const blobStore = getStore({ name: 'shapes', consistency: 'strong' }); - const data = await blobStore.list(); - const keys = data.blobs.map(({ key }) => key); - return new Response( - JSON.stringify({ - keys - }) - ); + try { + const blobStore = getStore({ name: 'shapes', consistency: 'strong' }); + const data = await blobStore.list(); + const keys = data.blobs.map(({ key }) => key); + return new Response( + JSON.stringify({ + keys + }) + ); + } catch (e) { + console.error(e); + return new Response( + JSON.stringify({ + keys: [], + error: 'Failed listing blobs' + }) + ); + } }; -- cgit v1.2.3