From 9d952483f250a97cbeab4061fa1c4e68341b330f Mon Sep 17 00:00:00 2001 From: kartofen Date: Sun, 28 Aug 2022 23:22:15 +0300 Subject: posting thread and image works --- src/pages/create/thread.ts | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-) (limited to 'src/pages/create/thread.ts') diff --git a/src/pages/create/thread.ts b/src/pages/create/thread.ts index 0af3471..0a0b7d1 100644 --- a/src/pages/create/thread.ts +++ b/src/pages/create/thread.ts @@ -1,28 +1,16 @@ -import type { APIRoute } from 'astro'; -import { v4 as uuidV4 } from 'uuid'; +import { api } from '../../lib/api'; +import { processThreadOut } from '../../lib/thread'; -import type Thread from '../../models/Thread' -import { api } from '../../lib/api' +export async function post({ request }) { + const form = await request.formData(); -export async function post({ params, request }): APIRoute { - const form = await request.formData(); + console.log(form); - let t: Thread = {}; - t.id = uuidV4().toString(); - t.ThreadName = form.get('ThreadName').toString(); - // data["ThreadCreator"] = locals.userid; - t.ThreadCreator = ''; - t.ThreadText = form.get('ThreadText').toString(); - t.Comments = []; - t.CreationDate = Date.now(); - // data["ImageId"] = await post_img(base64image, writeFileSync); - // data["FileType"] = get_img_type(base64image); - t.ImageId = form.get('image').toString(); - t.FileType = ''; + let t: Thread = await processThreadOut(form); - // await api('post', `thread/${form.get('board')}`, JSON.stringify(data)); + await api('post', `thread/${form.get('board')}`, JSON.stringify(t)); - return new Response(null, { - status: 200 - }); + return new Response(t.id, { + status: 200 + }); } -- cgit v1.2.3