path
parent
6f6942ba15
commit
ec489da56b
|
@ -56,29 +56,6 @@ module.exports = {
|
|||
error: e.message
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
list: async function (req, res) {
|
||||
try {
|
||||
const body = req.allParams()
|
||||
let page = 1
|
||||
const perPage = 200
|
||||
if (body.page) {
|
||||
page = Math.abs(+body.page) || 1
|
||||
delete body.page
|
||||
}
|
||||
const books = await Book.find(body || {}).skip((page * perPage) - perPage).limit(perPage)
|
||||
|
||||
if (!books.length) {
|
||||
throw new HttpError(404, 'No books matching those parameters were found.')
|
||||
}
|
||||
return res.json(books)
|
||||
} catch (e) {
|
||||
if (e instanceof HttpError) return e.send(res)
|
||||
return res.status(500).json({
|
||||
error: e.message
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ module.exports = {
|
|||
'type': 'application/opds+json',
|
||||
'rel': 'current'
|
||||
},
|
||||
{ 'rel': 'search', 'href': '/api/catalog/search{?title,author,isbn}', 'type': 'application/opds+json', 'templated': true }
|
||||
{ 'rel': 'search', 'href': 'search{?title,author,isbn}', 'type': 'application/opds+json', 'templated': true }
|
||||
]
|
||||
})
|
||||
},
|
||||
|
|
|
@ -73,7 +73,6 @@ module.exports.routes = {
|
|||
'GET /auth/:provider/:action': 'AuthController.callback',
|
||||
|
||||
'POST /api/publish': 'BooksController.publish',
|
||||
'GET /api/books': 'BooksController.list',
|
||||
|
||||
'GET /api/catalog': 'CatalogController.navigation',
|
||||
'GET /api/catalog/new': 'CatalogController.listNew',
|
||||
|
|
Loading…
Reference in New Issue