Improve wav audio file support

This commit is contained in:
Pavel Djundik 2020-02-26 10:07:40 +02:00
parent e20b1a55c3
commit 63fd0def6c
2 changed files with 8 additions and 1 deletions

View file

@ -221,6 +221,7 @@ function parse(msg, chan, preview, res, client) {
case "audio/mpeg3":
case "audio/ogg":
case "audio/wav":
case "audio/x-wav":
case "audio/x-mid":
case "audio/x-midi":
case "audio/x-mpeg":

View file

@ -66,7 +66,7 @@ class Uploader {
const folder = name.substring(0, 2);
const uploadPath = Helper.getFileUploadPath();
const filePath = path.join(uploadPath, folder, name);
const detectedMimeType = await Uploader.getFileType(filePath);
let detectedMimeType = await Uploader.getFileType(filePath);
// doesn't exist
if (detectedMimeType === null) {
@ -76,6 +76,12 @@ class Uploader {
// Force a download in the browser if it's not a whitelisted type (binary or otherwise unknown)
const contentDisposition = Uploader.isValidType(detectedMimeType) ? "inline" : "attachment";
if (detectedMimeType === "audio/vnd.wave") {
// Send a more common mime type for wave audio files
// so that browsers can play them correctly
detectedMimeType = "audio/wav";
}
res.setHeader("Content-Disposition", contentDisposition);
res.setHeader("Cache-Control", "max-age=86400");
res.contentType(detectedMimeType);