You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
svelte/sites/svelte.dev/src/routes/(authed)/repl/create.json/+server.js

19 lines
455 B

import * as gist from '$lib/db/gist';
import * as session from '$lib/db/session';
import { error, json } from '@sveltejs/kit';
export async function POST({ request }) {
const user = await session.from_cookie(request.headers.get('cookie'));
if (!user) error(401);
const body = await request.json();
const result = await gist.create(user, body);
// normalize id
result.id = result.id.replace(/-/g, '');
return json(result, {
status: 201
});
}