Rewrite
This commit is contained in:
parent
ce7957e0bf
commit
d8670ecf81
18 changed files with 191 additions and 193 deletions
|
@ -1,17 +1,9 @@
|
|||
import { tokenBackend, postCreateBackend } from '../../lib/db.js';
|
||||
import { backend } from '../../lib/db.js';
|
||||
import { checkLength, checkRegex } from '../../lib/util.js';
|
||||
|
||||
/** @type {import('./$types').Actions} */
|
||||
export const actions = {
|
||||
create: async ({ request, cookies }) => {
|
||||
|
||||
var user = await tokenBackend({
|
||||
token: cookies.get('token')
|
||||
});
|
||||
|
||||
if (!user)
|
||||
return {'success': 'Not logged in.'}
|
||||
|
||||
const data = await request.formData();
|
||||
const content = data.get('content') + '';
|
||||
|
||||
|
@ -20,7 +12,7 @@ export const actions = {
|
|||
if (lengthCheck)
|
||||
return lengthCheck;
|
||||
|
||||
await postCreateBackend({user, content});
|
||||
await backend.postCreate({user, content});
|
||||
|
||||
return {'success': 'Successfully posted.'};
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
<script>
|
||||
import Area from '$lib/Area.svelte';
|
||||
|
||||
/** @type {import('./$types').PageData} */
|
||||
export let data;
|
||||
import { handleSubmit } from '$lib/util.js';
|
||||
|
||||
/** @type {import('./$types').ActionData} */
|
||||
export let form;
|
||||
</script>
|
||||
|
@ -18,7 +18,7 @@
|
|||
<p slot="header">
|
||||
Create Post
|
||||
</p>
|
||||
<form slot="main" method='POST'>
|
||||
<form slot="main" action='/api/postCreate' method='POST' on:submit|preventDefault={async e => form = JSON.parse(await handleSubmit(e)) }>
|
||||
<p>
|
||||
<textarea name='content'></textarea>
|
||||
</p>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue