Move /connect to /api/connect

This commit is contained in:
RemixDev 2022-07-29 20:05:27 +02:00
parent a752a63e0e
commit 554dfcced7
No known key found for this signature in database
GPG Key ID: B33962B465BDB51C
3 changed files with 52 additions and 44 deletions

View File

@ -0,0 +1,50 @@
// @ts-expect-error
import { Deezer } from 'deezer-js'
import { ApiHandler } from '../../../types'
import { logger } from '../../../helpers/logger'
import { getLoginCredentials } from '../../../helpers/loginStorage'
import { sessionDZ, deemixVersion, currentVersion } from '../../../app'
const path: ApiHandler['path'] = '/connect'
let update: any = null
const handler: ApiHandler['handler'] = async (req, res) => {
if (!sessionDZ[req.session.id]) sessionDZ[req.session.id] = new Deezer()
const dz = sessionDZ[req.session.id]
const deemix = req.app.get('deemix')
const isSingleUser = req.app.get('isSingleUser')
if (!update) {
logger.info(`Currently running deemix-gui version ${currentVersion}`)
logger.info(`deemix-lib version ${deemixVersion}`)
update = {
currentCommit: currentVersion,
deemixVersion
}
}
const result: any = {
update,
autologin: !dz.logged_in,
currentUser: dz.current_user,
deezerAvailable: await deemix.isDeezerAvailable(),
spotifyEnabled: deemix.plugins.spotify.enabled,
settingsData: deemix.getSettings()
}
if (isSingleUser && result.autologin) result.singleUser = getLoginCredentials()
if (result.settingsData.settings.autoCheckForUpdates) result.checkForUpdates = true
const queue = deemix.getQueue()
if (Object.keys(queue.queue).length > 0) {
result.queue = queue
}
res.send(result)
}
const apiHandler: ApiHandler = { path, handler }
export default apiHandler

View File

@ -1,3 +1,4 @@
import connect from './connect'
import analyzeLink from './analyzeLink'
import getHome from './getHome'
import getCharts from './getCharts'
@ -19,6 +20,7 @@ import spotifyStatus from './spotifyStatus'
import checkForUpdates from './checkForUpdates'
export default [
connect,
albumSearch,
analyzeLink,
getHome,

View File

@ -1,48 +1,4 @@
import express from 'express'
// @ts-expect-error
import { Deezer } from 'deezer-js'
import { logger } from '../helpers/logger'
import { getLoginCredentials } from '../helpers/loginStorage'
import { sessionDZ, deemixVersion, currentVersion } from '../app'
const router = express.Router()
let update: any = null
router.get('/connect', async (req, res) => {
if (!sessionDZ[req.session.id]) sessionDZ[req.session.id] = new Deezer()
const dz = sessionDZ[req.session.id]
const deemix = req.app.get('deemix')
const isSingleUser = req.app.get('isSingleUser')
if (!update) {
logger.info(`Currently running deemix-gui version ${currentVersion}`)
logger.info(`deemix-lib version ${deemixVersion}`)
update = {
currentCommit: currentVersion,
deemixVersion
}
}
const result: any = {
update,
autologin: !dz.logged_in,
currentUser: dz.current_user,
deezerAvailable: await deemix.isDeezerAvailable(),
spotifyEnabled: deemix.plugins.spotify.enabled,
settingsData: deemix.getSettings()
}
if (isSingleUser && result.autologin) result.singleUser = getLoginCredentials()
if (result.settingsData.settings.autoCheckForUpdates) result.checkForUpdates = true
const queue = deemix.getQueue()
if (Object.keys(queue.queue).length > 0) {
result.queue = queue
}
res.send(result)
})
export default router