From e13a95d9dd197dc63ffac126c7571460c48adbc8 Mon Sep 17 00:00:00 2001 From: jeffvli Date: Thu, 18 Nov 2021 03:23:26 -0800 Subject: [PATCH] Move types file to root src directory --- src/__tests__/App.test.tsx | 2 +- src/api/api.ts | 8 ++++---- src/api/controller.ts | 17 +++++++++++------ src/api/jellyfinApi.ts | 2 +- src/redux/configSlice.ts | 2 +- src/{api => }/types.ts | 39 +++++++++++++++++++++++++++++++++++++- 6 files changed, 56 insertions(+), 14 deletions(-) rename src/{api => }/types.ts (73%) diff --git a/src/__tests__/App.test.tsx b/src/__tests__/App.test.tsx index 4e2d121..a0f02d4 100644 --- a/src/__tests__/App.test.tsx +++ b/src/__tests__/App.test.tsx @@ -13,7 +13,7 @@ import { FolderSelection } from '../redux/folderSlice'; import { FavoritePage } from '../redux/favoriteSlice'; import App from '../App'; import { AlbumPage } from '../redux/albumSlice'; -import { Server } from '../api/types'; +import { Server } from '../types'; const middlewares: Middleware, any, Dispatch>[] | undefined = []; const mockStore = configureMockStore(middlewares); diff --git a/src/api/api.ts b/src/api/api.ts index 44d537e..5a7bda0 100644 --- a/src/api/api.ts +++ b/src/api/api.ts @@ -5,7 +5,7 @@ import settings from 'electron-settings'; import { nanoid } from 'nanoid/non-secure'; import axiosRetry from 'axios-retry'; import { mockSettings } from '../shared/mockSettings'; -import { Item } from './types'; +import { Item } from '../types'; const legacyAuth = process.env.NODE_ENV === 'test' @@ -120,11 +120,11 @@ const getCoverArtUrl = (item: any, useLegacyAuth: boolean, size?: number) => { ); }; -export const getDownloadUrl = (id: string, useLegacyAuth = legacyAuth) => { +export const getDownloadUrl = (options: { id: string }, useLegacyAuth = legacyAuth) => { if (useLegacyAuth) { return ( `${API_BASE_URL}/download` + - `?id=${id}` + + `?id=${options.id}` + `&u=${auth.username}` + `&p=${auth.password}` + `&v=1.15.0` + @@ -134,7 +134,7 @@ export const getDownloadUrl = (id: string, useLegacyAuth = legacyAuth) => { return ( `${API_BASE_URL}/download` + - `?id=${id}` + + `?id=${options.id}` + `&u=${auth.username}` + `&s=${auth.salt}` + `&t=${auth.hash}` + diff --git a/src/api/controller.ts b/src/api/controller.ts index 745270e..f3b5cb6 100644 --- a/src/api/controller.ts +++ b/src/api/controller.ts @@ -11,6 +11,7 @@ import { getArtistInfo, getArtists, getArtistSongs, + getDownloadUrl, getGenres, getIndexes, getMusicDirectory, @@ -23,6 +24,8 @@ import { getSearch, getSimilarSongs, getStarred, + scrobble, + setRating, star, startScan, unstar, @@ -31,7 +34,7 @@ import { updatePlaylistSongsLg, } from './api'; import { getPlaylist as jfGetPlaylist, getPlaylists as jfGetPlaylists } from './jellyfinApi'; -import { APIEndpoints, ServerType } from './types'; +import { APIEndpoints, ServerType } from '../types'; // prettier-ignore const endpoints = [ @@ -51,6 +54,7 @@ const endpoints = [ { id: 'unstar', endpoint: { subsonic: unstar, jellyfin: undefined } }, { id: 'batchStar', endpoint: { subsonic: batchStar, jellyfin: undefined } }, { id: 'batchUnstar', endpoint: { subsonic: batchUnstar, jellyfin: undefined } }, + { id: 'setRating', endpoint: { subsonic: setRating, jellyfin: undefined } }, { id: 'getSimilarSongs', endpoint: { subsonic: getSimilarSongs, jellyfin: undefined } }, { id: 'updatePlaylistSongs', endpoint: { subsonic: updatePlaylistSongs, jellyfin: undefined } }, { id: 'updatePlaylistSongsLg', endpoint: { subsonic: updatePlaylistSongsLg, jellyfin: undefined } }, @@ -60,10 +64,12 @@ const endpoints = [ { id: 'clearPlaylist', endpoint: { subsonic: clearPlaylist, jellyfin: undefined } }, { id: 'getGenres', endpoint: { subsonic: getGenres, jellyfin: undefined } }, { id: 'getSearch', endpoint: { subsonic: getSearch, jellyfin: undefined } }, + { id: 'scrobble', endpoint: { subsonic: scrobble, jellyfin: undefined } }, { id: 'getIndexes', endpoint: { subsonic: getIndexes, jellyfin: undefined } }, { id: 'getMusicFolders', endpoint: { subsonic: getMusicFolders, jellyfin: undefined } }, { id: 'getMusicDirectory', endpoint: { subsonic: getMusicDirectory, jellyfin: undefined } }, { id: 'getMusicDirectorySongs', endpoint: { subsonic: getMusicDirectorySongs, jellyfin: undefined } }, + { id: 'getDownloadUrl', endpoint: { subsonic: getDownloadUrl, jellyfin: undefined } }, ]; export const apiController = async (options: { @@ -71,14 +77,13 @@ export const apiController = async (options: { endpoint: APIEndpoints; args?: any; }) => { - const selectedEndpoint = endpoints.find((e) => e.id === options.endpoint)?.endpoint[ - options.serverType - ]; + const selectedEndpoint = endpoints.find((e) => e.id === options.endpoint); + const selectedEndpointFn = selectedEndpoint!.endpoint[options.serverType]; - if (!selectedEndpoint) { + if (!selectedEndpointFn || !selectedEndpoint) { return notifyToast('warning', `[${options.endpoint}] not available`); } - const res = await selectedEndpoint(options.args); + const res = await selectedEndpointFn(options.args); return res; }; diff --git a/src/api/jellyfinApi.ts b/src/api/jellyfinApi.ts index 144c0da..f9730b0 100644 --- a/src/api/jellyfinApi.ts +++ b/src/api/jellyfinApi.ts @@ -3,7 +3,7 @@ import _ from 'lodash'; import { nanoid } from 'nanoid/non-secure'; import { handleDisconnect } from '../components/settings/DisconnectButton'; import { notifyToast } from '../components/shared/toast'; -import { Item } from './types'; +import { Item } from '../types'; const getAuth = () => { return { diff --git a/src/redux/configSlice.ts b/src/redux/configSlice.ts index 6d58a59..bf59548 100644 --- a/src/redux/configSlice.ts +++ b/src/redux/configSlice.ts @@ -3,7 +3,7 @@ import { createSlice, PayloadAction } from '@reduxjs/toolkit'; import settings from 'electron-settings'; import { mockSettings } from '../shared/mockSettings'; import { moveSelectedToIndex } from '../shared/utils'; -import { Server } from '../api/types'; +import { Server } from '../types'; const parsedSettings: any = process.env.NODE_ENV === 'test' ? mockSettings : settings.getSync(); diff --git a/src/api/types.ts b/src/types.ts similarity index 73% rename from src/api/types.ts rename to src/types.ts index f739e96..cd9c79c 100644 --- a/src/api/types.ts +++ b/src/types.ts @@ -13,7 +13,44 @@ export enum Item { } export type ServerType = Server.Subsonic | Server.Jellyfin; -export type APIEndpoints = 'getPlaylist' | 'getPlaylists'; + +export type APIEndpoints = + | 'getPlaylist' + | 'getPlaylists' + | 'getStarred' + | 'getAlbum' + | 'getAlbums' + | 'getRandomSongs' + | 'getArtist' + | 'getArtists' + | 'getArtistInfo' + | 'getArtistSongs' + | 'startScan' + | 'getScanStatus' + | 'star' + | 'unstar' + | 'batchStar' + | 'batchUnstar' + | 'setRating' + | 'getSimilarSongs' + | 'updatePlaylistSongs' + | 'updatePlaylistSongsLg' + | 'deletePlaylist' + | 'createPlaylist' + | 'updatePlaylist' + | 'updatePlaylistSongsLg' + | 'deletePlaylist' + | 'createPlaylist' + | 'updatePlaylist' + | 'clearPlaylist' + | 'getGenres' + | 'getSearch' + | 'scrobble' + | 'getIndexes' + | 'getMusicFolders' + | 'getMusicDirectory' + | 'getMusicDirectorySongs' + | 'getDownloadUrl'; export interface Album { id: string;