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