From bb6e4bec0d22ede72668afe278e9a8e4b13c7c46 Mon Sep 17 00:00:00 2001 From: RemixDev Date: Thu, 13 Jan 2022 01:27:08 +0100 Subject: [PATCH] Made POST requests actual post requests --- server/src/routes/api/get/index.ts | 2 -- server/src/routes/api/post/addToQueue.ts | 4 ++-- .../api/{get => post}/changeAccount.spec.ts | 0 .../routes/api/{get => post}/changeAccount.ts | 0 server/src/routes/api/post/index.ts | 8 +++++--- .../{login-arl.spec.ts => loginArl.spec.ts} | 10 +++++----- .../api/post/{login-arl.ts => loginArl.ts} | 18 +++++++++--------- .../{loginWithCredentials.ts => loginEmail.ts} | 2 +- 8 files changed, 22 insertions(+), 22 deletions(-) rename server/src/routes/api/{get => post}/changeAccount.spec.ts (100%) rename server/src/routes/api/{get => post}/changeAccount.ts (100%) rename server/src/routes/api/post/{login-arl.spec.ts => loginArl.spec.ts} (74%) rename server/src/routes/api/post/{login-arl.ts => loginArl.ts} (81%) rename server/src/routes/api/post/{loginWithCredentials.ts => loginEmail.ts} (93%) diff --git a/server/src/routes/api/get/index.ts b/server/src/routes/api/get/index.ts index 435426c..c3eb86b 100644 --- a/server/src/routes/api/get/index.ts +++ b/server/src/routes/api/get/index.ts @@ -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, diff --git a/server/src/routes/api/post/addToQueue.ts b/server/src/routes/api/post/addToQueue.ts index a5ed448..9d94262 100644 --- a/server/src/routes/api/post/addToQueue.ts +++ b/server/src/routes/api/post/addToQueue.ts @@ -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 diff --git a/server/src/routes/api/get/changeAccount.spec.ts b/server/src/routes/api/post/changeAccount.spec.ts similarity index 100% rename from server/src/routes/api/get/changeAccount.spec.ts rename to server/src/routes/api/post/changeAccount.spec.ts diff --git a/server/src/routes/api/get/changeAccount.ts b/server/src/routes/api/post/changeAccount.ts similarity index 100% rename from server/src/routes/api/get/changeAccount.ts rename to server/src/routes/api/post/changeAccount.ts diff --git a/server/src/routes/api/post/index.ts b/server/src/routes/api/post/index.ts index 88f5a07..5d88377 100644 --- a/server/src/routes/api/post/index.ts +++ b/server/src/routes/api/post/index.ts @@ -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, diff --git a/server/src/routes/api/post/login-arl.spec.ts b/server/src/routes/api/post/loginArl.spec.ts similarity index 74% rename from server/src/routes/api/post/login-arl.spec.ts rename to server/src/routes/api/post/loginArl.spec.ts index 75d50bd..dd5dde7 100644 --- a/server/src/routes/api/post/login-arl.spec.ts +++ b/server/src/routes/api/post/loginArl.spec.ts @@ -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) diff --git a/server/src/routes/api/post/login-arl.ts b/server/src/routes/api/post/loginArl.ts similarity index 81% rename from server/src/routes/api/post/login-arl.ts rename to server/src/routes/api/post/loginArl.ts index f5b7686..3711e66 100644 --- a/server/src/routes/api/post/login-arl.ts +++ b/server/src/routes/api/post/loginArl.ts @@ -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 diff --git a/server/src/routes/api/post/loginWithCredentials.ts b/server/src/routes/api/post/loginEmail.ts similarity index 93% rename from server/src/routes/api/post/loginWithCredentials.ts rename to server/src/routes/api/post/loginEmail.ts index 52623de..8104407 100644 --- a/server/src/routes/api/post/loginWithCredentials.ts +++ b/server/src/routes/api/post/loginEmail.ts @@ -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