Added post deletion
This commit is contained in:
parent
abceb346e3
commit
6c205a0ad3
7 changed files with 110 additions and 21 deletions
0
src/lib/components/Image.svelte
Normal file
0
src/lib/components/Image.svelte
Normal file
|
@ -3,7 +3,7 @@
|
|||
import PostButton from '$lib/components/PostButton.svelte';
|
||||
import PostBody from '$lib/components/PostBody.svelte';
|
||||
|
||||
export let success, username, content, upvotes, downvotes, id;
|
||||
export let success, username, content, upvotes, downvotes, id, isAuthor;
|
||||
|
||||
let query = (id) ? `/post/${id}` : '';
|
||||
|
||||
|
@ -24,6 +24,20 @@
|
|||
downvotes = j.data.down;
|
||||
})
|
||||
}
|
||||
|
||||
function deletePost(v) {
|
||||
fData = (new FormData());
|
||||
|
||||
fData.append('id',id);
|
||||
|
||||
fetch('/api/postDelete', {
|
||||
method: 'POST',
|
||||
body: fData
|
||||
}).then(async x => {
|
||||
window.location.href = '/';
|
||||
})
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<style>
|
||||
|
@ -66,17 +80,25 @@
|
|||
<span slot="footer">
|
||||
<PostButton
|
||||
clickFunc={() => vote('up')}
|
||||
data={upvotes * 1}
|
||||
data={upvotes * 1 + ' Yes'}
|
||||
icon='/upvote.svg'
|
||||
/>
|
||||
<PostButton
|
||||
clickFunc={() => vote('down')}
|
||||
data={downvotes * 1}
|
||||
data={downvotes * 1 + ' No'}
|
||||
icon='/downvote.svg'
|
||||
/>
|
||||
{#if isAuthor}
|
||||
<PostButton
|
||||
clickFunc={() => deletePost()}
|
||||
data={'Delete'}
|
||||
icon='/delete.svg'
|
||||
/>
|
||||
{/if}
|
||||
{#if id}
|
||||
<PostButton
|
||||
href='/post/{id}'
|
||||
data={'View'}
|
||||
icon='/view.svg'
|
||||
/>
|
||||
{/if}
|
||||
|
|
|
@ -3,7 +3,8 @@ const rowCount = 5;
|
|||
const AUTH_ACTIONS = [
|
||||
'postCreate',
|
||||
'fileCreate',
|
||||
'vote'
|
||||
'vote',
|
||||
'postDelete'
|
||||
];
|
||||
|
||||
const fileSizeLimit = 1024*1024*16;
|
||||
|
@ -100,6 +101,8 @@ backend.register = async ({user, pass, pass2}) => {
|
|||
passHash
|
||||
])
|
||||
|
||||
await updateUser({user: user[0].username});
|
||||
|
||||
return { success: 'Successfully created account.', location: '/'};
|
||||
}
|
||||
|
||||
|
@ -155,7 +158,18 @@ backend.postCreate = async ({content, user}) => {
|
|||
return {'success': 'Your post has been broadcasted!', 'href': `/post/${id}` };
|
||||
}
|
||||
|
||||
backend.postGet = async ({id}) => {
|
||||
backend.postDelete = async ({id, user}) => {
|
||||
|
||||
await db.run('DELETE FROM post WHERE username = ? AND id = ?', [
|
||||
user,
|
||||
id
|
||||
])
|
||||
|
||||
return {'success': 'Your post has been deleted!', 'href': `/post/${id}` };
|
||||
}
|
||||
|
||||
|
||||
backend.postGet = async ({id, cookies }) => {
|
||||
var posts = await db.all('SELECT * from post WHERE id = ?', [
|
||||
id
|
||||
])
|
||||
|
@ -164,7 +178,9 @@ backend.postGet = async ({id}) => {
|
|||
return {'success': 'Post does not exist.'}
|
||||
}
|
||||
|
||||
return {data: posts[0]};
|
||||
var user = (await backend.token({cookies})).data;
|
||||
|
||||
return {data: posts[0], isAuthor: posts[0].username == user};
|
||||
}
|
||||
|
||||
backend.userGet = async ({user}) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue