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