turns out discord auto embeds files................ no need for that.

This commit is contained in:
hippoz 2020-10-02 22:13:19 +03:00
parent ec5a603d3c
commit 82bb80da84
2 changed files with 0 additions and 76 deletions

View file

@ -52,36 +52,6 @@ app.get('/file/:filename', (req, res) => {
return; return;
} }
fs.access(filePath, fs.F_OK, (err) => {
if (err) {
res.status(404).send('File not found or is invalid.');
return;
}
const type = getFileType(filePath);
const mimeType = mime.lookup(filePath);
if (type === config.files.other) {
res.contentType('text/plain');
res.sendFile(filePath);
return;
} else {
res.render('file', { filename, fileType: type, fileUrl: `${config.url}/file/raw/${filename}`, mimeType });
return;
}
});
});
app.get('/file/raw/:filename', (req, res) => {
const filename = req.params.filename;
const filePath = path.join(config.storagePath, filename);
const isValid = isPathValid(filename, filePath);
if (!isValid) {
res.status(400).send('Invalid input.');
return;
}
fs.access(filePath, fs.F_OK, (err) => { fs.access(filePath, fs.F_OK, (err) => {
if (err) { if (err) {
res.status(404).send('File not found or is invalid.'); res.status(404).send('File not found or is invalid.');

View file

@ -1,46 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><%= filename %></title>
<% if (fileType !== 'file') { %>
<% if (fileType === 'video') { %>
<meta name="twitter:card" content="player" />
<meta name="twitter:site" content="@harry" />
<meta name="twitter:title" content="<%= filename %>" />
<meta name="twitter:description" content="Video uploaded to hippoz.xyz" />
<meta name="twitter:player" content="<%= fileUrl %>" />
<meta name="twitter:player:width" content="320" />
<meta name="twitter:player:height" content="180" />
<meta name="twitter:player:stream" content="<%= fileUrl %>" />
<meta name="twitter:player:stream:content_type" content="<%= mimeType %>" />
<% } %>
<% if (fileType === 'image') { %>
<meta name="twitter:card" content="summary" />
<meta name="twitter:site" content="@harry" />
<meta name="twitter:title" content="<%= filename %>" />
<meta name="twitter:description" content="Image uploaded to hippoz.xyz" />
<meta name="twitter:image" content="<%= fileUrl %>" />
<meta name="twitter:image:width" content="320" />
<meta name="twitter:image:height" content="180" />
<% } %>
<meta property="og:<%= fileType %>:url" content="<%= fileUrl %>" />
<meta property="og:<%= fileType %>:secure_url" content="<%= fileUrl %>" />
<meta property="og:<%= fileType %>:type" content="<%= mimeType %>" />
<% } %>
</head>
<body>
<% if (fileType === 'audio' || fileType === 'video') { %>
<<%= fileType %> controls name="media" />
<source src="<%= fileUrl %>" type="<%= mimeType %>">
</<%= fileType %>>
<% } %>
<% if (fileType === 'image') { %>
<img src="<%= fileUrl %>" name="media"></img>
<% } %>
</body>
</html>