Added file uploads

This commit is contained in:
Xodrium 2023-02-07 19:36:32 -05:00
parent 911d17637f
commit b2ce13eea1
10 changed files with 169 additions and 40 deletions

View file

@ -1,19 +0,0 @@
import { backend } from '../../lib/db/db.js';
import { checkLength, checkRegex } from '../../lib/util.js';
/** @type {import('./$types').Actions} */
export const actions = {
create: async ({ request, cookies }) => {
const data = await request.formData();
const content = data.get('content') + '';
var lengthCheck = checkLength(content,'Post content',1,10240);
if (lengthCheck)
return lengthCheck;
await backend.postCreate({user, content});
return {'success': 'Successfully posted.'};
}
};

View file

@ -26,10 +26,20 @@
<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>
<span slot="footer">
<p>
{#if form?.success}
{#if form?.href}
<a href='{form?.href}'>{form?.success}</a>
{:else}
{form?.success}
{/if}
{/if}
</p>
<p>Create a post for the world to see.</p>
<h2>Post syntax</h2>
<p>
<b>img||filename.blah</b> embeds a user-uploaded file in this site
</p>
</span>
</Area>