diff options
Diffstat (limited to 'src/pages/api/blobs.ts')
| -rw-r--r-- | src/pages/api/blobs.ts | 29 |
1 files changed, 21 insertions, 8 deletions
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' + }) + ); + } }; |
