Made POST requests actual post requests
This commit is contained in:
parent
62cb39f154
commit
bb6e4bec0d
@ -1,5 +1,4 @@
|
||||
import analyzeLink from './analyzeLink'
|
||||
import changeAccount from './changeAccount'
|
||||
import getHome from './getHome'
|
||||
import getCharts from './getCharts'
|
||||
import mainSearch from './mainSearch'
|
||||
@ -20,7 +19,6 @@ import spotifyStatus from './spotifyStatus'
|
||||
|
||||
export default [
|
||||
albumSearch,
|
||||
changeAccount,
|
||||
analyzeLink,
|
||||
getHome,
|
||||
getCharts,
|
||||
|
@ -9,8 +9,8 @@ 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 url = req.query.url.split(/[\s;]+/)
|
||||
let bitrate = req.query.bitrate
|
||||
const url = req.body.url.split(/[\s;]+/)
|
||||
let bitrate = req.body.bitrate
|
||||
if (bitrate === 'null') bitrate = getSettings().settings.maxBitrate
|
||||
let obj: any
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
import loginArl from './login-arl'
|
||||
import changeAccount from './changeAccount'
|
||||
import loginArl from './loginArl'
|
||||
import addToQueue from './addToQueue'
|
||||
import loginWithCredentials from './loginWithCredentials'
|
||||
import loginEmail from './loginEmail'
|
||||
import cancelAllDownloads from './cancelAllDownloads'
|
||||
import removeFinishedDownloads from './removeFinishedDownloads'
|
||||
import removeFromQueue from './removeFromQueue'
|
||||
@ -8,9 +9,10 @@ import logout from './logout'
|
||||
import saveSettings from './saveSettings'
|
||||
|
||||
export default [
|
||||
changeAccount,
|
||||
loginArl,
|
||||
addToQueue,
|
||||
loginWithCredentials,
|
||||
loginEmail,
|
||||
cancelAllDownloads,
|
||||
removeFinishedDownloads,
|
||||
removeFromQueue,
|
||||
|
@ -1,9 +1,9 @@
|
||||
import { appSendPost } from '../../../../tests/utils'
|
||||
|
||||
describe('login-arl requests', () => {
|
||||
describe('loginArl requests', () => {
|
||||
it('should respond 200 to calls with arl', async () => {
|
||||
const responseStatusCollector: number[] = []
|
||||
const batchCalls = ['/api/login-arl/?arl=abcdef1234']
|
||||
const batchCalls = ['/api/loginArl/?arl=abcdef1234']
|
||||
|
||||
for (const uri of batchCalls) {
|
||||
responseStatusCollector.push((await appSendPost(uri)).status)
|
||||
@ -15,7 +15,7 @@ describe('login-arl requests', () => {
|
||||
|
||||
it('should respond 400 to calls without arl', async () => {
|
||||
const responseStatusCollector: number[] = []
|
||||
const batchCalls = ['/api/login-arl/', '/api/login-arl/?dummy=test', '/api/login-arl/?email=aaa@aa.com']
|
||||
const batchCalls = ['/api/loginArl/', '/api/loginArl/?dummy=test', '/api/loginArl/?email=aaa@aa.com']
|
||||
|
||||
for (const uri of batchCalls) {
|
||||
responseStatusCollector.push((await appSendPost(uri)).status)
|
||||
@ -25,14 +25,14 @@ describe('login-arl requests', () => {
|
||||
})
|
||||
|
||||
it('should login using ARL', async () => {
|
||||
const response = await appSendPost(`/api/login-arl/?arl=${process.env.DEEZER_ARL}`)
|
||||
const response = await appSendPost(`/api/loginArl/?arl=${process.env.DEEZER_ARL}`)
|
||||
|
||||
expect(response.status).toBe(200)
|
||||
expect(response.body.status).toBe(true)
|
||||
})
|
||||
|
||||
it('should not login using wrong ARL', async () => {
|
||||
const response = await appSendPost(`/api/login-arl/?arl=abcdef1234`)
|
||||
const response = await appSendPost(`/api/loginArl/?arl=abcdef1234`)
|
||||
|
||||
expect(response.status).toBe(200)
|
||||
expect(response.body.status).toBe(false)
|
@ -4,7 +4,7 @@ import { Deezer } from 'deezer-js'
|
||||
import { sessionDZ, startQueue, isDeezerAvailable } from '../../../main'
|
||||
import { ApiHandler } from '../../../types'
|
||||
|
||||
export interface RawLoginArlQuery {
|
||||
export interface RawLoginArlBody {
|
||||
arl: string
|
||||
child?: number
|
||||
}
|
||||
@ -17,26 +17,26 @@ const LoginStatus = {
|
||||
FORCED_SUCCESS: 3
|
||||
}
|
||||
|
||||
const path: ApiHandler['path'] = '/login-arl'
|
||||
const path: ApiHandler['path'] = '/loginArl'
|
||||
|
||||
const handler: RequestHandler<{}, {}, {}, RawLoginArlQuery> = async (req, res, _) => {
|
||||
const handler: RequestHandler<{}, {}, RawLoginArlBody, {}> = async (req, res, _) => {
|
||||
if (!sessionDZ[req.session.id]) sessionDZ[req.session.id] = new Deezer()
|
||||
const dz = sessionDZ[req.session.id]
|
||||
|
||||
if (!req.query) {
|
||||
if (!req.body) {
|
||||
return res.status(400).send()
|
||||
}
|
||||
|
||||
if (!req.query.arl) {
|
||||
if (!req.body.arl) {
|
||||
return res.status(400).send()
|
||||
}
|
||||
|
||||
const loginParams: (string | number)[] = [req.query.arl]
|
||||
const loginParams: (string | number)[] = [req.body.arl]
|
||||
|
||||
// TODO Handle the child === 0 case, don't want to rely on the login_via_arl default param (it may change in the
|
||||
// future)
|
||||
if (req.query.child) {
|
||||
loginParams.push(req.query.child)
|
||||
if (req.body.child) {
|
||||
loginParams.push(req.body.child)
|
||||
}
|
||||
|
||||
let response
|
||||
@ -61,7 +61,7 @@ const handler: RequestHandler<{}, {}, {}, RawLoginArlQuery> = async (req, res, _
|
||||
if (!(await isDeezerAvailable())) response = LoginStatus.NOT_AVAILABLE
|
||||
const returnValue = {
|
||||
status: response,
|
||||
arl: req.query.arl,
|
||||
arl: req.body.arl,
|
||||
user: dz.current_user,
|
||||
childs: dz.childs,
|
||||
currentChild: dz.selected_account
|
@ -1,7 +1,7 @@
|
||||
import { ApiHandler } from '../../../types'
|
||||
import { getAccessToken, getArlFromAccessToken } from '../../../main'
|
||||
|
||||
const path = '/loginWithCredentials'
|
||||
const path = '/loginEmail'
|
||||
|
||||
const handler: ApiHandler['handler'] = async (req, res) => {
|
||||
const { email, password } = req.body
|
Loading…
Reference in New Issue
Block a user