mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-06-05 06:34:14 -04:00
Fix:Set correct mime type for m4b file static requests
This commit is contained in:
parent
6cbfd8679b
commit
976427b0b3
@ -1,5 +1,8 @@
|
|||||||
|
const { AudioMimeType } = require('../utils/constants')
|
||||||
|
const { getAudioMimeTypeFromExtname } = require('../utils/fileUtils')
|
||||||
const DEFAULT_EXPIRATION = 1000 * 60 * 60 // 60 minutes
|
const DEFAULT_EXPIRATION = 1000 * 60 * 60 // 60 minutes
|
||||||
const DEFAULT_TIMEOUT = 1000 * 60 * 30 // 30 minutes
|
const DEFAULT_TIMEOUT = 1000 * 60 * 30 // 30 minutes
|
||||||
|
|
||||||
class Download {
|
class Download {
|
||||||
constructor(download) {
|
constructor(download) {
|
||||||
this.id = null
|
this.id = null
|
||||||
@ -32,16 +35,7 @@ class Download {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get mimeType() {
|
get mimeType() {
|
||||||
if (this.ext === '.mp3' || this.ext === '.m4b' || this.ext === '.m4a') {
|
return getAudioMimeTypeFromExtname(this.ext) || AudioMimeType.MP3
|
||||||
return 'audio/mpeg'
|
|
||||||
} else if (this.ext === '.mp4') {
|
|
||||||
return 'audio/mp4'
|
|
||||||
} else if (this.ext === '.ogg') {
|
|
||||||
return 'audio/ogg'
|
|
||||||
} else if (this.ext === '.aac' || this.ext === '.m4p') {
|
|
||||||
return 'audio/aac'
|
|
||||||
}
|
|
||||||
return 'audio/mpeg'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
toJSON() {
|
toJSON() {
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
const { isNullOrNaN } = require('../../utils/index')
|
|
||||||
const { AudioMimeType } = require('../../utils/constants')
|
const { AudioMimeType } = require('../../utils/constants')
|
||||||
const AudioMetaTags = require('../metadata/AudioMetaTags')
|
const AudioMetaTags = require('../metadata/AudioMetaTags')
|
||||||
const FileMetadata = require('../metadata/FileMetadata')
|
const FileMetadata = require('../metadata/FileMetadata')
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
const express = require('express')
|
const express = require('express')
|
||||||
const Path = require('path')
|
const Path = require('path')
|
||||||
const Logger = require('../Logger')
|
const { getAudioMimeTypeFromExtname } = require('../utils/fileUtils')
|
||||||
|
|
||||||
class StaticRouter {
|
class StaticRouter {
|
||||||
constructor(db) {
|
constructor(db) {
|
||||||
@ -20,7 +20,16 @@ class StaticRouter {
|
|||||||
var fullPath = null
|
var fullPath = null
|
||||||
if (item.isFile) fullPath = item.path
|
if (item.isFile) fullPath = item.path
|
||||||
else fullPath = Path.join(item.path, remainingPath)
|
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)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ const rra = require('../libs/recursiveReaddirAsync')
|
|||||||
const axios = require('axios')
|
const axios = require('axios')
|
||||||
const Path = require('path')
|
const Path = require('path')
|
||||||
const Logger = require('../Logger')
|
const Logger = require('../Logger')
|
||||||
|
const { AudioMimeType } = require('./constants')
|
||||||
|
|
||||||
async function getFileStat(path) {
|
async function getFileStat(path) {
|
||||||
try {
|
try {
|
||||||
@ -211,3 +212,11 @@ module.exports.sanitizeFilename = (filename, colonReplacement = ' - ') => {
|
|||||||
|
|
||||||
return sanitized
|
return sanitized
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns null if extname is not in our defined list of audio extnames
|
||||||
|
module.exports.getAudioMimeTypeFromExtname = (extname) => {
|
||||||
|
if (!extname || !extname.length) return null
|
||||||
|
const formatUpper = extname.slice(1).toUpperCase()
|
||||||
|
if (AudioMimeType[formatUpper]) return AudioMimeType[formatUpper]
|
||||||
|
return null
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user