better embeds
This commit is contained in:
parent
729a7b8c56
commit
6ef218055e
3 changed files with 28 additions and 5 deletions
2
lib.js
2
lib.js
|
@ -15,7 +15,7 @@ function splitUp(content) {
|
||||||
for (let i in out) {
|
for (let i in out) {
|
||||||
let res = out[i];
|
let res = out[i];
|
||||||
if (res.startsWith('file::')) {
|
if (res.startsWith('file::')) {
|
||||||
out[i] = ['file', res.slice('file::'.length)];
|
out[i] = ['file', new URL(res.slice('file::'.length), 'https://tbg.dervland.net/').pathname , res.split('.').pop()];
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (res.startsWith('https://')) {
|
if (res.startsWith('https://')) {
|
||||||
|
|
|
@ -7,13 +7,26 @@ import { randomBytes } from 'node:crypto';
|
||||||
|
|
||||||
let db = await initDb();
|
let db = await initDb();
|
||||||
|
|
||||||
|
const mimes = {
|
||||||
|
'image/gif': 'gif',
|
||||||
|
'image/jpeg': 'jpg',
|
||||||
|
'text/plain': 'txt',
|
||||||
|
'application/json': 'json',
|
||||||
|
'video/mp4': 'mp4',
|
||||||
|
'video/webm': 'webm',
|
||||||
|
'image/png': 'png',
|
||||||
|
'audio/mpeg': 'mp3',
|
||||||
|
'audio/wav': 'wav',
|
||||||
|
};
|
||||||
|
|
||||||
const upload = multer.diskStorage({
|
const upload = multer.diskStorage({
|
||||||
destination: function (req, file, cb) {
|
destination: function (req, file, cb) {
|
||||||
cb(null, './uploads/')
|
cb(null, './uploads/')
|
||||||
},
|
},
|
||||||
filename: function (req, file, cb) {
|
filename: function (req, file, cb) {
|
||||||
const uniqueSuffix = randomBytes(8).toString('hex');
|
const uniqueSuffix = randomBytes(8).toString('hex');
|
||||||
cb(null, uniqueSuffix + '.png')
|
const type = mimes[file.mimetype] || 'txt';
|
||||||
|
cb(null, uniqueSuffix + '.' + type)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -81,7 +94,7 @@ function initr(req, res, next) {
|
||||||
{ link: '/walls/list', icon: '/walls.svg', name: 'Explore' },
|
{ link: '/walls/list', icon: '/walls.svg', name: 'Explore' },
|
||||||
{ link: '/users/' + (res.auth ? res.auth.username : ''), icon: '/login.svg', name: 'You' },
|
{ link: '/users/' + (res.auth ? res.auth.username : ''), icon: '/login.svg', name: 'You' },
|
||||||
{ link: '/you/messages', icon: '/mail.svg', name: 'Messages' },
|
{ link: '/you/messages', icon: '/mail.svg', name: 'Messages' },
|
||||||
{ link: '/you/logout', icon: '/logout.svg', name: 'Leave' }
|
{ link: '/you/logout', icon: '/logout.svg', name: 'Leave' }
|
||||||
];
|
];
|
||||||
|
|
||||||
if (!res.auth || !res.auth.valid) {
|
if (!res.auth || !res.auth.valid) {
|
||||||
|
|
|
@ -10,9 +10,19 @@
|
||||||
<div>
|
<div>
|
||||||
<% for (let contentN of content) { %>
|
<% for (let contentN of content) { %>
|
||||||
<% if (contentN[0] == 'file') { %>
|
<% if (contentN[0] == 'file') { %>
|
||||||
<img class='art' src='<%= new URL(contentN[1], 'https://tbg.dervland.net/') %>'>
|
<a class='link' href='<%= contentN[1] %>'>
|
||||||
|
<% if (['gif','png','jpg'].indexOf(contentN[2]) != -1) { %>
|
||||||
|
<img class='art' src='<%= contentN[1] %>'>
|
||||||
|
<% } else if (['txt','json'].indexOf(contentN[2]) != -1) { %>
|
||||||
|
<%= contentN[1] %>
|
||||||
|
<% } else if (['mp4','mp3','webm','wav'].indexOf(contentN[2]) != -1) { %>
|
||||||
|
<video class='art' controls>
|
||||||
|
<source src='<%= contentN[1] %>'>
|
||||||
|
</video>
|
||||||
|
<% } %>
|
||||||
|
</a>
|
||||||
<% } else if (contentN[0] == 'link') { %>
|
<% } else if (contentN[0] == 'link') { %>
|
||||||
<a class='link' href='<%= contentN[1] %>.'><%= contentN[1] %></a>
|
<a class='link' href='<%= contentN[1] %>'><%= contentN[1] %></a>
|
||||||
<% } else if (contentN[0].replaceAll(' ','').length > 0) { %>
|
<% } else if (contentN[0].replaceAll(' ','').length > 0) { %>
|
||||||
<span class='commentbox'><%= contentN[0] %></span>
|
<span class='commentbox'><%= contentN[0] %></span>
|
||||||
<% } } %>
|
<% } } %>
|
||||||
|
|
Loading…
Reference in a new issue