Fix:Set correct mime type for m4b file static requests

This commit is contained in:
advplyr 2022-07-24 13:32:05 -05:00
parent 6cbfd8679b
commit 976427b0b3
4 changed files with 24 additions and 13 deletions

View file

@ -1,6 +1,6 @@
const express = require('express')
const Path = require('path')
const Logger = require('../Logger')
const { getAudioMimeTypeFromExtname } = require('../utils/fileUtils')
class StaticRouter {
constructor(db) {
@ -20,7 +20,16 @@ class StaticRouter {
var fullPath = null
if (item.isFile) fullPath = item.path
else fullPath = Path.join(item.path, remainingPath)
res.sendFile(fullPath)
var opts = {}
// Express does not set the correct mimetype for m4b files so use our defined mimetypes if available
const audioMimeType = getAudioMimeTypeFromExtname(Path.extname(fullPath))
if (audioMimeType) {
opts = { headers: { 'Content-Type': audioMimeType } }
}
res.sendFile(fullPath, opts)
})
}
}