mirror of
				https://github.com/advplyr/audiobookshelf.git
				synced 2025-11-03 19:07:00 -05:00 
			
		
		
		
	
		
			
				
	
	
		
			27 lines
		
	
	
		
			714 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			27 lines
		
	
	
		
			714 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
const express = require('express')
 | 
						|
const Path = require('path')
 | 
						|
const Logger = require('../Logger')
 | 
						|
 | 
						|
class StaticRouter {
 | 
						|
  constructor(db) {
 | 
						|
    this.db = db
 | 
						|
 | 
						|
    this.router = express()
 | 
						|
    this.init()
 | 
						|
  }
 | 
						|
 | 
						|
  init() {
 | 
						|
    // Library Item static file routes
 | 
						|
    this.router.get('/item/:id/*', (req, res) => {
 | 
						|
      var item = this.db.libraryItems.find(ab => ab.id === req.params.id)
 | 
						|
      if (!item) return res.status(404).send('Item not found with id ' + req.params.id)
 | 
						|
 | 
						|
      var remainingPath = req.params['0']
 | 
						|
      var fullPath = null
 | 
						|
      if (item.isFile) fullPath = item.path
 | 
						|
      else fullPath = Path.join(item.path, remainingPath)
 | 
						|
      res.sendFile(fullPath)
 | 
						|
    })
 | 
						|
  }
 | 
						|
}
 | 
						|
module.exports = StaticRouter |