fix: type checking errors; feat: added .yarnrc file; chore: linting

This commit is contained in:
Roberto Tonino 2021-05-11 20:21:37 +02:00
parent d672b9bc55
commit 9fc36abf06
21 changed files with 146 additions and 145 deletions

1
server/.yarnrc Normal file
View File

@ -0,0 +1 @@
save-prefix: ""

View File

@ -1,10 +1,10 @@
NODE_BIN ?= .\node_modules\.bin
lint:
@$(NODE_BIN)\eslint ./src/** --fix
$(NODE_BIN)\eslint ./src/** --fix
test:
@$(NODE_BIN)\jest
$(NODE_BIN)\jest
build: lint test
@$(NODE_BIN)\tsc
$(NODE_BIN)\tsc

View File

@ -1,8 +1,6 @@
// @ts-expect-error
import { Deezer } from 'deezer-js'
// @ts-expect-error
import deemix from 'deemix'
export let settings: any = deemix.settings.load()
export const settings: any = deemix.settings.load()
export const defaultSettings: any = deemix.settings.DEFAULTS
export let sessionDZ: any = {}
export const sessionDZ: any = {}

View File

@ -4,14 +4,14 @@ import express from 'express'
import cookieParser from 'cookie-parser'
import session from 'express-session'
declare module 'express-session' {
export interface SessionData {
dz: any;
}
}
import { WEBUI_DIR } from './helpers/paths'
declare module 'express-session' {
export interface SessionData {
dz: any
}
}
export function registerMiddlewares(app: Application) {
if (process.env.NODE_ENV !== 'test') {
app.use(logger('dev'))
@ -20,10 +20,12 @@ export function registerMiddlewares(app: Application) {
app.use(express.json())
app.use(express.urlencoded({ extended: false }))
app.use(cookieParser())
app.use(session({
secret: "U2hoLCBpdHMgYSBzZWNyZXQh",
resave: true,
saveUninitialized: true
}))
app.use(
session({
secret: 'U2hoLCBpdHMgYSBzZWNyZXQh',
resave: true,
saveUninitialized: true
})
)
app.use(express.static(WEBUI_DIR))
}

View File

@ -1,7 +1,7 @@
import { RequestHandler } from 'express'
import { ApiHandler } from '../../../types'
// @ts-expect-error
import { Deezer } from 'deezer-js'
import { ApiHandler } from '../../../types'
import { sessionDZ } from '../../../main'
export interface RawAlbumQuery {
@ -26,7 +26,7 @@ const path: ApiHandler['path'] = '/album-search/'
const handler: RequestHandler<{}, {}, {}, RawAlbumQuery> = async (req, res, next) => {
if (!sessionDZ[req.session.id]) sessionDZ[req.session.id] = new Deezer()
let dz = sessionDZ[req.session.id]
const dz = sessionDZ[req.session.id]
if (!req.query) {
res.status(400).send()

View File

@ -1,7 +1,7 @@
import { RequestHandler } from 'express'
import { ApiHandler } from '../../../types'
// @ts-expect-error
import { Deezer } from 'deezer-js'
import { ApiHandler } from '../../../types'
import { sessionDZ } from '../../../main'
import { isObjectEmpy } from '../../../helpers/primitive-checks'
@ -18,7 +18,7 @@ const path: ApiHandler['path'] = '/getChartTracks'
const handler: RequestHandler<{}, {}, {}, RawChartTracksQuery> = async (req, res, next) => {
try {
if (!sessionDZ[req.session.id]) sessionDZ[req.session.id] = new Deezer()
let dz = sessionDZ[req.session.id]
const dz = sessionDZ[req.session.id]
if (isObjectEmpy(req.query) || !req.query.id) {
throw new BadRequestError()

View File

@ -1,6 +1,6 @@
import { ApiHandler } from '../../../types'
// @ts-expect-error
import { Deezer } from 'deezer-js'
import { ApiHandler } from '../../../types'
import { sessionDZ } from '../../../main'
const path: ApiHandler['path'] = '/getCharts'
@ -10,7 +10,7 @@ let chartsCache: any
const handler: ApiHandler['handler'] = async (req, res) => {
if (!chartsCache) {
if (!sessionDZ[req.session.id]) sessionDZ[req.session.id] = new Deezer()
let dz = sessionDZ[req.session.id]
const dz = sessionDZ[req.session.id]
const chartsData = await dz.api.get_countries_charts()
const countries: any[] = []

View File

@ -1,6 +1,6 @@
import { ApiHandler } from '../../../types'
// @ts-expect-error
import { Deezer } from 'deezer-js'
import { ApiHandler } from '../../../types'
import { sessionDZ } from '../../../main'
const path: ApiHandler['path'] = '/getHome'
@ -9,7 +9,7 @@ let homeCache: any
const handler: ApiHandler['handler'] = async (req, res) => {
if (!sessionDZ[req.session.id]) sessionDZ[req.session.id] = new Deezer()
let dz = sessionDZ[req.session.id]
const dz = sessionDZ[req.session.id]
if (!homeCache) {
homeCache = await dz.api.get_chart(0, { limit: 30 })

View File

@ -4,7 +4,7 @@ import { settings, defaultSettings } from '../../../main'
const path: ApiHandler['path'] = '/getSettings'
const handler: ApiHandler['handler'] = async (_, res) => {
res.send({settings, defaultSettings})
res.send({ settings, defaultSettings })
}
const apiHandler: ApiHandler = { path, handler }

View File

@ -1,20 +1,20 @@
import { ApiHandler } from '../../../types'
// @ts-expect-error
import { Deezer } from 'deezer-js'
import { ApiHandler } from '../../../types'
import { sessionDZ } from '../../../main'
const path: ApiHandler['path'] = '/getTracklist'
const handler: ApiHandler['handler'] = async (req, res) => {
if (!sessionDZ[req.session.id]) sessionDZ[req.session.id] = new Deezer()
let dz = sessionDZ[req.session.id]
const dz = sessionDZ[req.session.id]
let list_id = String(req.query.id)
let list_type = String(req.query.type)
const list_id = String(req.query.id)
const list_type = String(req.query.type)
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, {limit: 100})
artistAPI.releases = await dz.gw.get_artist_discography_tabs(list_id, { limit: 100 })
res.send(artistAPI)
break
}

View File

@ -1,27 +1,27 @@
import { ApiHandler } from '../../../types'
// @ts-expect-error
import { Deezer } from 'deezer-js'
import { ApiHandler } from '../../../types'
import { sessionDZ } from '../../../main'
const path: ApiHandler['path'] = '/getUserAlbums'
const handler: ApiHandler['handler'] = async (req, res) => {
if (!sessionDZ[req.session.id]) sessionDZ[req.session.id] = new Deezer()
let dz = sessionDZ[req.session.id]
let data
const dz = sessionDZ[req.session.id]
let data
if (dz.logged_in){
let userID = dz.current_user.id
try {
data = await dz.api.get_user_albums(userID, {limit: -1})
data = data.data
} catch {
data = await dz.gw.get_user_albums(userID, {limit: -1})
}
} else {
data = {error: "notLoggedIn"}
}
res.send(data)
if (dz.logged_in) {
const userID = dz.current_user.id
try {
data = await dz.api.get_user_albums(userID, { limit: -1 })
data = data.data
} catch {
data = await dz.gw.get_user_albums(userID, { limit: -1 })
}
} else {
data = { error: 'notLoggedIn' }
}
res.send(data)
}
const apiHandler: ApiHandler = { path, handler }

View File

@ -1,27 +1,27 @@
import { ApiHandler } from '../../../types'
// @ts-expect-error
import { Deezer } from 'deezer-js'
import { ApiHandler } from '../../../types'
import { sessionDZ } from '../../../main'
const path: ApiHandler['path'] = '/getUserArtists'
const handler: ApiHandler['handler'] = async (req, res) => {
if (!sessionDZ[req.session.id]) sessionDZ[req.session.id] = new Deezer()
let dz = sessionDZ[req.session.id]
let data
const dz = sessionDZ[req.session.id]
let data
if (dz.logged_in){
let userID = dz.current_user.id
try {
data = await dz.api.get_user_artists(userID, {limit: -1})
data = data.data
} catch {
data = await dz.gw.get_user_artists(userID, {limit: -1})
}
} else {
data = {error: "notLoggedIn"}
}
res.send(data)
if (dz.logged_in) {
const userID = dz.current_user.id
try {
data = await dz.api.get_user_artists(userID, { limit: -1 })
data = data.data
} catch {
data = await dz.gw.get_user_artists(userID, { limit: -1 })
}
} else {
data = { error: 'notLoggedIn' }
}
res.send(data)
}
const apiHandler: ApiHandler = { path, handler }

View File

@ -1,39 +1,39 @@
import { ApiHandler } from '../../../types'
// @ts-expect-error
import { Deezer } from 'deezer-js'
import { ApiHandler } from '../../../types'
import { sessionDZ } from '../../../main'
const path: ApiHandler['path'] = '/getUserFavorites'
const handler: ApiHandler['handler'] = async (req, res) => {
if (!sessionDZ[req.session.id]) sessionDZ[req.session.id] = new Deezer()
let dz = sessionDZ[req.session.id]
const dz = sessionDZ[req.session.id]
let result: any = {}
let result: any = {}
if (dz.logged_in){
let userID = dz.current_user.id
if (dz.logged_in) {
const userID = dz.current_user.id
try {
let data
data = await dz.api.get_user_playlists(userID, {limit: -1})
result['playlists'] = data.data
data = await dz.api.get_user_albums(userID, {limit: -1})
result['albums'] = data.data
data = await dz.api.get_user_artists(userID, {limit: -1})
result['artists'] = data.data
data = await dz.api.get_user_tracks(userID, {limit: -1})
result['tracks'] = data.data
} catch {
result['playlists'] = await dz.gw.get_user_playlists(userID, {limit: -1})
result['albums'] = await dz.gw.get_user_albums(userID, {limit: -1})
result['artists'] = await dz.gw.get_user_artists(userID, {limit: -1})
result['tracks'] = await dz.gw.get_user_tracks(userID, {limit: -1})
}
} else {
result = {error: "notLoggedIn"}
}
res.send(result)
try {
let data
data = await dz.api.get_user_playlists(userID, { limit: -1 })
result.playlists = data.data
data = await dz.api.get_user_albums(userID, { limit: -1 })
result.albums = data.data
data = await dz.api.get_user_artists(userID, { limit: -1 })
result.artists = data.data
data = await dz.api.get_user_tracks(userID, { limit: -1 })
result.tracks = data.data
} catch {
result.playlists = await dz.gw.get_user_playlists(userID, { limit: -1 })
result.albums = await dz.gw.get_user_albums(userID, { limit: -1 })
result.artists = await dz.gw.get_user_artists(userID, { limit: -1 })
result.tracks = await dz.gw.get_user_tracks(userID, { limit: -1 })
}
} else {
result = { error: 'notLoggedIn' }
}
res.send(result)
}
const apiHandler: ApiHandler = { path, handler }

View File

@ -1,27 +1,27 @@
import { ApiHandler } from '../../../types'
// @ts-expect-error
import { Deezer } from 'deezer-js'
import { ApiHandler } from '../../../types'
import { sessionDZ } from '../../../main'
const path: ApiHandler['path'] = '/getUserPlaylists'
const handler: ApiHandler['handler'] = async (req, res) => {
if (!sessionDZ[req.session.id]) sessionDZ[req.session.id] = new Deezer()
let dz = sessionDZ[req.session.id]
let data
const dz = sessionDZ[req.session.id]
let data
if (dz.logged_in){
let userID = dz.current_user.id
try {
data = await dz.api.get_user_playlists(userID, {limit: -1})
data = data.data
} catch {
data = await dz.gw.get_user_playlists(userID, {limit: -1})
}
} else {
data = {error: "notLoggedIn"}
}
res.send(data)
if (dz.logged_in) {
const userID = dz.current_user.id
try {
data = await dz.api.get_user_playlists(userID, { limit: -1 })
data = data.data
} catch {
data = await dz.gw.get_user_playlists(userID, { limit: -1 })
}
} else {
data = { error: 'notLoggedIn' }
}
res.send(data)
}
const apiHandler: ApiHandler = { path, handler }

View File

@ -1,27 +1,27 @@
import { ApiHandler } from '../../../types'
// @ts-expect-error
import { Deezer } from 'deezer-js'
import { ApiHandler } from '../../../types'
import { sessionDZ } from '../../../main'
const path: ApiHandler['path'] = '/getUserTracks'
const handler: ApiHandler['handler'] = async (req, res) => {
if (!sessionDZ[req.session.id]) sessionDZ[req.session.id] = new Deezer()
let dz = sessionDZ[req.session.id]
let data
const dz = sessionDZ[req.session.id]
let data
if (dz.logged_in){
let userID = dz.current_user.id
try {
data = await dz.api.get_user_tracks(userID, {limit: -1})
data = data.data
} catch {
data = await dz.gw.get_user_tracks(userID, {limit: -1})
}
} else {
data = {error: "notLoggedIn"}
}
res.send(data)
if (dz.logged_in) {
const userID = dz.current_user.id
try {
data = await dz.api.get_user_tracks(userID, { limit: -1 })
data = data.data
} catch {
data = await dz.gw.get_user_tracks(userID, { limit: -1 })
}
} else {
data = { error: 'notLoggedIn' }
}
res.send(data)
}
const apiHandler: ApiHandler = { path, handler }

View File

@ -13,17 +13,17 @@ import getUserPlaylists from './getUserPlaylists'
import getUserFavorites from './getUserFavorites'
export default [
albumSearch,
getHome,
getCharts,
getChartTracks,
mainSearch,
search,
getTracklist,
getSettings,
getUserTracks,
getUserAlbums,
getUserArtists,
getUserPlaylists,
getUserFavorites
albumSearch,
getHome,
getCharts,
getChartTracks,
mainSearch,
search,
getTracklist,
getSettings,
getUserTracks,
getUserAlbums,
getUserArtists,
getUserPlaylists,
getUserFavorites
]

View File

@ -1,16 +1,16 @@
import { ApiHandler } from '../../../types'
// @ts-expect-error
import { Deezer } from 'deezer-js'
import { ApiHandler } from '../../../types'
import { sessionDZ } from '../../../main'
const path: ApiHandler['path'] = '/mainSearch'
const handler: ApiHandler['handler'] = async (req, res) => {
if (!sessionDZ[req.session.id]) sessionDZ[req.session.id] = new Deezer()
let dz = sessionDZ[req.session.id]
const dz = sessionDZ[req.session.id]
const term = String(req.query.term)
let results = await dz.gw.search(term)
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)

View File

@ -1,20 +1,20 @@
import { ApiHandler } from '../../../types'
// @ts-expect-error
import { Deezer } from 'deezer-js'
import { ApiHandler } from '../../../types'
import { sessionDZ } from '../../../main'
const path: ApiHandler['path'] = '/search'
const handler: ApiHandler['handler'] = async (req, res) => {
if (!sessionDZ[req.session.id]) sessionDZ[req.session.id] = new Deezer()
let dz = sessionDZ[req.session.id]
const dz = sessionDZ[req.session.id]
const term = String(req.query.term)
const type = String(req.query.type)
const start = parseInt(String(req.query.start))
const nb = parseInt(String(req.query.nb))
let data;
let data
switch (type) {
case 'track':
@ -39,7 +39,7 @@ const handler: ApiHandler['handler'] = async (req, res) => {
data = await dz.api.search(term, { limit: nb, index: start })
break
}
data.type = type
res.send(data)
}

View File

@ -21,7 +21,7 @@ const path: ApiHandler['path'] = '/login-arl/'
const handler: RequestHandler<{}, {}, {}, RawLoginArlQuery> = async (req, res, next) => {
if (!sessionDZ[req.session.id]) sessionDZ[req.session.id] = new Deezer()
let dz = sessionDZ[req.session.id]
const dz = sessionDZ[req.session.id]
if (!req.query) {
res.status(400).send()
@ -44,7 +44,7 @@ const handler: RequestHandler<{}, {}, {}, RawLoginArlQuery> = async (req, res, n
let response
if (process.env.NODE_ENV !== 'test') {
if (!dz.logged_in){
if (!dz.logged_in) {
response = await dz.login_via_arl(...loginParams)
response = response ? 1 : 0
} else {
@ -55,7 +55,7 @@ const handler: RequestHandler<{}, {}, {}, RawLoginArlQuery> = async (req, res, n
response = await testDz.login_via_arl(...loginParams)
}
console.log(response)
let returnValue = {status: response, arl: req.query.arl, user: dz.current_user}
const returnValue = { status: response, arl: req.query.arl, user: dz.current_user }
res.status(200).send(returnValue)
next()

View File

@ -16,14 +16,14 @@ router.get('/', (_, res) => {
router.get('/connect', (req, res) => {
if (!sessionDZ[req.session.id]) sessionDZ[req.session.id] = new Deezer()
let dz = sessionDZ[req.session.id]
const dz = sessionDZ[req.session.id]
res.send({
update: {
currentCommit: "testing",
latestCommit: "testing",
currentCommit: 'testing',
latestCommit: 'testing',
updateAvailable: false,
deemixVersion: "3.0_beta"
deemixVersion: '3.0_beta'
},
autologin: !dz.logged_in,
currentUser: dz.current_user,

2
webui

@ -1 +1 @@
Subproject commit 6baf7d989bafdf1100422d03308ddedf49af1c2c
Subproject commit 9710a5f19f6614fefc760e1771cb67b410ee55de