Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Vman authored and Vman committed Apr 8, 2018
2 parents 8e85f39 + 4a984d4 commit 7c64635
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 27 deletions.
6 changes: 5 additions & 1 deletion routes/create/reply.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@ module.exports = {
ip = req.connection.remoteAddress,
content = req.body.content;

if(!allowedExt.includes(attachment.originalname.split('.').pop())) {
attachment = null;
}

//String formatting (Yes, I know this is janky)
content = striptags(content);
let contentLines = content.split(new RegExp('\r?\n', 'g'));
let contentFinal = "";
for(let i=0; i< contentLines.length; i++) {
lineContent = contentLines[i].replace(new RegExp('\\>', 'g'), "<span style='color: #789922;'>>");
lineContent = contentLines[i].replace(new RegExp('\\>'), "<span style='color: #789922;'>>");
if(lineContent.includes("<span style='color: #789922;'>>")) {
contentLines[i] = lineContent + "</span>";
}
Expand Down
8 changes: 6 additions & 2 deletions routes/create/thread.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@ module.exports = {
content = req.body.content,
title = req.body.title + ":";

if(!allowedExt.includes(attachment.originalname.split('.').pop())) {
attachment = null;
}

//String formatting (Yes, I know this is janky)
content = striptags(content);
let contentLines = content.split(new RegExp('\r?\n', 'g'));
let contentFinal = "";
for(let i=0; i< contentLines.length; i++) {
lineContent = contentLines[i].replace(new RegExp('\\>', 'g'), "<span style='color: #789922;'>>");
lineContent = contentLines[i].replace(new RegExp('\\>'), "<span style='color: #789922;'>>");
if(lineContent.includes("<span style='color: #789922;'>>")) {
contentLines[i] = lineContent + "</span>";
}
Expand Down Expand Up @@ -68,7 +72,7 @@ module.exports = {
return next(err);
}

if (attachment && allowedExt.includes(attachment.originalname.split('.').pop())) {
if (attachment) {
//Save file to fs
fs.rename(attachment.path, target_path, function (err) {
if (err) {
Expand Down
2 changes: 1 addition & 1 deletion routes/delete/reply.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const Reply = require(_base + 'models/reply');

module.exports = {
'/delete/reply': {
methods: ['delete'],
methods: ['post'],
fn: function(req, res, next) {
let _id = req.body._id;
Reply.findByIdAndRemove(_id, function(err, reply) {
Expand Down
2 changes: 1 addition & 1 deletion routes/update/reply.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = {
let contentLines = content.split(new RegExp('\r?\n', 'g'));
let contentFinal = "";
for(let i=0; i< contentLines.length; i++) {
lineContent = contentLines[i].replace(new RegExp('\\>', 'g'), "<span style='color: #789922;'>>");
lineContent = contentLines[i].replace(new RegExp('\\>'), "<span style='color: #789922;'>>");
if(lineContent.includes("<span style='color: #789922;'>>")) {
contentLines[i] = lineContent + "</span>";
}
Expand Down
17 changes: 16 additions & 1 deletion src/assets/js/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ axios.defaults.withCredentials = true;
repliesUrl: 'read/replies',
bansUrl: 'read/bans',
isAuthUrl: 'read/isAuth',
banUrl: 'create/ban'
banUrl: 'create/ban',
deleteReplyUrl: 'delete/reply'
};
function url(api) {
return root + urls[api];
Expand Down Expand Up @@ -42,6 +43,16 @@ axios.defaults.withCredentials = true;
});
}

function del(url, params, fn) {
axios.delete(url, { data: params })
.then(function (response) {
fn(null, response.data);
})
.catch(function (error) {
fn(error);
});
}

_api.boards = function (fn) {
get(url('boardsUrl'), { }, fn);
};
Expand Down Expand Up @@ -81,4 +92,8 @@ axios.defaults.withCredentials = true;
_api.ban = function (ip, message, fn) {
post(url('banUrl'), { ip: ip, message: message }, fn);
};

_api.deleteReply = function (id, fn) {
post(url('deleteReplyUrl'), { _id: id }, fn);
};
})();
18 changes: 13 additions & 5 deletions src/components/Catalog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,18 @@
</div>
<hr>
<div id="threads">
<div v-for="thread in threads" class="thread">
<a :href="'/' + $route.params.board + '/thread/' + thread._id"> <img class="thumbnail"
:src="'/' + thread.attachment_path"
width="150"> </a>
<div v-for="thread in threads" class="thread" v-bind:id="thread._id">
<a v-if="thread.attachment_path" :href="'/' + $route.params.board + '/thread/' + thread._id">
<img class="thumbnail" :src="'/' + thread.attachment_path" width="150" v-if="new Array('gif', 'jpg', 'jpeg', 'png').includes(thread.attachment_name.split('.').pop())">
<video class="thumbnail" width="150" v-if="new Array('webm').includes(thread.attachment_name.split('.').pop())">
<source :src="'/' + thread.attachment_path"></source>
</video>
</a>
<div class="meta">
R: <b>?</b>
</div>
<div class="teaser">
<b>{{ thread.title }}</b> <div v-html="thread.content">{{ thread.content }}</div>
<a :href="'/' + $route.params.board + '/thread/' + thread._id"><b>{{ thread.title }}</b></a> <div v-html="thread.content">{{ thread.content }}</div>
</div>
</div>
</div>
Expand Down Expand Up @@ -134,6 +137,11 @@
max-height: 320px;
}
.thread a, a:visited {
color: #34345c;
text-decoration: none;
}
#threads {
text-align: center;
padding: 20px 0;
Expand Down
18 changes: 15 additions & 3 deletions src/components/Login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,18 @@
<tr>
<td style="text-align: center; width: 65px;">Password</td>
<td>
<input name="password" style="width: 145px; text-align: center" type="password" v-model="password">
<input name="password" style="width: 145px; text-align: center" type="password"
v-model="password">
</td>
</tr>
<tr>
<td colspan="2" style="padding: 5px 0; border: none; background: none; text-align: center; font-weight: normal; padding-bottom: 20px">
<td colspan="2"
style="padding: 5px 0; border: none; background: none; text-align: center; font-weight: normal; padding-bottom: 20px">
<input value="Submit" style="margin: 0px;" type="button" v-on:click="login">
</td>
</tr>
</tbody>
<p v-if="error">{{ error }}</p>
</table>
</form>
</div>
Expand All @@ -36,32 +39,38 @@
text-align: center;
clear: both;
}
.boardBanner .boardTitle {
font-family: Tahoma,sans-serif;
font-family: Tahoma, sans-serif;
font-size: 28px;
font-weight: 700;
letter-spacing: -2px;
margin-top: 0;
color: #AF0A0F;
}
body {
background: #eef2ff url(http://s.4cdn.org/image/fade-blue.png) top center repeat-x;
}
hr {
border: 0;
border-top: 1px solid #b7c5d9;
height: 0;
}
table {
border-spacing: 1px;
margin-left: auto;
margin-right: auto;
}
td {
margin: 0;
padding: 0;
font-size: 10pt;
}
td:first-child {
background-color: #D6DAF0;
border: 1px solid #34345C;
Expand Down Expand Up @@ -93,6 +102,9 @@
vm.loggedIn = true;
vm.$router.push('/');
}
else if (res.error) {
vm.error = res.error;
}
});
},
logout() {
Expand Down
80 changes: 67 additions & 13 deletions src/components/Thread.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,25 @@
<div class="boardTitle">/{{ $route.params.board }}/ {{ board.name }}</div>
</div>
<hr class="abovePostLink">
<div id="postLink"> [<a :href="$route.params.thread + '/post'">Post a Reply</a>]</div>
<div id="postLink"> [<a href="#" v-on:click="toggleReplyBox">Post a Reply</a>]</div>
<hr>
<div class="board">
<div class="thread">
<div class="postContainer opContainer">
<div id="{UID}" class="post op">
<div class="file">
<div v-bind:id="thread._id" class="post op">
<div v-if="thread.attachment_path" class="file">
<div class="fileText"> File: <a :href="'/' + thread.attachment_path">{{ thread.attachment_name }}</a></div>
<a class="fileThumb" :href="'/' + thread.attachment_path" target="_blank"> <img
:src="'/' + thread.attachment_path">
</a></div>
<a class="fileThumb" :href="'/' + thread.attachment_path" target="_blank" v-if="new Array('gif', 'jpg', 'jpeg', 'png').includes(thread.attachment_name.split('.').pop())">
<img :src="'/' + thread.attachment_path">
</a>
<video class="fileThumb" v-if="new Array('webm').includes(thread.attachment_name.split('.').pop())" controls="">
<source :src="'/' + thread.attachment_path"></source>
</video>
</div>
<div class="postInfo"><span class="subject">{{ thread.title }}</span> <span class="nameBlock"> <span
class="name">{{ thread.name }}</span> </span> <span class="dateTime"
data-utc="1523057718{INSERT}">{{ new Date(thread.timeStamp) }}</span>
<span class="postNum"> <a href="#{ID}" title="Link to this post">No.</a> <a
>{{ new Date(thread.timeStamp) }}</span>
<span class="postNum"> <a :href="'#' + thread._id" title="Link to this post">No.</a> <a
href="{JS FOR APPENDING ID TO REPLY}"
title="Reply to this post">{{ thread._id }}</a> </span> <span v-if="isMod"><button v-on:click="ban(thread)">Ban</button></span></div>
<blockquote class="postMessage" v-html="thread.content">
Expand All @@ -35,15 +39,15 @@

<div v-for="reply in replies" class="postContainer replyContainer">
<div class="sideArrows">>></div>
<div class="post reply">
<div class="post reply" v-bind:id="reply._id">
<div v-if="reply.attachment_path" class="file">
<div class="fileText"> File: <a :href="'/' + reply.attachment_path">{{ reply.attachment_name }}</a></div>
<a class="fileThumb" :href="'/' + reply.attachment_path" target="_blank"> <img :src="'/' + reply.attachment_path"> </a>
</div>
<div class="postInfo"><span class="nameBlock"> <span class="name">{{ reply.name }}</span> </span> <span
class="dateTime" data-utc="1523057718{INSERT}">{{ new Date(reply.time) }}</span> <span
class="postNum"> <a href="#{ID}" title="Link to this post">No.</a> <a
href="{JS FOR APPENDING ID TO REPLY}" title="Reply to this post">{{ reply._id }}</a> </span> <span v-if="isMod"><button v-on:click="ban(reply)">Ban</button></span>
class="dateTime">{{ new Date(reply.time) }}</span> <span
class="postNum"> <a :href="'#' + reply_id" title="Link to this post">No.</a> <a
href="{JS FOR APPENDING ID TO REPLY}" title="Reply to this post">{{ reply._id }}</a> </span> <span v-if="isMod"><button v-on:click="ban(reply)">Ban</button> <button v-on:click="deleteReply(reply)">Delete</button></span>
</div>
<blockquote
class="postMessage"> {{ reply.content }}
Expand All @@ -56,6 +60,31 @@
href="catalog.php#top">Top</a> / <a href="/" target="_top">Home</a> ] </span></div>
<br>
</div>
</div>
</div>

<div class="replyBox" v-if="replyBoxShown">
<p>Post Reply</p>
<form name="post" action="/create/reply" method="post" enctype="multipart/form-data">
<tbody>
<tr style="display: none;" data-type="Thread">
<td>Thread</td>
<td><input id="thread" name="threadId" type="text" v-model="thread._id"></td>
</tr>
<tr data-type="Content">
<td>Content</td>
<td><textarea name="content" cols="48" rows="4" wrap="soft" tabindex="4"></textarea></td>
</tr>
<tr data-type="File">
<td>File</td>
<td><input id="postFile" name="attachment" type="file" tabindex="7">
</td>
</tr>
</tbody>
<button type="submit">Post</button>
</form>
</div>
</div>
</template>

<style scoped>
Expand All @@ -64,6 +93,15 @@
text-decoration: none;
}
.replyBox {
position: fixed;
border-style: solid;
left: 600px;
top: 200px;
border-color: black;
border-width: 2px;
}
.abovePostLink {
width: 90%;
}
Expand Down Expand Up @@ -159,7 +197,7 @@
margin-left: 2px;
}
.fileThumb img {
.fileThumb img, video {
max-width: 250px;
max-height: 250px;
height: auto;
Expand Down Expand Up @@ -209,6 +247,7 @@
board: {},
replies: [],
isMod: false,
replyBoxShown: false,
boardList: "t / r / a / p"
}
},
Expand Down Expand Up @@ -244,6 +283,17 @@
}
});
},
deleteReply(reply) {
let vm = this;
_api.deleteReply(reply._id, function (err, res) {
if (err) {
console.log(err);
}
else if (res.result) {
vm.$router.go(vm.$router.currentRoute);
}
});
},
updateThread(id) {
let vm = this;
_api.thread(id, function (err, res) {
Expand Down Expand Up @@ -285,6 +335,10 @@
}
});
},
toggleReplyBox() {
let vm = this;
vm.replyBoxShown = !vm.replyBoxShown;
},
compileBoardList() {
let vm = this;
_api.boards(function (err, res) {
Expand Down

0 comments on commit 7c64635

Please sign in to comment.