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({
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let allowedMimeTypes = [
|
||||||
|
'image/png',
|
||||||
|
'image/jpg',
|
||||||
|
'image/jpeg',
|
||||||
|
'image/gif',
|
||||||
|
'image/webp',
|
||||||
|
'video/mp4',
|
||||||
|
'video/mov',
|
||||||
|
'video/webm',
|
||||||
|
'audio/mpeg',
|
||||||
|
'audio/ogg'
|
||||||
|
]
|
||||||
|
|
||||||
const fileFilter = function(req, file, cb) {
|
const fileFilter = function(req, file, cb) {
|
||||||
if (file.mimetype == "image/png" || file.mimetype == "image/jpg" || file.mimetype == "image/jpeg" || file.mimetype == "image/gif" || file.mimetype == "image/webp"
|
if (allowedMimeTypes.includes(file.mimetype)) {
|
||||||
|| file.mimetype == "video/mp4" || file.mimetype == "video/mov" || file.mimetype == "video/webm"
|
cb(null, true);
|
||||||
|| file.mimetype == "audio/mpeg" || file.mimetype == "audio/ogg") {
|
|
||||||
cb(null, true)
|
|
||||||
} else {
|
} else {
|
||||||
cb(null, false);
|
cb(null, false);
|
||||||
//return cb(new Error('Only media files allowed'));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let upload = multer({ storage: storage, fileFilter: fileFilter });
|
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) => {
|
||||||
|
|
|
@ -46,8 +46,12 @@ function extension(string) {
|
||||||
<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 -->
|
||||||
|
<div class="nonmedia" onclick="copyURI(event)">
|
||||||
|
<p><%=extension(file.path)%> file</p>
|
||||||
|
</div>
|
||||||
<% } %>
|
<% } %>
|
||||||
<label text-align:"center"><%= file.path %></label>
|
<label text-align:"center"><%= file.path %></label>
|
||||||
<button class="destroy" form="delete-<%= file.path %>"></button>
|
<button class="destroy" form="delete-<%= file.path %>"></button>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue