add embeds support

This commit is contained in:
biglyderv 2025-05-26 18:06:31 -04:00
parent e86d4f4212
commit 21476e6e43
Signed by: biglyderv
GPG key ID: 0E2EB0B4CD7397B5
3 changed files with 63 additions and 6 deletions

49
lib.js
View file

@ -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;
}

View file

@ -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;
}

View file

@ -3,8 +3,15 @@
<a class='link' href='<%= contentN[1] %>'>
<% if (['gif','png','jpg'].indexOf(contentN[2]) != -1) { %>
<img class='art' src='<%= contentN[1] %>'>
<% } else if (['!neoboxels'].indexOf(contentN[2]) != -1) { %>
</a>
<iframe src="https://sand.dervland.net/?only=true&embed=https://com.dervland.net/uploads/<%= contentN[1] %>"></iframe>
<a>
<% } else if (['txt','json'].indexOf(contentN[2]) != -1) { %>
<%= contentN[1] %>
</a>
<textarea class="form-input big-text"> <%= contentN[3] %> </textarea>
<a>
<% } else if (['mp4','mp3','webm','wav'].indexOf(contentN[2]) != -1) { %>
<video class='art' controls>
<source src='<%= contentN[1] %>'>