chore: linting
This commit is contained in:
parent
29c84cf8b9
commit
1ecaaba51f
@ -13,3 +13,4 @@ rules:
|
|||||||
argsIgnorePattern: ^_
|
argsIgnorePattern: ^_
|
||||||
no-unused-vars: off
|
no-unused-vars: off
|
||||||
no-console: off
|
no-console: off
|
||||||
|
camelcase: off
|
||||||
|
@ -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 === */
|
||||||
|
@ -1,73 +1,77 @@
|
|||||||
// @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
|
||||||
|
|
||||||
export async function getHome(){
|
export async function getHome() {
|
||||||
if (!homeCache){
|
if (!homeCache) {
|
||||||
homeCache = await dz.api.get_chart(0, {limit: 30})
|
homeCache = await dz.api.get_chart(0, { limit: 30 })
|
||||||
}
|
}
|
||||||
return homeCache
|
return homeCache
|
||||||
}
|
}
|
||||||
|
|
||||||
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 }
|
||||||
}
|
}
|
||||||
return chartsCache
|
return chartsCache
|
||||||
}
|
}
|
||||||
|
|
||||||
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) => {
|
||||||
if (showdiscs && parseInt(track.disk_number) !== current_disk){
|
if (showdiscs && parseInt(track.disk_number) !== current_disk) {
|
||||||
current_disk = parseInt(track.disk_number)
|
current_disk = parseInt(track.disk_number)
|
||||||
tracks.push({type: 'disc_separator', number: current_disk})
|
tracks.push({ type: 'disc_separator', number: current_disk })
|
||||||
}
|
}
|
||||||
track.selected = false
|
track.selected = false
|
||||||
tracks.push(track)
|
tracks.push(track)
|
||||||
})
|
})
|
||||||
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,30 +96,30 @@ 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
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function search(term: string, type: string, start: number, nb: number){
|
export async function search(term: string, type: string, start: number, nb: number) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'track':
|
case 'track':
|
||||||
return await dz.api.search_track(term, {limit: nb, index: start})
|
return await dz.api.search_track(term, { limit: nb, index: start })
|
||||||
case 'album':
|
case 'album':
|
||||||
return await dz.api.search_album(term, {limit: nb, index: start})
|
return await dz.api.search_album(term, { limit: nb, index: start })
|
||||||
case 'artist':
|
case 'artist':
|
||||||
return await dz.api.search_artist(term, {limit: nb, index: start})
|
return await dz.api.search_artist(term, { limit: nb, index: start })
|
||||||
case 'playlist':
|
case 'playlist':
|
||||||
return await dz.api.search_playlist(term, {limit: nb, index: start})
|
return await dz.api.search_playlist(term, { limit: nb, index: start })
|
||||||
case 'radio':
|
case 'radio':
|
||||||
return await dz.api.search_radio(term, {limit: nb, index: start})
|
return await dz.api.search_radio(term, { limit: nb, index: start })
|
||||||
case 'user':
|
case 'user':
|
||||||
return await dz.api.search_user(term, {limit: nb, index: start})
|
return await dz.api.search_user(term, { limit: nb, index: start })
|
||||||
default:
|
default:
|
||||||
return await dz.api.search(term, {limit: nb, index: start})
|
return await dz.api.search(term, { limit: nb, index: start })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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()
|
||||||
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user