big commit
This commit is contained in:
parent
e96f85efdc
commit
dcae12453c
26 changed files with 3183 additions and 8 deletions
27
src/routes/new_post/+page.server.js
Normal file
27
src/routes/new_post/+page.server.js
Normal file
|
@ -0,0 +1,27 @@
|
|||
import { tokenBackend, postCreateBackend } 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') + '';
|
||||
|
||||
var lengthCheck = checkLength(content,'Post content',1,10240);
|
||||
|
||||
if (lengthCheck)
|
||||
return lengthCheck;
|
||||
|
||||
await postCreateBackend({user, content});
|
||||
|
||||
return {'success': 'Successfully posted.'};
|
||||
}
|
||||
};
|
35
src/routes/new_post/+page.svelte
Normal file
35
src/routes/new_post/+page.svelte
Normal file
|
@ -0,0 +1,35 @@
|
|||
<script>
|
||||
import Area from '$lib/Area.svelte';
|
||||
|
||||
/** @type {import('./$types').PageData} */
|
||||
export let data;
|
||||
/** @type {import('./$types').ActionData} */
|
||||
export let form;
|
||||
</script>
|
||||
|
||||
<style>
|
||||
textarea {
|
||||
width: 10rem;
|
||||
height: 10rem;
|
||||
}
|
||||
</style>
|
||||
|
||||
<Area>
|
||||
<p slot="header">
|
||||
Create Post
|
||||
</p>
|
||||
<form slot="main" method='POST'>
|
||||
<p>
|
||||
<textarea name='content'></textarea>
|
||||
</p>
|
||||
<p>
|
||||
<input formaction="?/create" type='submit' value='Post'>
|
||||
</p>
|
||||
</form>
|
||||
<p slot="footer">
|
||||
{#if form?.success}
|
||||
<p>{form?.success}</p>
|
||||
{/if}
|
||||
Create a post for the world to see.
|
||||
</p>
|
||||
</Area>
|
Loading…
Add table
Add a link
Reference in a new issue