diff --git a/lib.js b/lib.js index a793da5..c72a0e8 100644 --- a/lib.js +++ b/lib.js @@ -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; } diff --git a/public/index.css b/public/index.css index 90e9d2c..a170b34 100644 --- a/public/index.css +++ b/public/index.css @@ -235,7 +235,5 @@ h1 { iframe { border: none; - width: 700px; - height: 900px; overflow: auto; } \ No newline at end of file diff --git a/views/formatted.ejs b/views/formatted.ejs index b853344..3f2e732 100644 --- a/views/formatted.ejs +++ b/views/formatted.ejs @@ -1,30 +1,28 @@ <% for (let contentN of content) { %> -<% if (contentN[0] == 'file') { %> - - <% if (['gif','png','jpg'].indexOf(contentN[2]) != -1) { %> - - <% } else if (['!neoboxels'].indexOf(contentN[2]) != -1) { %> +<% if (contentN.type == 'file') { %> + + <% if (['gif','png','jpg'].indexOf(contentN.ext) != -1) { %> + + <% } else if (contentN.ext == '!neoboxels') { %> - - https://sand.dervland.net/?embed=https://com.dervland.net<%= contentN[1] %> + + https://sand.dervland.net/?embed=https://com.dervland.net<%= contentN.path %> - + - <% } else if (['txt','json'].indexOf(contentN[2]) != -1) { %> - <%= contentN[1] %> + <% } else if (['txt','json'].indexOf(contentN.ext) != -1) { %> + <%= contentN.href %> - + - <% } else if (['mp4','mp3','webm','wav'].indexOf(contentN[2]) != -1) { %> + <% } else if (['mp4','mp3','webm','wav'].indexOf(contentN.ext) != -1) { %> <% } %> -<% } else if (contentN[0] == 'link') { %> -<%= contentN[1] %> -<% } else if (contentN[0] == 'curl') { %> -<%= contentN[1] %> -<% } else if (contentN[0].replaceAll(' ','').length > 0) { %> -<%= contentN[0] %> +<% } else if (contentN.type == 'link') { %> +<%= contentN.name %> +<% } else if (contentN.type.replaceAll(' ','').length > 0) { %> +<%= contentN.data %> <% } } %> \ No newline at end of file