Clean up ApiRouter adding MiscController, move upload and scan to api endpoints

This commit is contained in:
advplyr 2022-03-18 11:51:55 -05:00
parent 69fcb103e4
commit 57399bb79e
14 changed files with 299 additions and 270 deletions

View file

@ -1,5 +1,6 @@
const Logger = require('../Logger')
const { reqSupportsWebp } = require('../utils/index')
const { ScanResult } = require('../utils/constants')
class LibraryItemController {
constructor() { }
@ -239,6 +240,18 @@ class LibraryItemController {
else res.sendStatus(500)
}
// GET: api/items/:id/scan (Root)
async scan(req, res) {
if (!req.user.isRoot) {
Logger.error(`[LibraryItemController] Non-root user attempted to scan library item`, req.user)
return res.sendStatus(403)
}
var result = await this.scanner.scanLibraryItemById(req.libraryItem.id)
res.json({
result: Object.keys(ScanResult).find(key => ScanResult[key] == result)
})
}
middleware(req, res, next) {
var item = this.db.libraryItems.find(li => li.id === req.params.id)