From 1ecaaba51f21df5c4d6d7f775edec435c86d1406 Mon Sep 17 00:00:00 2001 From: Roberto Tonino Date: Sat, 24 Apr 2021 18:08:08 +0200 Subject: [PATCH] chore: linting --- server/.eslintrc.yml | 1 + server/src/app.ts | 4 +- server/src/main.ts | 214 ++++++++++++----------- server/src/routes/api/get/albumSearch.ts | 2 +- server/src/routes/api/get/search.ts | 7 +- 5 files changed, 119 insertions(+), 109 deletions(-) diff --git a/server/.eslintrc.yml b/server/.eslintrc.yml index 9bf9eb1..e7eab88 100644 --- a/server/.eslintrc.yml +++ b/server/.eslintrc.yml @@ -13,3 +13,4 @@ rules: argsIgnorePattern: ^_ no-unused-vars: off no-console: off + camelcase: off diff --git a/server/src/app.ts b/server/src/app.ts index a0a0cd0..59c0193 100644 --- a/server/src/app.ts +++ b/server/src/app.ts @@ -1,6 +1,6 @@ import http from 'http' import express, { Application } from 'express' -import { Server as wsServer } from 'ws' +import { Server as WsServer } from 'ws' import initDebug from 'debug' import { registerMiddlewares } from './middlewares' @@ -15,7 +15,7 @@ const PORT = normalizePort(process.env.PORT || '6595') const debug = initDebug('deemix-gui:server') export const app: Application = express() -const ws = new wsServer({ noServer: true }) +const ws = new WsServer({ noServer: true }) const server = http.createServer(app) /* === Middlewares === */ diff --git a/server/src/main.ts b/server/src/main.ts index ba720d8..eb973ff 100644 --- a/server/src/main.ts +++ b/server/src/main.ts @@ -1,121 +1,125 @@ -// @ts-ignore +// @ts-expect-error import { Deezer } from 'deezer-js' -console.log("init!") +console.log('init!') const dz = new Deezer() let homeCache: any, chartsCache: any -export async function getHome(){ - if (!homeCache){ - homeCache = await dz.api.get_chart(0, {limit: 30}) - } - return homeCache +export async function getHome() { + if (!homeCache) { + homeCache = await dz.api.get_chart(0, { limit: 30 }) + } + return homeCache } -export async function getCharts(){ - if (!chartsCache){ - const chartsData = await dz.api.get_countries_charts() - let countries: any[] = [] - chartsData.forEach((country: any) => { - countries.push({ - title: country.title.replace("Top ", ""), - id: country.id, - picture_small: country.picture_small, - picture_medium: country.picture_medium, - picture_big: country.picture_big, - }) - }) - chartsCache = {data: countries} - } - return chartsCache +export async function getCharts() { + if (!chartsCache) { + const chartsData = await dz.api.get_countries_charts() + const countries: any[] = [] + chartsData.forEach((country: any) => { + countries.push({ + title: country.title.replace('Top ', ''), + id: country.id, + picture_small: country.picture_small, + picture_medium: country.picture_medium, + picture_big: country.picture_big + }) + }) + chartsCache = { data: countries } + } + return chartsCache } -export async function getTracklist(list_id: string, list_type: string){ - switch (list_type) { - case 'artist': - let artistAPI = await dz.api.get_artist(list_id) - artistAPI.releases = await dz.gw.get_artist_discography_tabs(list_id, 100) - return artistAPI - default: - let releaseAPI = await dz.api[`get_${list_type}`](list_id) - let releaseTracksAPI = await dz.api[`get_${list_type}_tracks`](list_id) - releaseTracksAPI = releaseTracksAPI['data'] +export async function getTracklist(list_id: string, list_type: string) { + switch (list_type) { + case 'artist': { + const artistAPI = await dz.api.get_artist(list_id) + artistAPI.releases = await dz.gw.get_artist_discography_tabs(list_id, 100) + return artistAPI + } + default: { + const releaseAPI = await dz.api[`get_${list_type}`](list_id) + let releaseTracksAPI = await dz.api[`get_${list_type}_tracks`](list_id) + releaseTracksAPI = releaseTracksAPI.data - let tracks: any[] = [] - const showdiscs = (list_type == 'album' && releaseTracksAPI.length && releaseTracksAPI[releaseTracksAPI.length -1].disk_number != 1) - let current_disk = 0 + const tracks: any[] = [] + const showdiscs = + list_type === 'album' && + releaseTracksAPI.length && + releaseTracksAPI[releaseTracksAPI.length - 1].disk_number !== 1 + let current_disk = 0 - releaseTracksAPI.forEach((track: any) => { - if (showdiscs && parseInt(track.disk_number) !== current_disk){ - current_disk = parseInt(track.disk_number) - tracks.push({type: 'disc_separator', number: current_disk}) - } - track.selected = false - tracks.push(track) - }) - releaseAPI.tracks = tracks - return releaseAPI - break - } + releaseTracksAPI.forEach((track: any) => { + if (showdiscs && parseInt(track.disk_number) !== current_disk) { + current_disk = parseInt(track.disk_number) + tracks.push({ type: 'disc_separator', number: current_disk }) + } + track.selected = false + tracks.push(track) + }) + releaseAPI.tracks = tracks + return releaseAPI + } + } } -export async function searchAll(term: string){ - let results = await dz.gw.search(term) - let order: string[] = [] - results.ORDER.forEach((element: string) => { - if (['TOP_RESULT', 'TRACK', 'ALBUM', 'ARTIST', 'PLAYLIST'].indexOf(element) != -1) order.push(element) - }) - if (results.TOP_RESULT && results.TOP_RESULT.length){ - let originalTopResult = results.TOP_RESULT[0] - let topResult: any = { - type: originalTopResult.__TYPE__ - } - switch (topResult.type) { - case 'artist': - topResult.id = originalTopResult.ART_ID - topResult.picture = `https://e-cdns-images.dzcdn.net/images/artist/${originalTopResult.ART_PICTURE}` - topResult.title = originalTopResult.ART_NAME - topResult.nb_fan = originalTopResult.NB_FAN - break - case 'album': - topResult.id = originalTopResult.ALB_ID - topResult.picture = `https://e-cdns-images.dzcdn.net/images/cover/${originalTopResult.ALB_PICTURE}` - topResult.title = originalTopResult.ALB_TITLE - topResult.artist = originalTopResult.ART_NAME - topResult.nb_song = originalTopResult.NUMBER_TRACK - break - case 'playlist': - topResult.id = originalTopResult.PLAYLIST_ID - topResult.picture = `https://e-cdns-images.dzcdn.net/images/${originalTopResult.PICTURE_TYPE}/${originalTopResult.PLAYLIST_PICTURE}` - topResult.title = originalTopResult.TITLE - topResult.artist = originalTopResult.PARENT_USERNAME - topResult.nb_song = originalTopResult.NB_SONG - break - default: - topResult.id = "0" - topResult.picture = 'https://e-cdns-images.dzcdn.net/images/cover' - break; - } - } - results.ORDER = order - return results +export async function searchAll(term: string) { + const results = await dz.gw.search(term) + const order: string[] = [] + results.ORDER.forEach((element: string) => { + if (['TOP_RESULT', 'TRACK', 'ALBUM', 'ARTIST', 'PLAYLIST'].includes(element)) order.push(element) + }) + if (results.TOP_RESULT && results.TOP_RESULT.length) { + const originalTopResult = results.TOP_RESULT[0] + const topResult: any = { + type: originalTopResult.__TYPE__ + } + switch (topResult.type) { + case 'artist': + topResult.id = originalTopResult.ART_ID + topResult.picture = `https://e-cdns-images.dzcdn.net/images/artist/${originalTopResult.ART_PICTURE}` + topResult.title = originalTopResult.ART_NAME + topResult.nb_fan = originalTopResult.NB_FAN + break + case 'album': + topResult.id = originalTopResult.ALB_ID + topResult.picture = `https://e-cdns-images.dzcdn.net/images/cover/${originalTopResult.ALB_PICTURE}` + topResult.title = originalTopResult.ALB_TITLE + topResult.artist = originalTopResult.ART_NAME + topResult.nb_song = originalTopResult.NUMBER_TRACK + break + case 'playlist': + topResult.id = originalTopResult.PLAYLIST_ID + topResult.picture = `https://e-cdns-images.dzcdn.net/images/${originalTopResult.PICTURE_TYPE}/${originalTopResult.PLAYLIST_PICTURE}` + topResult.title = originalTopResult.TITLE + topResult.artist = originalTopResult.PARENT_USERNAME + topResult.nb_song = originalTopResult.NB_SONG + break + default: + topResult.id = '0' + topResult.picture = 'https://e-cdns-images.dzcdn.net/images/cover' + break + } + } + results.ORDER = order + return results } -export async function search(term: string, type: string, start: number, nb: number){ - switch (type) { - case 'track': - return await dz.api.search_track(term, {limit: nb, index: start}) - case 'album': - return await dz.api.search_album(term, {limit: nb, index: start}) - case 'artist': - return await dz.api.search_artist(term, {limit: nb, index: start}) - case 'playlist': - return await dz.api.search_playlist(term, {limit: nb, index: start}) - case 'radio': - return await dz.api.search_radio(term, {limit: nb, index: start}) - case 'user': - return await dz.api.search_user(term, {limit: nb, index: start}) - default: - return await dz.api.search(term, {limit: nb, index: start}) - } +export async function search(term: string, type: string, start: number, nb: number) { + switch (type) { + case 'track': + return await dz.api.search_track(term, { limit: nb, index: start }) + case 'album': + return await dz.api.search_album(term, { limit: nb, index: start }) + case 'artist': + return await dz.api.search_artist(term, { limit: nb, index: start }) + case 'playlist': + return await dz.api.search_playlist(term, { limit: nb, index: start }) + case 'radio': + return await dz.api.search_radio(term, { limit: nb, index: start }) + case 'user': + return await dz.api.search_user(term, { limit: nb, index: start }) + default: + return await dz.api.search(term, { limit: nb, index: start }) + } } diff --git a/server/src/routes/api/get/albumSearch.ts b/server/src/routes/api/get/albumSearch.ts index 856d8df..9366bee 100644 --- a/server/src/routes/api/get/albumSearch.ts +++ b/server/src/routes/api/get/albumSearch.ts @@ -27,7 +27,7 @@ const handler: RequestHandler<{}, {}, {}, RawAlbumQuery> = (req, res, next) => { next() } - const { term, start, nb, ack } = parseQuery(req.query) + const { term } = parseQuery(req.query) if (!term || term.trim() === '') { res.status(400).send() diff --git a/server/src/routes/api/get/search.ts b/server/src/routes/api/get/search.ts index 803d552..08a7bfb 100644 --- a/server/src/routes/api/get/search.ts +++ b/server/src/routes/api/get/search.ts @@ -4,7 +4,12 @@ import { search } from '../../../main' const path: ApiHandler['path'] = '/search' 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) }