chore: linting

This commit is contained in:
Roberto Tonino 2021-04-24 18:08:08 +02:00
parent 29c84cf8b9
commit 1ecaaba51f
5 changed files with 119 additions and 109 deletions

View File

@ -13,3 +13,4 @@ rules:
argsIgnorePattern: ^_ argsIgnorePattern: ^_
no-unused-vars: off no-unused-vars: off
no-console: off no-console: off
camelcase: off

View File

@ -1,6 +1,6 @@
import http from 'http' import http from 'http'
import express, { Application } from 'express' import express, { Application } from 'express'
import { Server as wsServer } from 'ws' import { Server as WsServer } from 'ws'
import initDebug from 'debug' import initDebug from 'debug'
import { registerMiddlewares } from './middlewares' import { registerMiddlewares } from './middlewares'
@ -15,7 +15,7 @@ const PORT = normalizePort(process.env.PORT || '6595')
const debug = initDebug('deemix-gui:server') const debug = initDebug('deemix-gui:server')
export const app: Application = express() export const app: Application = express()
const ws = new wsServer({ noServer: true }) const ws = new WsServer({ noServer: true })
const server = http.createServer(app) const server = http.createServer(app)
/* === Middlewares === */ /* === Middlewares === */

View File

@ -1,7 +1,7 @@
// @ts-ignore // @ts-expect-error
import { Deezer } from 'deezer-js' import { Deezer } from 'deezer-js'
console.log("init!") console.log('init!')
const dz = new Deezer() const dz = new Deezer()
let homeCache: any, chartsCache: any let homeCache: any, chartsCache: any
@ -15,14 +15,14 @@ export async function getHome(){
export async function getCharts() { export async function getCharts() {
if (!chartsCache) { if (!chartsCache) {
const chartsData = await dz.api.get_countries_charts() const chartsData = await dz.api.get_countries_charts()
let countries: any[] = [] const countries: any[] = []
chartsData.forEach((country: any) => { chartsData.forEach((country: any) => {
countries.push({ countries.push({
title: country.title.replace("Top ", ""), title: country.title.replace('Top ', ''),
id: country.id, id: country.id,
picture_small: country.picture_small, picture_small: country.picture_small,
picture_medium: country.picture_medium, picture_medium: country.picture_medium,
picture_big: country.picture_big, picture_big: country.picture_big
}) })
}) })
chartsCache = { data: countries } chartsCache = { data: countries }
@ -32,17 +32,21 @@ export async function getCharts(){
export async function getTracklist(list_id: string, list_type: string) { export async function getTracklist(list_id: string, list_type: string) {
switch (list_type) { switch (list_type) {
case 'artist': case 'artist': {
let artistAPI = await dz.api.get_artist(list_id) const artistAPI = await dz.api.get_artist(list_id)
artistAPI.releases = await dz.gw.get_artist_discography_tabs(list_id, 100) artistAPI.releases = await dz.gw.get_artist_discography_tabs(list_id, 100)
return artistAPI return artistAPI
default: }
let releaseAPI = await dz.api[`get_${list_type}`](list_id) default: {
const releaseAPI = await dz.api[`get_${list_type}`](list_id)
let releaseTracksAPI = await dz.api[`get_${list_type}_tracks`](list_id) let releaseTracksAPI = await dz.api[`get_${list_type}_tracks`](list_id)
releaseTracksAPI = releaseTracksAPI['data'] releaseTracksAPI = releaseTracksAPI.data
let tracks: any[] = [] const tracks: any[] = []
const showdiscs = (list_type == 'album' && releaseTracksAPI.length && releaseTracksAPI[releaseTracksAPI.length -1].disk_number != 1) const showdiscs =
list_type === 'album' &&
releaseTracksAPI.length &&
releaseTracksAPI[releaseTracksAPI.length - 1].disk_number !== 1
let current_disk = 0 let current_disk = 0
releaseTracksAPI.forEach((track: any) => { releaseTracksAPI.forEach((track: any) => {
@ -55,19 +59,19 @@ export async function getTracklist(list_id: string, list_type: string){
}) })
releaseAPI.tracks = tracks releaseAPI.tracks = tracks
return releaseAPI return releaseAPI
break }
} }
} }
export async function searchAll(term: string) { export async function searchAll(term: string) {
let results = await dz.gw.search(term) const results = await dz.gw.search(term)
let order: string[] = [] const order: string[] = []
results.ORDER.forEach((element: string) => { results.ORDER.forEach((element: string) => {
if (['TOP_RESULT', 'TRACK', 'ALBUM', 'ARTIST', 'PLAYLIST'].indexOf(element) != -1) order.push(element) if (['TOP_RESULT', 'TRACK', 'ALBUM', 'ARTIST', 'PLAYLIST'].includes(element)) order.push(element)
}) })
if (results.TOP_RESULT && results.TOP_RESULT.length) { if (results.TOP_RESULT && results.TOP_RESULT.length) {
let originalTopResult = results.TOP_RESULT[0] const originalTopResult = results.TOP_RESULT[0]
let topResult: any = { const topResult: any = {
type: originalTopResult.__TYPE__ type: originalTopResult.__TYPE__
} }
switch (topResult.type) { switch (topResult.type) {
@ -92,9 +96,9 @@ export async function searchAll(term: string){
topResult.nb_song = originalTopResult.NB_SONG topResult.nb_song = originalTopResult.NB_SONG
break break
default: default:
topResult.id = "0" topResult.id = '0'
topResult.picture = 'https://e-cdns-images.dzcdn.net/images/cover' topResult.picture = 'https://e-cdns-images.dzcdn.net/images/cover'
break; break
} }
} }
results.ORDER = order results.ORDER = order

View File

@ -27,7 +27,7 @@ const handler: RequestHandler<{}, {}, {}, RawAlbumQuery> = (req, res, next) => {
next() next()
} }
const { term, start, nb, ack } = parseQuery(req.query) const { term } = parseQuery(req.query)
if (!term || term.trim() === '') { if (!term || term.trim() === '') {
res.status(400).send() res.status(400).send()

View File

@ -4,7 +4,12 @@ import { search } from '../../../main'
const path: ApiHandler['path'] = '/search' const path: ApiHandler['path'] = '/search'
const handler: ApiHandler['handler'] = async (req, res) => { const handler: ApiHandler['handler'] = async (req, res) => {
const searchData = await search(String(req.query.term), String(req.query.type), parseInt(String(req.query.start)), parseInt(String(req.query.nb))) const searchData = await search(
String(req.query.term),
String(req.query.type),
parseInt(String(req.query.start)),
parseInt(String(req.query.nb))
)
res.send(searchData) res.send(searchData)
} }