mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-08-04 10:14:36 +02:00
Merge pull request #1431 from lkiesow/x-accel
Implement X-Accel Redirect
This commit is contained in:
commit
9ebe4b55dd
4 changed files with 26 additions and 5 deletions
|
@ -51,6 +51,11 @@ class CacheManager {
|
|||
|
||||
// Cache exists
|
||||
if (await fs.pathExists(path)) {
|
||||
if (global.XAccel) {
|
||||
Logger.debug(`Use X-Accel to serve static file ${path}`)
|
||||
return res.status(204).header({'X-Accel-Redirect': global.XAccel + path}).send()
|
||||
}
|
||||
|
||||
const r = fs.createReadStream(path)
|
||||
const ps = new stream.PassThrough()
|
||||
stream.pipeline(r, ps, (err) => {
|
||||
|
@ -72,6 +77,11 @@ class CacheManager {
|
|||
// Set owner and permissions of cache image
|
||||
await filePerms.setDefault(path)
|
||||
|
||||
if (global.XAccel) {
|
||||
Logger.debug(`Use X-Accel to serve static file ${writtenFile}`)
|
||||
return res.status(204).header({'X-Accel-Redirect': global.XAccel + writtenFile}).send()
|
||||
}
|
||||
|
||||
var readStream = fs.createReadStream(writtenFile)
|
||||
readStream.pipe(res)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue