Merge pull request #3780 from nichwall/api_cache_case_insensitive

API Cache Manager route uses case-insensitive match
This commit is contained in:
advplyr 2025-01-04 16:03:14 -06:00 committed by GitHub
commit f366dfa909
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 3 additions and 1 deletions

View File

@ -42,6 +42,8 @@ class ApiCacheManager {
Logger.debug(`[ApiCacheManager] Skipping cache for random sort`) Logger.debug(`[ApiCacheManager] Skipping cache for random sort`)
return next() return next()
} }
// Force URL to be lower case for matching against routes
req.url = req.url.toLowerCase()
const key = { user: req.user.username, url: req.url } const key = { user: req.user.username, url: req.url }
const stringifiedKey = JSON.stringify(key) const stringifiedKey = JSON.stringify(key)
Logger.debug(`[ApiCacheManager] count: ${this.cache.size} size: ${this.cache.calculatedSize}`) Logger.debug(`[ApiCacheManager] count: ${this.cache.size} size: ${this.cache.calculatedSize}`)

View File

@ -65,7 +65,7 @@ class ApiRouter {
// //
// Library Routes // Library Routes
// //
this.router.get(/^\/libraries/, this.apiCacheManager.middleware) this.router.get(/^\/libraries/i, this.apiCacheManager.middleware)
this.router.post('/libraries', LibraryController.create.bind(this)) this.router.post('/libraries', LibraryController.create.bind(this))
this.router.get('/libraries', LibraryController.findAll.bind(this)) this.router.get('/libraries', LibraryController.findAll.bind(this))
this.router.get('/libraries/:id', LibraryController.middleware.bind(this), LibraryController.findOne.bind(this)) this.router.get('/libraries/:id', LibraryController.middleware.bind(this), LibraryController.findOne.bind(this))