summaryrefslogtreecommitdiff
path: root/src/pages/api/blobs.ts
diff options
context:
space:
mode:
authorElad Rosenheim <eladroz@users.noreply.github.com>2024-04-23 19:48:09 +0300
committerGitHub <noreply@github.com>2024-04-23 19:48:09 +0300
commit6eb143cda881ba4dd26ab84bd85673f0fe94c1b8 (patch)
treed946a3b4b567f0ee2590c9b45d3e2673db89626f /src/pages/api/blobs.ts
parente028782c14356a5efaaa72b01cf34c30a4357df6 (diff)
Support disabling uploads + fonts fix (#11)
* Inline Netlify logo, preload fonts * Support disabling blobs upload + fonts fix
Diffstat (limited to 'src/pages/api/blobs.ts')
-rw-r--r--src/pages/api/blobs.ts29
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'
+ })
+ );
+ }
};