mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-07-27 03:31:46 +00:00
Add /me/sessions endpoint and show sessions table on account page
This commit is contained in:
parent
4c71a076e7
commit
35a2c5e87c
5 changed files with 130 additions and 1 deletions
28
server/utils/parsers/parseUserAgent.js
Normal file
28
server/utils/parsers/parseUserAgent.js
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
const uaParserJs = require('../../libs/uaParser')
|
||||
|
||||
/**
|
||||
* @param {string|null|undefined} userAgent
|
||||
* @returns {{ browserName?:string, browserVersion?:string, osName?:string, osVersion?:string, deviceType?:string, model?:string, vendor?:string }|null}
|
||||
*/
|
||||
function parseUserAgent(userAgent) {
|
||||
if (!userAgent) return null
|
||||
|
||||
const ua = uaParserJs(userAgent)
|
||||
const deviceInfo = {
|
||||
browserName: ua?.browser?.name || undefined,
|
||||
browserVersion: ua?.browser?.version || undefined,
|
||||
osName: ua?.os?.name || undefined,
|
||||
osVersion: ua?.os?.version || undefined,
|
||||
deviceType: ua?.device?.type || undefined,
|
||||
model: ua?.device?.model || undefined,
|
||||
vendor: ua?.device?.vendor || undefined
|
||||
}
|
||||
|
||||
for (const key in deviceInfo) {
|
||||
if (deviceInfo[key] === undefined) delete deviceInfo[key]
|
||||
}
|
||||
|
||||
return Object.keys(deviceInfo).length ? deviceInfo : null
|
||||
}
|
||||
|
||||
module.exports = parseUserAgent
|
||||
Loading…
Add table
Add a link
Reference in a new issue