Added editing posts
This commit is contained in:
parent
e323c22ba9
commit
eec1873e28
7 changed files with 119 additions and 28 deletions
|
@ -97,7 +97,7 @@
|
||||||
Failed to get post.
|
Failed to get post.
|
||||||
</p>
|
</p>
|
||||||
</Area>
|
</Area>
|
||||||
{:else}
|
{:else if content}
|
||||||
<Area>
|
<Area>
|
||||||
<span slot="header" id='header'>
|
<span slot="header" id='header'>
|
||||||
<img class='pfp' src='/img/pfp/{username}.png'/>
|
<img class='pfp' src='/img/pfp/{username}.png'/>
|
||||||
|
@ -130,6 +130,11 @@
|
||||||
data={''}
|
data={''}
|
||||||
icon='/delete.svg'
|
icon='/delete.svg'
|
||||||
/>
|
/>
|
||||||
|
<PostButton
|
||||||
|
href='/new_post?edit={id}'
|
||||||
|
data={''}
|
||||||
|
icon='/edit.svg'
|
||||||
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
{#if id}
|
{#if id}
|
||||||
<PostButton
|
<PostButton
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
<style>
|
<style>
|
||||||
img, video {
|
img, video {
|
||||||
max-width: 100px;
|
max-width: 200px;
|
||||||
max-height: 200px;
|
max-height: 200px;
|
||||||
margin: 5px;
|
margin: 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.only-img {
|
.only-img {
|
||||||
max-width: 200px;
|
max-width: 300px;
|
||||||
max-height: 450px;
|
max-height: 300px;
|
||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
import Button from '$lib/components/Button.svelte';
|
import Button from '$lib/components/Button.svelte';
|
||||||
import {setLocation} from '$lib/util.js';
|
import {setLocation} from '$lib/util.js';
|
||||||
|
|
||||||
export let data, noRatings;
|
export let data, noRatings = false;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
|
|
|
@ -63,6 +63,11 @@ async function initDb() {
|
||||||
time INTEGER \
|
time INTEGER \
|
||||||
)');
|
)');
|
||||||
|
|
||||||
|
await db.run('CREATE TABLE IF NOT EXISTS tag ( \
|
||||||
|
id CHAR(64), \
|
||||||
|
reply CHAR(64) \
|
||||||
|
)');
|
||||||
|
|
||||||
await db.run('CREATE TABLE IF NOT EXISTS chat ( \
|
await db.run('CREATE TABLE IF NOT EXISTS chat ( \
|
||||||
username CHAR(64), \
|
username CHAR(64), \
|
||||||
content CHAR(10240), \
|
content CHAR(10240), \
|
||||||
|
|
|
@ -170,7 +170,7 @@ backend.login = async ({user, pass, cookies},{db}) => {
|
||||||
return { success: 'Successfully logged into account.', data: token, location: '/'};
|
return { success: 'Successfully logged into account.', data: token, location: '/'};
|
||||||
}
|
}
|
||||||
|
|
||||||
backend.postCreate = async ({content}, {user,db}) => {
|
backend.postCreate = async ({content, edit}, {user,db}) => {
|
||||||
if (!content) return {'success': 'No post provided.'}
|
if (!content) return {'success': 'No post provided.'}
|
||||||
|
|
||||||
var lengthCheck = checkLength(content,'Post content',1,10240);
|
var lengthCheck = checkLength(content,'Post content',1,10240);
|
||||||
|
@ -178,41 +178,70 @@ backend.postCreate = async ({content}, {user,db}) => {
|
||||||
if (lengthCheck)
|
if (lengthCheck)
|
||||||
return lengthCheck;
|
return lengthCheck;
|
||||||
|
|
||||||
|
let userData = (await db.all('SELECT * FROM post WHERE id = ?', [
|
||||||
|
edit || ''
|
||||||
|
]));
|
||||||
|
|
||||||
var id = randomBytes(10).toString('hex');
|
var id = randomBytes(10).toString('hex');
|
||||||
|
|
||||||
|
if (edit && userData[0] && userData[0].user === user)
|
||||||
|
id = edit;
|
||||||
|
|
||||||
var postFlatten = formatPost(content).flat();
|
var postFlatten = formatPost(content).flat();
|
||||||
var reply = postFlatten[postFlatten.findIndex(x => x.subtype == 'post')];
|
var reply = postFlatten.filter(x => x.subtype == 'post').map(x => x.url.split('/').pop());
|
||||||
|
var firstReply = reply[0];
|
||||||
|
|
||||||
if (reply)
|
await db.run('DELETE from tag WHERE id = ?', [
|
||||||
reply = reply.url.split('/').pop();
|
id
|
||||||
|
])
|
||||||
|
|
||||||
if (reply) {
|
if (firstReply) {
|
||||||
let replyData = (await db.all('SELECT * FROM post WHERE id = ?', [
|
let replyData = (await db.all('SELECT * FROM post WHERE id = ?', [
|
||||||
reply
|
firstReply
|
||||||
]));
|
]));
|
||||||
|
|
||||||
let replyUser = '';
|
let replyUser = '';
|
||||||
if (replyData && replyData[0])
|
if (replyData && replyData[0])
|
||||||
replyUser = replyData[0].username;
|
replyUser = replyData[0].username;
|
||||||
|
|
||||||
|
if (replyUser && !edit) {
|
||||||
await db.run('INSERT INTO messages (username, content, time,read) VALUES (?, ?, ?, ?)', [
|
await db.run('INSERT INTO messages (username, content, time,read) VALUES (?, ?, ?, ?)', [
|
||||||
replyUser,
|
replyUser,
|
||||||
`@${user} replied to #${reply} on #${id}`,
|
`@${user} replied to #${irstReply} on #${id}`,
|
||||||
Math.floor(new Date() * 1000),
|
Math.floor(new Date() * 1000),
|
||||||
0
|
0
|
||||||
]);
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (id === edit) {
|
||||||
|
await db.run('UPDATE post SET content = ? WHERE id = ?', [
|
||||||
|
content,
|
||||||
|
id
|
||||||
|
])
|
||||||
|
|
||||||
|
} else {
|
||||||
await db.run('INSERT INTO post (username, id, content, rating, reply, time) VALUES (?, ?, ?, ?, ?, ?)', [
|
await db.run('INSERT INTO post (username, id, content, rating, reply, time) VALUES (?, ?, ?, ?, ?, ?)', [
|
||||||
user,
|
user,
|
||||||
id,
|
id,
|
||||||
content,
|
content,
|
||||||
calcVote(0,0),
|
calcVote(0,0),
|
||||||
reply || '',
|
firstReply || '',
|
||||||
Math.floor(new Date() * 1000)
|
Math.floor(new Date() * 1000)
|
||||||
])
|
])
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
for (var i = 0; i < reply.length; i++) {
|
||||||
|
await db.run('INSERT INTO tag (id, reply) VALUES (?, ?)', [
|
||||||
|
id,
|
||||||
|
reply[i]
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return {'success': 'Your post has been broadcasted!', 'href': `/post/${id}` };
|
return {'success': 'Your post has been broadcasted!', 'href': `/post/${id}` };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -298,7 +327,7 @@ backend.postBulk = async ({page, id, user, cookies, sort, type}, {admin, db}) =>
|
||||||
|
|
||||||
if (posts.length == 0) posts.push({});
|
if (posts.length == 0) posts.push({});
|
||||||
|
|
||||||
posts.push(...(await db.all('SELECT * from post WHERE reply = ? ORDER BY '+sort+' DESC LIMIT ?, ?', [
|
posts.push(...(await db.all('SELECT * from post WHERE id IN (SELECT id FROM tag WHERE reply = ?) ORDER BY '+sort+' DESC LIMIT ?, ?', [
|
||||||
id,
|
id,
|
||||||
...pageParams
|
...pageParams
|
||||||
])))
|
])))
|
||||||
|
@ -309,7 +338,7 @@ backend.postBulk = async ({page, id, user, cookies, sort, type}, {admin, db}) =>
|
||||||
...pageParams
|
...pageParams
|
||||||
])
|
])
|
||||||
} else if (type == 'follow') {
|
} else if (type == 'follow') {
|
||||||
posts = await db.all('SELECT * from post WHERE username IN (SELECT following from follow WHERE username = ?) ORDER BY '+sort+' DESC LIMIT ?, ?', [
|
posts = await db.all('SELECT * from post WHERE username IN (SELECT following FROM follow WHERE username = ?) ORDER BY '+sort+' DESC LIMIT ?, ?', [
|
||||||
userAuth,
|
userAuth,
|
||||||
...pageParams
|
...pageParams
|
||||||
])
|
])
|
||||||
|
|
|
@ -18,6 +18,8 @@
|
||||||
|
|
||||||
let currentState = 'editor';
|
let currentState = 'editor';
|
||||||
|
|
||||||
|
let edit = $page.url.searchParams.get('edit') || '';
|
||||||
|
|
||||||
function setState(editor) {
|
function setState(editor) {
|
||||||
currentState = editor;
|
currentState = editor;
|
||||||
}
|
}
|
||||||
|
@ -50,6 +52,7 @@
|
||||||
method='POST'
|
method='POST'
|
||||||
on:submit|preventDefault={async e => form = JSON.parse(await handleSubmit(e)) }
|
on:submit|preventDefault={async e => form = JSON.parse(await handleSubmit(e)) }
|
||||||
>
|
>
|
||||||
|
<textarea name='edit' style='display: none;' value={edit}></textarea>
|
||||||
<textarea name='content' style='display: none;' value={formContent}></textarea>
|
<textarea name='content' style='display: none;' value={formContent}></textarea>
|
||||||
<input formaction="?/create" type='submit' value='Post' bind:this={formBody} style='display: none;'>
|
<input formaction="?/create" type='submit' value='Post' bind:this={formBody} style='display: none;'>
|
||||||
{#if currentState == 'editor'}
|
{#if currentState == 'editor'}
|
||||||
|
@ -88,7 +91,7 @@
|
||||||
<b>@user</b> mentions a user
|
<b>@user</b> mentions a user
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<b>#post</b> replies to a post by ID
|
<b>#post</b> tags a post as a reply or subtopic
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<b>%post</b> links to a chatroom
|
<b>%post</b> links to a chatroom
|
||||||
|
|
49
static/edit.svg
Normal file
49
static/edit.svg
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||||
|
|
||||||
|
<svg
|
||||||
|
width="19.863544mm"
|
||||||
|
height="30.12483mm"
|
||||||
|
viewBox="0 0 19.863544 30.124831"
|
||||||
|
version="1.1"
|
||||||
|
id="svg14062"
|
||||||
|
inkscape:version="1.2.2 (b0a8486541, 2022-12-01)"
|
||||||
|
sodipodi:docname="edit.svg"
|
||||||
|
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||||
|
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
xmlns:svg="http://www.w3.org/2000/svg">
|
||||||
|
<sodipodi:namedview
|
||||||
|
id="namedview14064"
|
||||||
|
pagecolor="#000000"
|
||||||
|
bordercolor="#666666"
|
||||||
|
borderopacity="1.0"
|
||||||
|
inkscape:showpageshadow="2"
|
||||||
|
inkscape:pageopacity="0"
|
||||||
|
inkscape:pagecheckerboard="0"
|
||||||
|
inkscape:deskcolor="#d1d1d1"
|
||||||
|
inkscape:document-units="mm"
|
||||||
|
showgrid="false"
|
||||||
|
inkscape:zoom="5.8154882"
|
||||||
|
inkscape:cx="25.707214"
|
||||||
|
inkscape:cy="75.402096"
|
||||||
|
inkscape:window-width="1868"
|
||||||
|
inkscape:window-height="1006"
|
||||||
|
inkscape:window-x="24"
|
||||||
|
inkscape:window-y="46"
|
||||||
|
inkscape:window-maximized="1"
|
||||||
|
inkscape:current-layer="layer1" />
|
||||||
|
<defs
|
||||||
|
id="defs14059" />
|
||||||
|
<g
|
||||||
|
inkscape:label="Layer 1"
|
||||||
|
inkscape:groupmode="layer"
|
||||||
|
id="layer1"
|
||||||
|
transform="translate(-54.746539,-131.04017)">
|
||||||
|
<path
|
||||||
|
style="fill:none;fill-opacity:1;stroke:#aaaaaa;stroke-width:7.93753;stroke-linecap:round;stroke-linejoin:round;stroke-dasharray:none;stroke-opacity:1"
|
||||||
|
d="m 70.641318,135.00894 -11.9262,11.09365 11.9262,11.09365"
|
||||||
|
id="path2225"
|
||||||
|
sodipodi:nodetypes="ccc" />
|
||||||
|
</g>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 1.6 KiB |
Loading…
Reference in a new issue