fix(server): album search endpoint multiple headers error
This commit is contained in:
parent
cb77745776
commit
6dfd28f7a9
@ -1,7 +1,8 @@
|
|||||||
import { RequestHandler } from 'express'
|
import type { RequestHandler } from 'express'
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
import { Deezer } from 'deezer-js'
|
import { Deezer } from 'deezer-js'
|
||||||
import { ApiHandler } from '../../../types'
|
|
||||||
|
import type { ApiHandler } from '../../../types'
|
||||||
import { sessionDZ } from '../../../main'
|
import { sessionDZ } from '../../../main'
|
||||||
|
|
||||||
export interface RawAlbumQuery {
|
export interface RawAlbumQuery {
|
||||||
@ -24,20 +25,18 @@ export interface AlbumResponse {
|
|||||||
|
|
||||||
const path: ApiHandler['path'] = '/album-search/'
|
const path: ApiHandler['path'] = '/album-search/'
|
||||||
|
|
||||||
const handler: RequestHandler<{}, {}, {}, RawAlbumQuery> = async (req, res, next) => {
|
const handler: RequestHandler<{}, {}, {}, RawAlbumQuery> = 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.query) {
|
||||||
res.status(400).send()
|
return res.status(400).send()
|
||||||
return next()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const { term, start, nb, ack } = parseQuery(req.query)
|
const { term, start, nb, ack } = parseQuery(req.query)
|
||||||
|
|
||||||
if (!term || term.trim() === '') {
|
if (!term || term.trim() === '') {
|
||||||
res.status(400).send()
|
return res.status(400).send()
|
||||||
return next()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const albums = await dz.api.search_album(term, { start, nb })
|
const albums = await dz.api.search_album(term, { start, nb })
|
||||||
@ -48,9 +47,7 @@ const handler: RequestHandler<{}, {}, {}, RawAlbumQuery> = async (req, res, next
|
|||||||
ack
|
ack
|
||||||
}
|
}
|
||||||
|
|
||||||
res.send(output)
|
return res.send(output)
|
||||||
res.send()
|
|
||||||
next()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const apiHandler = { path, handler }
|
const apiHandler = { path, handler }
|
||||||
|
Loading…
Reference in New Issue
Block a user