Merge pull request #3781 from thelounge/xpaw/wave

Improve wav audio detection
This commit is contained in:
Richard Lewis 2020-02-26 23:19:12 +02:00 committed by GitHub
commit abd414beb9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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/mpeg3":
case "audio/ogg": case "audio/ogg":
case "audio/wav": case "audio/wav":
case "audio/x-wav":
case "audio/x-mid": case "audio/x-mid":
case "audio/x-midi": case "audio/x-midi":
case "audio/x-mpeg": case "audio/x-mpeg":

View File

@ -66,7 +66,7 @@ class Uploader {
const folder = name.substring(0, 2); const folder = name.substring(0, 2);
const uploadPath = Helper.getFileUploadPath(); const uploadPath = Helper.getFileUploadPath();
const filePath = path.join(uploadPath, folder, name); const filePath = path.join(uploadPath, folder, name);
const detectedMimeType = await Uploader.getFileType(filePath); let detectedMimeType = await Uploader.getFileType(filePath);
// doesn't exist // doesn't exist
if (detectedMimeType === null) { 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) // Force a download in the browser if it's not a whitelisted type (binary or otherwise unknown)
const contentDisposition = Uploader.isValidType(detectedMimeType) ? "inline" : "attachment"; 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("Content-Disposition", contentDisposition);
res.setHeader("Cache-Control", "max-age=86400"); res.setHeader("Cache-Control", "max-age=86400");
res.contentType(detectedMimeType); res.contentType(detectedMimeType);