embedding fixes and cleanup

This commit is contained in:
biglyderv 2025-05-26 23:37:14 -04:00
parent 9732d9aef0
commit fe9e3ce840
Signed by: biglyderv
GPG key ID: 0E2EB0B4CD7397B5
3 changed files with 40 additions and 39 deletions

41
lib.js
View file

@ -12,7 +12,7 @@ function sanitize(input, replacement) {
.replace(controlRe, replacement) .replace(controlRe, replacement)
.replace(reservedRe, replacement) .replace(reservedRe, replacement)
.replace(windowsReservedRe, replacement); .replace(windowsReservedRe, replacement);
return sanitized.slice(0,200); return sanitized.slice(0, 200);
} }
async function importRouters(app, routers) { async function importRouters(app, routers) {
@ -32,48 +32,53 @@ async function splitUp(content) {
for (let i in out) { for (let i in out) {
let res = out[i]; let res = out[i];
if (res.startsWith('file::')) { if (res.startsWith('file::')) {
let type = res.split('.').pop(); let ext = res.split('.').pop();
let inner = ''; let content = '';
let path = new URL(res.slice('file::'.length), 'https://tbg.dervland.net/').pathname; let path = new URL(res.slice('file::'.length), 'https://tbg.dervland.net/').pathname;
if (type == 'txt' || type == 'json') { if (ext == 'txt' || ext == 'json') {
let san = sanitize(path.split('/').pop(), ''); let san = sanitize(path.split('/').pop(), '');
inner = await readFile(`${process.cwd()}/uploads/${san}`, 'utf-8'); content = await readFile(`${process.cwd()}/uploads/${san}`, 'utf-8');
} }
let innerJson = {}; let contentJson = {};
let width = 0;
let height = 0;
try { try {
innerJson = JSON.parse(inner) contentJson = JSON.parse(content)
} catch (err) { } catch (err) {
innerJson = {}; contentJson = {};
} }
if (innerJson.pal) { if (contentJson.pal) {
//type = '!neoboxels' ext = '!neoboxels';
console.log(Object.keys(contentJson))
width = contentJson.width * 4;
height = contentJson.height *4;
} }
out[i] = ['file', path, type, inner]; out[i] = { type: 'file', path, ext, content, width, height };
continue; continue;
} }
if (res.startsWith('https://')) { if (res.startsWith('https://')) {
out[i] = ['link', res]; out[i] = { type: 'link', name: res, href: res };
continue; continue;
} }
let urlThing = ""; let href = "";
if (res[0] == '@' || res[0] == '#') { if (res[0] == '@' || res[0] == '#') {
let type = res[0] == '@' ? '/users/' : '/walls/get/hub/'; let type = res[0] == '@' ? '/users/' : '/walls/get/hub/';
let type2 = res[0] == '@' ? '' : '/0'; let type2 = res[0] == '@' ? '' : '/0';
urlThing = new URL(type + res.slice(1) + type2, 'https://tbg.dervland.net/').pathname href = new URL(type + res.slice(1) + type2, 'https://tbg.dervland.net/').pathname
} }
if (res[0] == '@') { if (res[0] == '@') {
out[i] = ['curl', res, urlThing]; out[i] = { type: 'link', name: res, href };
continue; continue;
} }
if (res[0] == '#') { if (res[0] == '#') {
out[i] = ['curl', res, urlThing]; out[i] = { type: 'link', name: res, href };
continue; continue;
} }
out[i] = [res]; out[i] = {type: 'normal', data: res};
} }
return out; return out;
} }

View file

@ -235,7 +235,5 @@ h1 {
iframe { iframe {
border: none; border: none;
width: 700px;
height: 900px;
overflow: auto; overflow: auto;
} }

View file

@ -1,30 +1,28 @@
<% for (let contentN of content) { %> <% for (let contentN of content) { %>
<% if (contentN[0] == 'file') { %> <% if (contentN.type == 'file') { %>
<a class='link' href='<%= contentN[1] %>'> <a class='link' href='<%= contentN.path %>'>
<% if (['gif','png','jpg'].indexOf(contentN[2]) != -1) { %> <% if (['gif','png','jpg'].indexOf(contentN.ext) != -1) { %>
<img class='art' src='<%= contentN[1] %>'> <img class='art' src='<%= contentN.path %>'>
<% } else if (['!neoboxels'].indexOf(contentN[2]) != -1) { %> <% } else if (contentN.ext == '!neoboxels') { %>
</a> </a>
<a class='link' href='https://sand.dervland.net/?embed=https://com.dervland.net<%= contentN[1] %>'> <a class='link' href='https://sand.dervland.net/?embed=https://com.dervland.net<%= contentN.path %>'>
https://sand.dervland.net/?embed=https://com.dervland.net<%= contentN[1] %> https://sand.dervland.net/?embed=https://com.dervland.net<%= contentN.path %>
</a> </a>
<iframe src="https://sand.dervland.net/?only=true&embed=https://com.dervland.net<%= contentN[1] %>"></iframe> <iframe width="<%= contentN.width %>" height="<%= contentN.height %>" src="https://sand.dervland.net/?only=true&embed=https://com.dervland.net<%= contentN.path %>"></iframe>
<a> <a>
<% } else if (['txt','json'].indexOf(contentN[2]) != -1) { %> <% } else if (['txt','json'].indexOf(contentN.ext) != -1) { %>
<%= contentN[1] %> <%= contentN.href %>
</a> </a>
<textarea class="form-input big-text"> <%= contentN[3] %> </textarea> <textarea class="form-input big-text"> <%= contentN.content %> </textarea>
<a> <a>
<% } else if (['mp4','mp3','webm','wav'].indexOf(contentN[2]) != -1) { %> <% } else if (['mp4','mp3','webm','wav'].indexOf(contentN.ext) != -1) { %>
<video class='art' controls> <video class='art' controls>
<source src='<%= contentN[1] %>'> <source src='<%= contentN.ext %>'>
</video> </video>
<% } %> <% } %>
</a> </a>
<% } else if (contentN[0] == 'link') { %> <% } else if (contentN.type == 'link') { %>
<a class='link' href='<%= contentN[1] %>'><%= contentN[1] %></a> <a class='link' href='<%= contentN.href %>'><%= contentN.name %></a>
<% } else if (contentN[0] == 'curl') { %> <% } else if (contentN.type.replaceAll(' ','').length > 0) { %>
<a class='link' href='<%= contentN[2] %>'><%= contentN[1] %></a> <span class='commentbox'><%= contentN.data %></span>
<% } else if (contentN[0].replaceAll(' ','').length > 0) { %>
<span class='commentbox'><%= contentN[0] %></span>
<% } } %> <% } } %>