diff --git a/lib.js b/lib.js
index d471026..447d0e5 100644
--- a/lib.js
+++ b/lib.js
@@ -1,3 +1,20 @@
+import { readFile } from "fs/promises";
+
+
+var illegalRe = /[\/\?<>\\:\*\|":]/g;
+var controlRe = /[\x00-\x1f\x80-\x9f]/g;
+var reservedRe = /^\.+$/;
+var windowsReservedRe = /^(con|prn|aux|nul|com[0-9]|lpt[0-9])(\..*)?$/i;
+
+function sanitize(input, replacement) {
+ var sanitized = input
+ .replace(illegalRe, replacement)
+ .replace(controlRe, replacement)
+ .replace(reservedRe, replacement)
+ .replace(windowsReservedRe, replacement);
+ return sanitized.slice(0,200);
+}
+
async function importRouters(app, routers) {
for (let router in routers) {
await app.use(router, (await import(routers[router])).default)
@@ -9,17 +26,37 @@ function apiStat(res, next, message, success = false, redirect = '/') {
next();
}
-function splitUp(content) {
+async function splitUp(content) {
let out = content.split(/(\s+)/g);
for (let i in out) {
let res = out[i];
if (res.startsWith('file::')) {
- out[i] = ['file', new URL(res.slice('file::'.length), 'https://tbg.dervland.net/').pathname , res.split('.').pop()];
+ let type = res.split('.').pop();
+ let inner = '';
+ let path = new URL(res.slice('file::'.length), 'https://tbg.dervland.net/').pathname;
+ if (type == 'txt' || type == 'json') {
+ let san = sanitize(path.split('/').pop(), '');
+ inner = await readFile(`${process.cwd()}/uploads/${san}`, 'utf-8');
+ }
+
+ let innerJson = {};
+
+ try {
+ innerJson = JSON.parse(inner)
+ } catch (err) {
+ innerJson = {};
+ }
+
+ if (innerJson.pal) {
+ type = '!neoboxels'
+ }
+
+ out[i] = ['file', path, type, inner];
continue;
}
if (res.startsWith('https://')) {
- out[i] = ['link',res];
+ out[i] = ['link', res];
continue;
}
let urlThing = "";
@@ -29,11 +66,11 @@ function splitUp(content) {
urlThing = new URL(type + res.slice(1) + type2, 'https://tbg.dervland.net/').pathname
}
if (res[0] == '@') {
- out[i] = ['curl',res, urlThing];
+ out[i] = ['curl', res, urlThing];
continue;
}
if (res[0] == '#') {
- out[i] = ['curl',res, urlThing];
+ out[i] = ['curl', res, urlThing];
continue;
}
out[i] = [res];
@@ -64,7 +101,7 @@ async function replyIterator(replies, db) {
//reply.comment.id = reply.childId;
}
for (let reply of replies) {
- reply.comment.content = splitUp(reply.comment.content)
+ reply.comment.content = await splitUp(reply.comment.content)
}
return replies;
}
diff --git a/public/index.css b/public/index.css
index 353d86e..4e78bea 100644
--- a/public/index.css
+++ b/public/index.css
@@ -224,4 +224,17 @@ h1 {
.form-button, .form-message, form .header-big {
grid-column: span 1;
}
+}
+
+.big-text {
+ min-width: 500px;
+ min-height: 300px;
+ display: block;
+ text-decoration: none;
+}
+
+iframe {
+ border: none;
+ width: 500px;
+ height: 500px;
}
\ No newline at end of file
diff --git a/views/formatted.ejs b/views/formatted.ejs
index ada9ec3..51d5916 100644
--- a/views/formatted.ejs
+++ b/views/formatted.ejs
@@ -3,8 +3,15 @@
<% if (['gif','png','jpg'].indexOf(contentN[2]) != -1) { %>
+ <% } else if (['!neoboxels'].indexOf(contentN[2]) != -1) { %>
+
+
+
<% } else if (['txt','json'].indexOf(contentN[2]) != -1) { %>
<%= contentN[1] %>
+
+
+
<% } else if (['mp4','mp3','webm','wav'].indexOf(contentN[2]) != -1) { %>