diff --git a/lib.js b/lib.js index 55156e4..9610e3b 100644 --- a/lib.js +++ b/lib.js @@ -9,6 +9,11 @@ function apiStat(res, next, message, success = false, redirect = '/') { next(); } +function splitUp(content) { + let out = content.split('\n').map(x => x.split('::')); + return out; +} + async function replyIterator(replies, db) { for (let reply of replies) { if (reply.childType == 'hub') { @@ -31,6 +36,9 @@ async function replyIterator(replies, db) { reply.comment.type = reply.childType; //reply.comment.id = reply.childId; } + for (let reply of replies) { + reply.comment.content = splitUp(reply.comment.content) + } return replies; } diff --git a/public/index.css b/public/index.css index 6fff367..d376c56 100644 --- a/public/index.css +++ b/public/index.css @@ -194,4 +194,9 @@ h1 { .link { color: inherit; +} + +.commentbox { + white-space: pre-wrap; + word-wrap: break-word; } \ No newline at end of file diff --git a/public/index.js b/public/index.js index 0b49900..422d879 100644 --- a/public/index.js +++ b/public/index.js @@ -5,9 +5,10 @@ async function formClick(ev) { let fData = new FormData(target); - let file = target.querySelector('input[type=file]'); - if (file) + for (let file of target.querySelectorAll('.form-input')) { file.value = null; + file.textContent = ''; + } let fetched = await fetch(target.action, { 'method': 'POST', diff --git a/routes/commenter.js b/routes/commenter.js index 7c41546..7b62d8e 100644 --- a/routes/commenter.js +++ b/routes/commenter.js @@ -23,7 +23,11 @@ router.post('/', async (req, res, next) => { return; } - let token = randomBytes(12).toString('hex'); + let token = randomBytes(8).toString('hex'); + + if (req.file && req.file.path) { + post += `\nfile::${req.file.path}`; + } await db.run('INSERT INTO comment (username, date, content, id) VALUES (?,?,?,?)', [ username, diff --git a/routes/init.js b/routes/init.js index 74e3498..893fe32 100644 --- a/routes/init.js +++ b/routes/init.js @@ -3,10 +3,21 @@ import multer from "multer"; import cookieParser from "cookie-parser"; import { initDb } from "../db.js"; import express from "express"; +import { randomBytes } from 'node:crypto'; let db = await initDb(); -const upload = multer({ dest: 'uploads/' }); +const upload = multer.diskStorage({ + destination: function (req, file, cb) { + cb(null, './uploads/') + }, + filename: function (req, file, cb) { + const uniqueSuffix = randomBytes(8).toString('hex'); + cb(null, uniqueSuffix + '.png') + } +}); + +const upload2 = multer({ storage: upload }); const aliases = { '/': '/walls/get/hub/main/0' @@ -95,8 +106,8 @@ async function doInit(app) { app.use(auther) app.use(initr) - app.use('/api/form', upload.none()); - app.use('/api/file', upload.single('file')); + app.use('/api/form', upload2.none()); + app.use('/api/file', upload2.single('file')); await importRouters(app, routers); diff --git a/views/comment.ejs b/views/comment.ejs index 3e35267..bc0ad73 100644 --- a/views/comment.ejs +++ b/views/comment.ejs @@ -6,7 +6,13 @@ Context <% } %> -
<%= content %>
+ <% for (let contentN of content) { %> + <% if (contentN[0] == 'file' && contentN [1]) { %> + '> + <% } else { %> +
<%= contentN[0] %>
+ <% } %> + <% } %> <% if (!isNaN(date * 1)) { %>
Posted on <%= new Date(date).toISOString() %>
<% } %>