diff --git a/lib.js b/lib.js index ac1b875..f345980 100644 --- a/lib.js +++ b/lib.js @@ -35,10 +35,12 @@ async function splitUp(content) { let ext = res.split('.').pop(); let content = ''; let path = new URL(res.slice('file::'.length), 'https://tbg.dervland.net/').pathname; + let encoded = encodeURIComponent(path); if (ext == 'txt' || ext == 'json') { let san = sanitize(path.split('/').pop(), ''); try { content = await readFile(`${process.cwd()}/uploads/${san}`, 'utf-8'); + content.length = Math.min(content.length,5000); } catch (err) { content = ''; } @@ -60,7 +62,7 @@ async function splitUp(content) { height = contentJson.height; } - out[i] = { type: 'file', path, ext, content, width, height }; + out[i] = { type: 'file', path, ext, content, width, height, encoded }; continue; } if (res.startsWith('https://')) { diff --git a/routes/init.js b/routes/init.js index 9e0e65b..d62f597 100644 --- a/routes/init.js +++ b/routes/init.js @@ -17,6 +17,8 @@ const mimes = { 'image/png': 'png', 'audio/mpeg': 'mp3', 'audio/wav': 'wav', + 'pmp': 'pmp', + 'sb3': 'sb3' }; const upload = multer.diskStorage({ @@ -25,7 +27,7 @@ const upload = multer.diskStorage({ }, filename: function (req, file, cb) { const uniqueSuffix = randomBytes(8).toString('hex'); - const type = mimes[file.mimetype] || 'txt'; + const type = mimes[file.mimetype] || mimes[file.originalname.split('.').pop()] || 'txt'; cb(null, uniqueSuffix + '.' + type) } }); @@ -97,7 +99,7 @@ async function initr(req, res, next) { 'unread' ]); - msgCount = messages[0]['count(*)']; + msgCount = messages[0]['count(*)']; } let headerCtx = [ diff --git a/views/formatted.ejs b/views/formatted.ejs index 7baad97..b07363a 100644 --- a/views/formatted.ejs +++ b/views/formatted.ejs @@ -5,8 +5,16 @@ <% } else if (contentN.ext == '!neoboxels') { %> - - Neoboxels Save + + Play my Neoboxels map! + <% } else if (contentN.ext == 'pmp') { %> + + + Play my PenguinMod project! + <% } else if (contentN.ext == 'sb3') { %> + + + Play my Scratch project! <% } else if (['txt','json'].indexOf(contentN.ext) != -1) { %> <%= contentN.href %>