mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-04-11 01:17:50 +02:00
Update:Remove RSS feeds from login response payload and include feeds from library items request
This commit is contained in:
parent
8bbfee334c
commit
0e6b0d3eff
@ -260,7 +260,7 @@ export default {
|
|||||||
return this.bookCoverAspectRatio === 1
|
return this.bookCoverAspectRatio === 1
|
||||||
},
|
},
|
||||||
sizeMultiplier() {
|
sizeMultiplier() {
|
||||||
var baseSize = this.squareAspectRatio ? 192 : 120
|
const baseSize = this.squareAspectRatio ? 192 : 120
|
||||||
return this.width / baseSize
|
return this.width / baseSize
|
||||||
},
|
},
|
||||||
title() {
|
title() {
|
||||||
@ -538,11 +538,11 @@ export default {
|
|||||||
return this.author
|
return this.author
|
||||||
},
|
},
|
||||||
isAlternativeBookshelfView() {
|
isAlternativeBookshelfView() {
|
||||||
var constants = this.$constants || this.$nuxt.$constants
|
const constants = this.$constants || this.$nuxt.$constants
|
||||||
return this.bookshelfView === constants.BookshelfView.DETAIL
|
return this.bookshelfView === constants.BookshelfView.DETAIL
|
||||||
},
|
},
|
||||||
isAuthorBookshelfView() {
|
isAuthorBookshelfView() {
|
||||||
var constants = this.$constants || this.$nuxt.$constants
|
const constants = this.$constants || this.$nuxt.$constants
|
||||||
return this.bookshelfView === constants.BookshelfView.AUTHOR
|
return this.bookshelfView === constants.BookshelfView.AUTHOR
|
||||||
},
|
},
|
||||||
titleDisplayBottomOffset() {
|
titleDisplayBottomOffset() {
|
||||||
@ -552,7 +552,7 @@ export default {
|
|||||||
},
|
},
|
||||||
rssFeed() {
|
rssFeed() {
|
||||||
if (this.booksInSeries) return null
|
if (this.booksInSeries) return null
|
||||||
return this.store.getters['feeds/getFeedForItem'](this.libraryItemId)
|
return this._libraryItem.rssFeed || null
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
@ -330,10 +330,10 @@ export default {
|
|||||||
this.$store.commit('libraries/removeUserPlaylist', playlist)
|
this.$store.commit('libraries/removeUserPlaylist', playlist)
|
||||||
},
|
},
|
||||||
rssFeedOpen(data) {
|
rssFeedOpen(data) {
|
||||||
this.$store.commit('feeds/addFeed', data)
|
console.log('RSS Feed Open', data)
|
||||||
},
|
},
|
||||||
rssFeedClosed(data) {
|
rssFeedClosed(data) {
|
||||||
this.$store.commit('feeds/removeFeed', data)
|
console.log('RSS Feed Closed', data)
|
||||||
},
|
},
|
||||||
backupApplied() {
|
backupApplied() {
|
||||||
// Force refresh
|
// Force refresh
|
||||||
|
@ -127,7 +127,6 @@ export default {
|
|||||||
setUser({ user, userDefaultLibraryId, serverSettings, Source, feeds }) {
|
setUser({ user, userDefaultLibraryId, serverSettings, Source, feeds }) {
|
||||||
this.$store.commit('setServerSettings', serverSettings)
|
this.$store.commit('setServerSettings', serverSettings)
|
||||||
this.$store.commit('setSource', Source)
|
this.$store.commit('setSource', Source)
|
||||||
this.$store.commit('feeds/setFeeds', feeds)
|
|
||||||
this.$setServerLanguageCode(serverSettings.language)
|
this.$setServerLanguageCode(serverSettings.language)
|
||||||
|
|
||||||
if (serverSettings.chromecastEnabled) {
|
if (serverSettings.chromecastEnabled) {
|
||||||
|
@ -1,28 +0,0 @@
|
|||||||
|
|
||||||
export const state = () => ({
|
|
||||||
feeds: []
|
|
||||||
})
|
|
||||||
|
|
||||||
export const getters = {
|
|
||||||
getFeedForItem: state => id => {
|
|
||||||
return state.feeds.find(feed => feed.id === id)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const actions = {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
export const mutations = {
|
|
||||||
addFeed(state, feed) {
|
|
||||||
var index = state.feeds.findIndex(f => f.id === feed.id)
|
|
||||||
if (index >= 0) state.feeds.splice(index, 1, feed)
|
|
||||||
else state.feeds.push(feed)
|
|
||||||
},
|
|
||||||
removeFeed(state, feed) {
|
|
||||||
state.feeds = state.feeds.filter(f => f.id !== feed.id)
|
|
||||||
},
|
|
||||||
setFeeds(state, feeds) {
|
|
||||||
state.feeds = feeds || []
|
|
||||||
}
|
|
||||||
}
|
|
@ -115,17 +115,16 @@ class Auth {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
getUserLoginResponsePayload(user, feeds) {
|
getUserLoginResponsePayload(user) {
|
||||||
return {
|
return {
|
||||||
user: user.toJSONForBrowser(),
|
user: user.toJSONForBrowser(),
|
||||||
userDefaultLibraryId: user.getDefaultLibraryId(this.db.libraries),
|
userDefaultLibraryId: user.getDefaultLibraryId(this.db.libraries),
|
||||||
serverSettings: this.db.serverSettings.toJSONForBrowser(),
|
serverSettings: this.db.serverSettings.toJSONForBrowser(),
|
||||||
feeds,
|
|
||||||
Source: global.Source
|
Source: global.Source
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async login(req, res, feeds) {
|
async login(req, res) {
|
||||||
const ipAddress = requestIp.getClientIp(req)
|
const ipAddress = requestIp.getClientIp(req)
|
||||||
var username = (req.body.username || '').toLowerCase()
|
var username = (req.body.username || '').toLowerCase()
|
||||||
var password = req.body.password || ''
|
var password = req.body.password || ''
|
||||||
@ -146,14 +145,14 @@ class Auth {
|
|||||||
if (password) {
|
if (password) {
|
||||||
return res.status(401).send('Invalid root password (hint: there is none)')
|
return res.status(401).send('Invalid root password (hint: there is none)')
|
||||||
} else {
|
} else {
|
||||||
return res.json(this.getUserLoginResponsePayload(user, feeds))
|
return res.json(this.getUserLoginResponsePayload(user))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check password match
|
// Check password match
|
||||||
var compare = await bcrypt.compare(password, user.pash)
|
var compare = await bcrypt.compare(password, user.pash)
|
||||||
if (compare) {
|
if (compare) {
|
||||||
res.json(this.getUserLoginResponsePayload(user, feeds))
|
res.json(this.getUserLoginResponsePayload(user))
|
||||||
} else {
|
} else {
|
||||||
Logger.warn(`[Auth] Failed login attempt ${req.rateLimit.current} of ${req.rateLimit.limit} from ${ipAddress}`)
|
Logger.warn(`[Auth] Failed login attempt ${req.rateLimit.current} of ${req.rateLimit.limit} from ${ipAddress}`)
|
||||||
if (req.rateLimit.remaining <= 2) {
|
if (req.rateLimit.remaining <= 2) {
|
||||||
|
@ -212,7 +212,7 @@ class Server {
|
|||||||
]
|
]
|
||||||
dyanimicRoutes.forEach((route) => router.get(route, (req, res) => res.sendFile(Path.join(distPath, 'index.html'))))
|
dyanimicRoutes.forEach((route) => router.get(route, (req, res) => res.sendFile(Path.join(distPath, 'index.html'))))
|
||||||
|
|
||||||
router.post('/login', this.getLoginRateLimiter(), (req, res) => this.auth.login(req, res, this.rssFeedManager.feedsArray))
|
router.post('/login', this.getLoginRateLimiter(), (req, res) => this.auth.login(req, res))
|
||||||
router.post('/logout', this.authMiddleware.bind(this), this.logout.bind(this))
|
router.post('/logout', this.authMiddleware.bind(this), this.logout.bind(this))
|
||||||
router.post('/init', (req, res) => {
|
router.post('/init', (req, res) => {
|
||||||
if (this.db.hasRootUser) {
|
if (this.db.hasRootUser) {
|
||||||
|
@ -170,8 +170,11 @@ class LibraryController {
|
|||||||
// api/libraries/:id/items
|
// api/libraries/:id/items
|
||||||
// TODO: Optimize this method, items are iterated through several times but can be combined
|
// TODO: Optimize this method, items are iterated through several times but can be combined
|
||||||
getLibraryItems(req, res) {
|
getLibraryItems(req, res) {
|
||||||
var libraryItems = req.libraryItems
|
let libraryItems = req.libraryItems
|
||||||
var payload = {
|
|
||||||
|
const include = (req.query.include || '').split(',').map(v => v.trim().toLowerCase()).filter(v => !!v)
|
||||||
|
|
||||||
|
const payload = {
|
||||||
results: [],
|
results: [],
|
||||||
total: libraryItems.length,
|
total: libraryItems.length,
|
||||||
limit: req.query.limit && !isNaN(req.query.limit) ? Number(req.query.limit) : 0,
|
limit: req.query.limit && !isNaN(req.query.limit) ? Number(req.query.limit) : 0,
|
||||||
@ -181,7 +184,8 @@ class LibraryController {
|
|||||||
filterBy: req.query.filter,
|
filterBy: req.query.filter,
|
||||||
mediaType: req.library.mediaType,
|
mediaType: req.library.mediaType,
|
||||||
minified: req.query.minified === '1',
|
minified: req.query.minified === '1',
|
||||||
collapseseries: req.query.collapseseries === '1'
|
collapseseries: req.query.collapseseries === '1',
|
||||||
|
include: include.join(',')
|
||||||
}
|
}
|
||||||
const mediaIsBook = payload.mediaType === 'book'
|
const mediaIsBook = payload.mediaType === 'book'
|
||||||
|
|
||||||
@ -219,7 +223,7 @@ class LibraryController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Step 3 - Sort the retrieved library items.
|
// Step 3 - Sort the retrieved library items.
|
||||||
var sortArray = []
|
const sortArray = []
|
||||||
|
|
||||||
// When on the series page, sort by sequence only
|
// When on the series page, sort by sequence only
|
||||||
if (payload.sortBy === 'book.volumeNumber') payload.sortBy = null // TODO: Remove temp fix after mobile release 0.9.60
|
if (payload.sortBy === 'book.volumeNumber') payload.sortBy = null // TODO: Remove temp fix after mobile release 0.9.60
|
||||||
@ -294,13 +298,13 @@ class LibraryController {
|
|||||||
|
|
||||||
// Step 3.5: Limit items
|
// Step 3.5: Limit items
|
||||||
if (payload.limit) {
|
if (payload.limit) {
|
||||||
var startIndex = payload.page * payload.limit
|
const startIndex = payload.page * payload.limit
|
||||||
libraryItems = libraryItems.slice(startIndex, startIndex + payload.limit)
|
libraryItems = libraryItems.slice(startIndex, startIndex + payload.limit)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 4 - Transform the items to pass to the client side
|
// Step 4 - Transform the items to pass to the client side
|
||||||
payload.results = libraryItems.map(li => {
|
payload.results = libraryItems.map(li => {
|
||||||
let json = payload.minified ? li.toJSONMinified() : li.toJSON()
|
const json = payload.minified ? li.toJSONMinified() : li.toJSON()
|
||||||
|
|
||||||
if (li.collapsedSeries) {
|
if (li.collapsedSeries) {
|
||||||
json.collapsedSeries = {
|
json.collapsedSeries = {
|
||||||
@ -333,9 +337,16 @@ class LibraryController {
|
|||||||
.map(r => r.start == r.end ? r.start : `${r.start}-${r.end}`)
|
.map(r => r.start == r.end ? r.start : `${r.start}-${r.end}`)
|
||||||
.join(', ')
|
.join(', ')
|
||||||
}
|
}
|
||||||
} else if (filterSeries) {
|
} else {
|
||||||
// If filtering by series, make sure to include the series metadata
|
// add rssFeed object if "include=rssfeed" was put in query string (only for non-collapsed series)
|
||||||
json.media.metadata.series = li.media.metadata.getSeries(filterSeries)
|
if (include.includes('rssfeed')) {
|
||||||
|
json.rssFeed = this.rssFeedManager.findFeedForEntityId(json.id)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filterSeries) {
|
||||||
|
// If filtering by series, make sure to include the series metadata
|
||||||
|
json.media.metadata.series = li.media.metadata.getSeries(filterSeries)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return json
|
return json
|
||||||
|
@ -122,7 +122,7 @@ class MiscController {
|
|||||||
Logger.error('Invalid user in authorize')
|
Logger.error('Invalid user in authorize')
|
||||||
return res.sendStatus(401)
|
return res.sendStatus(401)
|
||||||
}
|
}
|
||||||
const userResponse = this.auth.getUserLoginResponsePayload(req.user, this.rssFeedManager.feedsArray)
|
const userResponse = this.auth.getUserLoginResponsePayload(req.user)
|
||||||
res.json(userResponse)
|
res.json(userResponse)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -291,11 +291,11 @@ module.exports = {
|
|||||||
collapseBookSeries(libraryItems, series, filterSeries) {
|
collapseBookSeries(libraryItems, series, filterSeries) {
|
||||||
// Get series from the library items. If this list is being collapsed after filtering for a series,
|
// Get series from the library items. If this list is being collapsed after filtering for a series,
|
||||||
// don't collapse that series, only books that are in other series.
|
// don't collapse that series, only books that are in other series.
|
||||||
var seriesObjects = this
|
const seriesObjects = this
|
||||||
.getSeriesFromBooks(libraryItems, series, filterSeries, null, null, true)
|
.getSeriesFromBooks(libraryItems, series, filterSeries, null, null, true)
|
||||||
.filter(s => s.id != filterSeries)
|
.filter(s => s.id != filterSeries)
|
||||||
|
|
||||||
var filteredLibraryItems = []
|
const filteredLibraryItems = []
|
||||||
|
|
||||||
libraryItems.forEach((li) => {
|
libraryItems.forEach((li) => {
|
||||||
if (li.mediaType != 'book') return
|
if (li.mediaType != 'book') return
|
||||||
@ -307,12 +307,12 @@ module.exports = {
|
|||||||
filteredLibraryItems.push(Object.assign(
|
filteredLibraryItems.push(Object.assign(
|
||||||
Object.create(Object.getPrototypeOf(li)),
|
Object.create(Object.getPrototypeOf(li)),
|
||||||
li, { collapsedSeries: series }))
|
li, { collapsedSeries: series }))
|
||||||
});
|
})
|
||||||
|
|
||||||
// Only included books not contained in series
|
// Only included books not contained in series
|
||||||
if (!seriesObjects.some(s => s.books.some(b => b.id == li.id)))
|
if (!seriesObjects.some(s => s.books.some(b => b.id == li.id)))
|
||||||
filteredLibraryItems.push(li)
|
filteredLibraryItems.push(li)
|
||||||
});
|
})
|
||||||
|
|
||||||
return filteredLibraryItems
|
return filteredLibraryItems
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user