-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
277abe3
commit 1b605cd
Showing
2 changed files
with
49 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { getStore } from "@netlify/blobs" | ||
|
||
export default async (request, context) => { | ||
const store = getStore('ifieldnotes') | ||
const id = context.id | ||
|
||
if (request.method === 'POST') { | ||
try { | ||
const body = await request.text() | ||
await store.set(id, body) | ||
return new Response('HTML fragment stored', { status: 200 }) | ||
} catch (error) { | ||
console.error(error) | ||
return new Response(JSON.stringify({ error: 'Failed to store HTML fragment' }), { status: 500 }) | ||
} | ||
} else if (request.method === 'GET') { | ||
try { | ||
const fragment = await store.get(id) | ||
if (fragment) { | ||
return new Response(fragment, { status: 200, headers: { 'Content-Type': 'text/html' } }) | ||
} else { | ||
return new Response(JSON.stringify({ error: 'Fragment not found' }), { status: 404 }) | ||
} | ||
} catch (error) { | ||
console.error(error) | ||
return new Response(JSON.stringify({ error: 'Failed to retrieve HTML fragment' }), { status: 500 }) | ||
} | ||
} else { | ||
return new Response(JSON.stringify({ error: 'Method Not Allowed' }), { status: 405 }) | ||
} | ||
} | ||
|
||
|
||
|
||
// import { getStore } from "@netlify/blobs" | ||
|
||
// export default async (request, context) => { | ||
// try { | ||
// const construction = getStore('fieldnotes') | ||
// await construction.set(request.fieldnotesId, request.article) | ||
|
||
// return new Response('Article stored') | ||
// } catch (error) { | ||
// console.log(error) | ||
// return Response.json({ error: 'Failed converting article to blob' }, { status: 500 }) | ||
// } | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters