Add:RSS feed icon over library item covers when feed is open #893

This commit is contained in:
advplyr 2022-08-05 19:23:18 -05:00
parent 2cb4f972d7
commit 24a142e718
9 changed files with 59 additions and 21 deletions

View file

@ -114,16 +114,17 @@ class Auth {
})
}
getUserLoginResponsePayload(user) {
getUserLoginResponsePayload(user, feeds) {
return {
user: user.toJSONForBrowser(),
userDefaultLibraryId: user.getDefaultLibraryId(this.db.libraries),
serverSettings: this.db.serverSettings.toJSONForBrowser(),
feeds,
Source: global.Source
}
}
async login(req, res) {
async login(req, res, feeds) {
var username = (req.body.username || '').toLowerCase()
var password = req.body.password || ''
@ -142,14 +143,14 @@ class Auth {
if (password) {
return res.status(401).send('Invalid root password (hint: there is none)')
} else {
return res.json(this.getUserLoginResponsePayload(user))
return res.json(this.getUserLoginResponsePayload(user, feeds))
}
}
// Check password match
var compare = await bcrypt.compare(password, user.pash)
if (compare) {
res.json(this.getUserLoginResponsePayload(user))
res.json(this.getUserLoginResponsePayload(user, feeds))
} else {
Logger.debug(`[Auth] Failed login attempt ${req.rateLimit.current} of ${req.rateLimit.limit}`)
if (req.rateLimit.remaining <= 2) {

View file

@ -10,6 +10,7 @@ const Author = require('./objects/entities/Author')
const Series = require('./objects/entities/Series')
const ServerSettings = require('./objects/settings/ServerSettings')
const PlaybackSession = require('./objects/PlaybackSession')
const Feed = require('./objects/Feed')
class Db {
constructor() {

View file

@ -230,7 +230,7 @@ class Server {
]
dyanimicRoutes.forEach((route) => app.get(route, (req, res) => res.sendFile(Path.join(distPath, 'index.html'))))
app.post('/login', this.getLoginRateLimiter(), (req, res) => this.auth.login(req, res))
app.post('/login', this.getLoginRateLimiter(), (req, res) => this.auth.login(req, res, this.rssFeedManager.feedsArray))
app.post('/logout', this.authMiddleware.bind(this), this.logout.bind(this))
app.post('/init', (req, res) => {
if (this.db.hasRootUser) {

View file

@ -239,12 +239,7 @@ class MiscController {
Logger.error('Invalid user in authorize')
return res.sendStatus(401)
}
const userResponse = {
user: req.user,
userDefaultLibraryId: req.user.getDefaultLibraryId(this.db.libraries),
serverSettings: this.db.serverSettings.toJSONForBrowser(),
Source: global.Source
}
const userResponse = this.auth.getUserLoginResponsePayload(req.user, this.rssFeedManager.feedsArray)
res.json(userResponse)
}

View file

@ -11,6 +11,10 @@ class RssFeedManager {
this.feeds = {}
}
get feedsArray() {
return Object.values(this.feeds)
}
async init() {
var feedObjects = await this.db.getAllEntities('feed')
if (feedObjects && feedObjects.length) {
@ -91,7 +95,7 @@ class RssFeedManager {
Logger.debug(`[RssFeedManager] Opened RSS feed ${feed.feedUrl}`)
await this.db.insertEntity('feed', feed)
this.emitter('rss_feed_open', { entityType: feed.entityType, entityId: feed.entityId, feedUrl: feed.feedUrl })
this.emitter('rss_feed_open', { id: feed.id, entityType: feed.entityType, entityId: feed.entityId, feedUrl: feed.feedUrl })
return feed
}
@ -105,7 +109,7 @@ class RssFeedManager {
if (!this.feeds[id]) return
var feed = this.feeds[id]
await this.db.removeEntity('feed', id)
this.emitter('rss_feed_closed', { entityType: feed.entityType, entityId: feed.entityId, feedUrl: feed.feedUrl })
this.emitter('rss_feed_closed', { id: feed.id, entityType: feed.entityType, entityId: feed.entityId, feedUrl: feed.feedUrl })
delete this.feeds[id]
Logger.info(`[RssFeedManager] Closed RSS feed "${feed.feedUrl}"`)
}