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(reservedRe, replacement)
.replace(windowsReservedRe, replacement);
return sanitized.slice(0,200);
return sanitized.slice(0, 200);
}
async function importRouters(app, routers) {
@ -32,48 +32,53 @@ async function splitUp(content) {
for (let i in out) {
let res = out[i];
if (res.startsWith('file::')) {
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 ext = res.split('.').pop();
let content = '';
let path = new URL(res.slice('file::'.length), 'https://tbg.dervland.net/').pathname;
if (ext == 'txt' || ext == 'json') {
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 {
innerJson = JSON.parse(inner)
contentJson = JSON.parse(content)
} catch (err) {
innerJson = {};
contentJson = {};
}
if (innerJson.pal) {
//type = '!neoboxels'
if (contentJson.pal) {
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;
}
if (res.startsWith('https://')) {
out[i] = ['link', res];
out[i] = { type: 'link', name: res, href: res };
continue;
}
let urlThing = "";
let href = "";
if (res[0] == '@' || res[0] == '#') {
let type = res[0] == '@' ? '/users/' : '/walls/get/hub/';
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] == '@') {
out[i] = ['curl', res, urlThing];
out[i] = { type: 'link', name: res, href };
continue;
}
if (res[0] == '#') {
out[i] = ['curl', res, urlThing];
out[i] = { type: 'link', name: res, href };
continue;
}
out[i] = [res];
out[i] = {type: 'normal', data: res};
}
return out;
}

View file

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

View file

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