Made POST requests actual post requests

This commit is contained in:
RemixDev 2022-01-13 01:27:08 +01:00
parent 62cb39f154
commit bb6e4bec0d
8 changed files with 22 additions and 22 deletions

View File

@ -1,5 +1,4 @@
import analyzeLink from './analyzeLink' import analyzeLink from './analyzeLink'
import changeAccount from './changeAccount'
import getHome from './getHome' import getHome from './getHome'
import getCharts from './getCharts' import getCharts from './getCharts'
import mainSearch from './mainSearch' import mainSearch from './mainSearch'
@ -20,7 +19,6 @@ import spotifyStatus from './spotifyStatus'
export default [ export default [
albumSearch, albumSearch,
changeAccount,
analyzeLink, analyzeLink,
getHome, getHome,
getCharts, getCharts,

View File

@ -9,8 +9,8 @@ const handler: ApiHandler['handler'] = async (req, res) => {
if (!sessionDZ[req.session.id]) sessionDZ[req.session.id] = new Deezer() if (!sessionDZ[req.session.id]) sessionDZ[req.session.id] = new Deezer()
const dz = sessionDZ[req.session.id] const dz = sessionDZ[req.session.id]
const url = req.query.url.split(/[\s;]+/) const url = req.body.url.split(/[\s;]+/)
let bitrate = req.query.bitrate let bitrate = req.body.bitrate
if (bitrate === 'null') bitrate = getSettings().settings.maxBitrate if (bitrate === 'null') bitrate = getSettings().settings.maxBitrate
let obj: any let obj: any

View File

@ -1,6 +1,7 @@
import loginArl from './login-arl' import changeAccount from './changeAccount'
import loginArl from './loginArl'
import addToQueue from './addToQueue' import addToQueue from './addToQueue'
import loginWithCredentials from './loginWithCredentials' import loginEmail from './loginEmail'
import cancelAllDownloads from './cancelAllDownloads' import cancelAllDownloads from './cancelAllDownloads'
import removeFinishedDownloads from './removeFinishedDownloads' import removeFinishedDownloads from './removeFinishedDownloads'
import removeFromQueue from './removeFromQueue' import removeFromQueue from './removeFromQueue'
@ -8,9 +9,10 @@ import logout from './logout'
import saveSettings from './saveSettings' import saveSettings from './saveSettings'
export default [ export default [
changeAccount,
loginArl, loginArl,
addToQueue, addToQueue,
loginWithCredentials, loginEmail,
cancelAllDownloads, cancelAllDownloads,
removeFinishedDownloads, removeFinishedDownloads,
removeFromQueue, removeFromQueue,

View File

@ -1,9 +1,9 @@
import { appSendPost } from '../../../../tests/utils' import { appSendPost } from '../../../../tests/utils'
describe('login-arl requests', () => { describe('loginArl requests', () => {
it('should respond 200 to calls with arl', async () => { it('should respond 200 to calls with arl', async () => {
const responseStatusCollector: number[] = [] const responseStatusCollector: number[] = []
const batchCalls = ['/api/login-arl/?arl=abcdef1234'] const batchCalls = ['/api/loginArl/?arl=abcdef1234']
for (const uri of batchCalls) { for (const uri of batchCalls) {
responseStatusCollector.push((await appSendPost(uri)).status) responseStatusCollector.push((await appSendPost(uri)).status)
@ -15,7 +15,7 @@ describe('login-arl requests', () => {
it('should respond 400 to calls without arl', async () => { it('should respond 400 to calls without arl', async () => {
const responseStatusCollector: number[] = [] 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) { for (const uri of batchCalls) {
responseStatusCollector.push((await appSendPost(uri)).status) responseStatusCollector.push((await appSendPost(uri)).status)
@ -25,14 +25,14 @@ describe('login-arl requests', () => {
}) })
it('should login using ARL', async () => { 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.status).toBe(200)
expect(response.body.status).toBe(true) expect(response.body.status).toBe(true)
}) })
it('should not login using wrong ARL', async () => { 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.status).toBe(200)
expect(response.body.status).toBe(false) expect(response.body.status).toBe(false)

View File

@ -4,7 +4,7 @@ import { Deezer } from 'deezer-js'
import { sessionDZ, startQueue, isDeezerAvailable } from '../../../main' import { sessionDZ, startQueue, isDeezerAvailable } from '../../../main'
import { ApiHandler } from '../../../types' import { ApiHandler } from '../../../types'
export interface RawLoginArlQuery { export interface RawLoginArlBody {
arl: string arl: string
child?: number child?: number
} }
@ -17,26 +17,26 @@ const LoginStatus = {
FORCED_SUCCESS: 3 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() if (!sessionDZ[req.session.id]) sessionDZ[req.session.id] = new Deezer()
const dz = sessionDZ[req.session.id] const dz = sessionDZ[req.session.id]
if (!req.query) { if (!req.body) {
return res.status(400).send() return res.status(400).send()
} }
if (!req.query.arl) { if (!req.body.arl) {
return res.status(400).send() 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 // TODO Handle the child === 0 case, don't want to rely on the login_via_arl default param (it may change in the
// future) // future)
if (req.query.child) { if (req.body.child) {
loginParams.push(req.query.child) loginParams.push(req.body.child)
} }
let response let response
@ -61,7 +61,7 @@ const handler: RequestHandler<{}, {}, {}, RawLoginArlQuery> = async (req, res, _
if (!(await isDeezerAvailable())) response = LoginStatus.NOT_AVAILABLE if (!(await isDeezerAvailable())) response = LoginStatus.NOT_AVAILABLE
const returnValue = { const returnValue = {
status: response, status: response,
arl: req.query.arl, arl: req.body.arl,
user: dz.current_user, user: dz.current_user,
childs: dz.childs, childs: dz.childs,
currentChild: dz.selected_account currentChild: dz.selected_account

View File

@ -1,7 +1,7 @@
import { ApiHandler } from '../../../types' import { ApiHandler } from '../../../types'
import { getAccessToken, getArlFromAccessToken } from '../../../main' import { getAccessToken, getArlFromAccessToken } from '../../../main'
const path = '/loginWithCredentials' const path = '/loginEmail'
const handler: ApiHandler['handler'] = async (req, res) => { const handler: ApiHandler['handler'] = async (req, res) => {
const { email, password } = req.body const { email, password } = req.body