Move /connect to /api/connect
This commit is contained in:
parent
a752a63e0e
commit
554dfcced7
50
server/src/routes/api/get/connect.ts
Normal file
50
server/src/routes/api/get/connect.ts
Normal 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
|
@ -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,
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user