reallow non-media files by default
This commit is contained in:
parent
e9fe154142
commit
25c1ea7da2
3 changed files with 101 additions and 74 deletions
|
@ -73,3 +73,16 @@
|
||||||
.image {
|
.image {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
div.nonmedia {
|
||||||
|
height: 100px;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
div.nonmedia p {
|
||||||
|
color: #444;
|
||||||
|
font-size: 20px;
|
||||||
|
font-weight: 400;
|
||||||
|
line-height: 100px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
|
@ -33,18 +33,28 @@ const storage = multer.diskStorage({
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const fileFilter = function(req, file, cb) {
|
let allowedMimeTypes = [
|
||||||
if (file.mimetype == "image/png" || file.mimetype == "image/jpg" || file.mimetype == "image/jpeg" || file.mimetype == "image/gif" || file.mimetype == "image/webp"
|
'image/png',
|
||||||
|| file.mimetype == "video/mp4" || file.mimetype == "video/mov" || file.mimetype == "video/webm"
|
'image/jpg',
|
||||||
|| file.mimetype == "audio/mpeg" || file.mimetype == "audio/ogg") {
|
'image/jpeg',
|
||||||
cb(null, true)
|
'image/gif',
|
||||||
} else {
|
'image/webp',
|
||||||
cb(null, false);
|
'video/mp4',
|
||||||
//return cb(new Error('Only media files allowed'));
|
'video/mov',
|
||||||
}
|
'video/webm',
|
||||||
}
|
'audio/mpeg',
|
||||||
|
'audio/ogg'
|
||||||
|
]
|
||||||
|
|
||||||
let upload = multer({ storage: storage, fileFilter: fileFilter });
|
const fileFilter = function(req, file, cb) {
|
||||||
|
if (allowedMimeTypes.includes(file.mimetype)) {
|
||||||
|
cb(null, true);
|
||||||
|
} else {
|
||||||
|
cb(null, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let upload = multer({ storage: storage /**, fileFilter: fileFilter**/ }); //maybe make this a env variable?
|
||||||
|
|
||||||
function fetchMedia(req, res, next) {
|
function fetchMedia(req, res, next) {
|
||||||
db.all('SELECT * FROM media', (err, rows) => {
|
db.all('SELECT * FROM media', (err, rows) => {
|
||||||
|
|
130
views/index.ejs
130
views/index.ejs
|
@ -1,70 +1,74 @@
|
||||||
<!doctype html>
|
<!doctype html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<title>Embedder</title>
|
<title>Embedder</title>
|
||||||
<link rel="stylesheet" href="/css/base.css">
|
<link rel="stylesheet" href="/css/base.css">
|
||||||
<link rel="stylesheet" href="/css/index.css">
|
<link rel="stylesheet" href="/css/index.css">
|
||||||
<link rel="stylesheet" href="/css/app.css">
|
<link rel="stylesheet" href="/css/app.css">
|
||||||
<%
|
<%
|
||||||
function extension(string) {
|
function extension(string) {
|
||||||
return string.slice((string.lastIndexOf(".") - 2 >>> 0) + 2);
|
return string.slice((string.lastIndexOf(".") - 2 >>> 0) + 2);
|
||||||
}
|
}
|
||||||
%>
|
%>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<section class="todoapp">
|
<section class="todoapp">
|
||||||
<nav class="nav">
|
<nav class="nav">
|
||||||
<ul>
|
<ul>
|
||||||
<li class="user"><%= user.name || user.username %></li>
|
<li class="user"><%= user.name || user.username %></li>
|
||||||
<li>
|
<li>
|
||||||
<form action="/logout" method="post">
|
<form action="/logout" method="post">
|
||||||
<button class="logout" type="submit">Sign out</button>
|
<button class="logout" type="submit">Sign out</button>
|
||||||
</form>
|
</form>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
<header class="header">
|
<header class="header">
|
||||||
<h1>Embedder</h1>
|
<h1>Embedder</h1>
|
||||||
<form action="/" method="post" encType="multipart/form-data">
|
<form action="/" method="post" encType="multipart/form-data">
|
||||||
<!---->
|
<!---->
|
||||||
<div id="dropArea">
|
<div id="dropArea">
|
||||||
<p class="dragregion">Upload a file, copy paste, or drag n' drop into the dashed region</p>
|
<p class="dragregion">Upload a file, copy paste, or drag n' drop into the dashed region</p>
|
||||||
<div id="gallery"></div>
|
<div id="gallery"></div>
|
||||||
<p class="dragregion"><input class="" type="file" id="fileupload" name="fileupload"><input type="submit" value="Upload"></p>
|
<p class="dragregion"><input class="" type="file" id="fileupload" name="fileupload"><input type="submit" value="Upload"></p>
|
||||||
<p class="dragregion">Click the file to copy the url</p>
|
<p class="dragregion">Click the file to copy the url</p>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</header>
|
</header>
|
||||||
<% if (Count > 0) { %>
|
<% if (Count > 0) { %>
|
||||||
<section class="main">
|
<section class="main">
|
||||||
<ul class="todo-list">
|
<ul class="todo-list">
|
||||||
<% files.forEach(function(file) { %>
|
<% files.forEach(function(file) { %>
|
||||||
<li>
|
<li>
|
||||||
<form action="<%= file.url %>" method="post">
|
<form action="<%= file.url %>" method="post">
|
||||||
<div class="view">
|
<div class="view">
|
||||||
<% if (extension(file.path) == ".mp4" || extension(file.path) == ".mov" || extension(file.path) == "webp") { %>
|
<% if (extension(file.path) == ".mp4" || extension(file.path) == ".mov" || extension(file.path) == "webp") { %>
|
||||||
<video autoplay loop muted playsinline class="image" src="/uploads/<%=file.path %>" width="100%" onclick="copyURI(event)"></video>
|
<video autoplay loop muted playsinline class="image" src="/uploads/<%=file.path %>" width="100%" onclick="copyURI(event)"></video>
|
||||||
<% } else { %>
|
<% } else if (extension(file.path) == ".jpg" || extension(file.path) == ".jpeg" || extension(file.path) == ".png" || extension(file.path) == ".gif" || extension(file.path) == ".webp" ) { %>
|
||||||
<img class="image" src="/uploads/<%=file.path %>" width="100%" onclick="copyURI(event)">
|
<img class="image" src="/uploads/<%=file.path %>" width="100%" onclick="copyURI(event)">
|
||||||
<% } %>
|
<% } else {%> <!-- non-media file -->
|
||||||
<label text-align:"center"><%= file.path %></label>
|
<div class="nonmedia" onclick="copyURI(event)">
|
||||||
<button class="destroy" form="delete-<%= file.path %>"></button>
|
<p><%=extension(file.path)%> file</p>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
<% } %>
|
||||||
<form name="delete-<%= file.path %>" id="delete-<%= file.path %>" action="<%= file.url %>/delete" method="post">
|
<label text-align:"center"><%= file.path %></label>
|
||||||
</form>
|
<button class="destroy" form="delete-<%= file.path %>"></button>
|
||||||
</li>
|
</div>
|
||||||
<% }); %>
|
</form>
|
||||||
</ul>
|
<form name="delete-<%= file.path %>" id="delete-<%= file.path %>" action="<%= file.url %>/delete" method="post">
|
||||||
</section>
|
</form>
|
||||||
<% } %>
|
</li>
|
||||||
</section>
|
<% }); %>
|
||||||
<footer class="info">
|
</ul>
|
||||||
<p><a href="https://l.nekomimi.pet/project">Created by Wavering Ana</a></p>
|
</section>
|
||||||
<p><a href="https://github.com/WaveringAna/Embedder">Github</a></p>
|
<% } %>
|
||||||
</footer>
|
</section>
|
||||||
<script src="/js/index.js"></script>
|
<footer class="info">
|
||||||
</body>
|
<p><a href="https://l.nekomimi.pet/project">Created by Wavering Ana</a></p>
|
||||||
|
<p><a href="https://github.com/WaveringAna/Embedder">Github</a></p>
|
||||||
|
</footer>
|
||||||
|
<script src="/js/index.js"></script>
|
||||||
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue