mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-08-09 04:39:12 +02:00
New api routes, updating web client pages, audiobooks to libraryItem migration
This commit is contained in:
parent
b97ed953f7
commit
2a30cc428f
51 changed files with 1225 additions and 654 deletions
37
server/controllers/LibraryItemController.js
Normal file
37
server/controllers/LibraryItemController.js
Normal file
|
@ -0,0 +1,37 @@
|
|||
const Logger = require('../Logger')
|
||||
const { reqSupportsWebp } = require('../utils/index')
|
||||
|
||||
class LibraryItemController {
|
||||
constructor() { }
|
||||
|
||||
findOne(req, res) {
|
||||
if (req.query.expanded == 1) return res.json(req.libraryItem.toJSONExpanded())
|
||||
res.json(req.libraryItem)
|
||||
}
|
||||
|
||||
// GET api/items/:id/cover
|
||||
async getCover(req, res) {
|
||||
let { query: { width, height, format }, libraryItem } = req
|
||||
|
||||
const options = {
|
||||
format: format || (reqSupportsWebp(req) ? 'webp' : 'jpeg'),
|
||||
height: height ? parseInt(height) : null,
|
||||
width: width ? parseInt(width) : null
|
||||
}
|
||||
return this.cacheManager.handleCoverCache(res, libraryItem, options)
|
||||
}
|
||||
|
||||
middleware(req, res, next) {
|
||||
var item = this.db.libraryItems.find(li => li.id === req.params.id)
|
||||
if (!item || !item.media || !item.media.coverPath) return res.sendStatus(404)
|
||||
|
||||
// Check user can access this audiobooks library
|
||||
if (!req.user.checkCanAccessLibrary(item.libraryId)) {
|
||||
return res.sendStatus(403)
|
||||
}
|
||||
|
||||
req.libraryItem = item
|
||||
next()
|
||||
}
|
||||
}
|
||||
module.exports = new LibraryItemController()
|
Loading…
Add table
Add a link
Reference in a new issue