add more file formats
This commit is contained in:
parent
552f075f31
commit
718b912719
3 changed files with 17 additions and 5 deletions
4
lib.js
4
lib.js
|
@ -35,10 +35,12 @@ async function splitUp(content) {
|
||||||
let ext = res.split('.').pop();
|
let ext = res.split('.').pop();
|
||||||
let content = '';
|
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;
|
||||||
|
let encoded = encodeURIComponent(path);
|
||||||
if (ext == 'txt' || ext == 'json') {
|
if (ext == 'txt' || ext == 'json') {
|
||||||
let san = sanitize(path.split('/').pop(), '');
|
let san = sanitize(path.split('/').pop(), '');
|
||||||
try {
|
try {
|
||||||
content = await readFile(`${process.cwd()}/uploads/${san}`, 'utf-8');
|
content = await readFile(`${process.cwd()}/uploads/${san}`, 'utf-8');
|
||||||
|
content.length = Math.min(content.length,5000);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
content = '';
|
content = '';
|
||||||
}
|
}
|
||||||
|
@ -60,7 +62,7 @@ async function splitUp(content) {
|
||||||
height = contentJson.height;
|
height = contentJson.height;
|
||||||
}
|
}
|
||||||
|
|
||||||
out[i] = { type: 'file', path, ext, content, width, height };
|
out[i] = { type: 'file', path, ext, content, width, height, encoded };
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (res.startsWith('https://')) {
|
if (res.startsWith('https://')) {
|
||||||
|
|
|
@ -17,6 +17,8 @@ const mimes = {
|
||||||
'image/png': 'png',
|
'image/png': 'png',
|
||||||
'audio/mpeg': 'mp3',
|
'audio/mpeg': 'mp3',
|
||||||
'audio/wav': 'wav',
|
'audio/wav': 'wav',
|
||||||
|
'pmp': 'pmp',
|
||||||
|
'sb3': 'sb3'
|
||||||
};
|
};
|
||||||
|
|
||||||
const upload = multer.diskStorage({
|
const upload = multer.diskStorage({
|
||||||
|
@ -25,7 +27,7 @@ const upload = multer.diskStorage({
|
||||||
},
|
},
|
||||||
filename: function (req, file, cb) {
|
filename: function (req, file, cb) {
|
||||||
const uniqueSuffix = randomBytes(8).toString('hex');
|
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)
|
cb(null, uniqueSuffix + '.' + type)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -97,7 +99,7 @@ async function initr(req, res, next) {
|
||||||
'unread'
|
'unread'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
msgCount = messages[0]['count(*)'];
|
msgCount = messages[0]['count(*)'];
|
||||||
}
|
}
|
||||||
|
|
||||||
let headerCtx = [
|
let headerCtx = [
|
||||||
|
|
|
@ -5,8 +5,16 @@
|
||||||
<img class='art' src='<%= contentN.path %>'>
|
<img class='art' src='<%= contentN.path %>'>
|
||||||
<% } else if (contentN.ext == '!neoboxels') { %>
|
<% } else if (contentN.ext == '!neoboxels') { %>
|
||||||
</a>
|
</a>
|
||||||
<a class='link' href='https://sand.dervland.net/?embed=https://com.dervland.net<%= contentN.path %>'>
|
<a class='form-button' href='https://sand.dervland.net/?embed=https://com.dervland.net<%= contentN.encoded %>'>
|
||||||
Neoboxels Save
|
Play my Neoboxels map!
|
||||||
|
<% } else if (contentN.ext == 'pmp') { %>
|
||||||
|
</a>
|
||||||
|
<a class='form-button' href='https://studio.penguinmod.com/editor.html?project_url=https://com.dervland.net<%= contentN.encoded %>'>
|
||||||
|
Play my PenguinMod project!
|
||||||
|
<% } else if (contentN.ext == 'sb3') { %>
|
||||||
|
</a>
|
||||||
|
<a class='form-button' href='https://turbowarp.org/editor.html?project_url=https://com.dervland.net<%= contentN.encoded %>'>
|
||||||
|
Play my Scratch project!
|
||||||
<% } else if (['txt','json'].indexOf(contentN.ext) != -1) { %>
|
<% } else if (['txt','json'].indexOf(contentN.ext) != -1) { %>
|
||||||
<%= contentN.href %>
|
<%= contentN.href %>
|
||||||
</a>
|
</a>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue