Browse Source

Move types file to root src directory

master
jeffvli 3 years ago
committed by Jeff
parent
commit
e13a95d9dd
  1. 2
      src/__tests__/App.test.tsx
  2. 8
      src/api/api.ts
  3. 17
      src/api/controller.ts
  4. 2
      src/api/jellyfinApi.ts
  5. 2
      src/redux/configSlice.ts
  6. 39
      src/types.ts

2
src/__tests__/App.test.tsx

@ -13,7 +13,7 @@ import { FolderSelection } from '../redux/folderSlice';
import { FavoritePage } from '../redux/favoriteSlice'; import { FavoritePage } from '../redux/favoriteSlice';
import App from '../App'; import App from '../App';
import { AlbumPage } from '../redux/albumSlice'; import { AlbumPage } from '../redux/albumSlice';
import { Server } from '../api/types'; import { Server } from '../types';
const middlewares: Middleware<Record<string, unknown>, any, Dispatch<AnyAction>>[] | undefined = []; const middlewares: Middleware<Record<string, unknown>, any, Dispatch<AnyAction>>[] | undefined = [];
const mockStore = configureMockStore(middlewares); const mockStore = configureMockStore(middlewares);

8
src/api/api.ts

@ -5,7 +5,7 @@ import settings from 'electron-settings';
import { nanoid } from 'nanoid/non-secure'; import { nanoid } from 'nanoid/non-secure';
import axiosRetry from 'axios-retry'; import axiosRetry from 'axios-retry';
import { mockSettings } from '../shared/mockSettings'; import { mockSettings } from '../shared/mockSettings';
import { Item } from './types'; import { Item } from '../types';
const legacyAuth = const legacyAuth =
process.env.NODE_ENV === 'test' 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) { if (useLegacyAuth) {
return ( return (
`${API_BASE_URL}/download` + `${API_BASE_URL}/download` +
`?id=${id}` + `?id=${options.id}` +
`&u=${auth.username}` + `&u=${auth.username}` +
`&p=${auth.password}` + `&p=${auth.password}` +
`&v=1.15.0` + `&v=1.15.0` +
@ -134,7 +134,7 @@ export const getDownloadUrl = (id: string, useLegacyAuth = legacyAuth) => {
return ( return (
`${API_BASE_URL}/download` + `${API_BASE_URL}/download` +
`?id=${id}` + `?id=${options.id}` +
`&u=${auth.username}` + `&u=${auth.username}` +
`&s=${auth.salt}` + `&s=${auth.salt}` +
`&t=${auth.hash}` + `&t=${auth.hash}` +

17
src/api/controller.ts

@ -11,6 +11,7 @@ import {
getArtistInfo, getArtistInfo,
getArtists, getArtists,
getArtistSongs, getArtistSongs,
getDownloadUrl,
getGenres, getGenres,
getIndexes, getIndexes,
getMusicDirectory, getMusicDirectory,
@ -23,6 +24,8 @@ import {
getSearch, getSearch,
getSimilarSongs, getSimilarSongs,
getStarred, getStarred,
scrobble,
setRating,
star, star,
startScan, startScan,
unstar, unstar,
@ -31,7 +34,7 @@ import {
updatePlaylistSongsLg, updatePlaylistSongsLg,
} from './api'; } from './api';
import { getPlaylist as jfGetPlaylist, getPlaylists as jfGetPlaylists } from './jellyfinApi'; import { getPlaylist as jfGetPlaylist, getPlaylists as jfGetPlaylists } from './jellyfinApi';
import { APIEndpoints, ServerType } from './types'; import { APIEndpoints, ServerType } from '../types';
// prettier-ignore // prettier-ignore
const endpoints = [ const endpoints = [
@ -51,6 +54,7 @@ const endpoints = [
{ id: 'unstar', endpoint: { subsonic: unstar, jellyfin: undefined } }, { id: 'unstar', endpoint: { subsonic: unstar, jellyfin: undefined } },
{ id: 'batchStar', endpoint: { subsonic: batchStar, jellyfin: undefined } }, { id: 'batchStar', endpoint: { subsonic: batchStar, jellyfin: undefined } },
{ id: 'batchUnstar', endpoint: { subsonic: batchUnstar, jellyfin: undefined } }, { id: 'batchUnstar', endpoint: { subsonic: batchUnstar, jellyfin: undefined } },
{ id: 'setRating', endpoint: { subsonic: setRating, jellyfin: undefined } },
{ id: 'getSimilarSongs', endpoint: { subsonic: getSimilarSongs, jellyfin: undefined } }, { id: 'getSimilarSongs', endpoint: { subsonic: getSimilarSongs, jellyfin: undefined } },
{ id: 'updatePlaylistSongs', endpoint: { subsonic: updatePlaylistSongs, jellyfin: undefined } }, { id: 'updatePlaylistSongs', endpoint: { subsonic: updatePlaylistSongs, jellyfin: undefined } },
{ id: 'updatePlaylistSongsLg', endpoint: { subsonic: updatePlaylistSongsLg, jellyfin: undefined } }, { id: 'updatePlaylistSongsLg', endpoint: { subsonic: updatePlaylistSongsLg, jellyfin: undefined } },
@ -60,10 +64,12 @@ const endpoints = [
{ id: 'clearPlaylist', endpoint: { subsonic: clearPlaylist, jellyfin: undefined } }, { id: 'clearPlaylist', endpoint: { subsonic: clearPlaylist, jellyfin: undefined } },
{ id: 'getGenres', endpoint: { subsonic: getGenres, jellyfin: undefined } }, { id: 'getGenres', endpoint: { subsonic: getGenres, jellyfin: undefined } },
{ id: 'getSearch', endpoint: { subsonic: getSearch, jellyfin: undefined } }, { id: 'getSearch', endpoint: { subsonic: getSearch, jellyfin: undefined } },
{ id: 'scrobble', endpoint: { subsonic: scrobble, jellyfin: undefined } },
{ id: 'getIndexes', endpoint: { subsonic: getIndexes, jellyfin: undefined } }, { id: 'getIndexes', endpoint: { subsonic: getIndexes, jellyfin: undefined } },
{ id: 'getMusicFolders', endpoint: { subsonic: getMusicFolders, jellyfin: undefined } }, { id: 'getMusicFolders', endpoint: { subsonic: getMusicFolders, jellyfin: undefined } },
{ id: 'getMusicDirectory', endpoint: { subsonic: getMusicDirectory, jellyfin: undefined } }, { id: 'getMusicDirectory', endpoint: { subsonic: getMusicDirectory, jellyfin: undefined } },
{ id: 'getMusicDirectorySongs', endpoint: { subsonic: getMusicDirectorySongs, jellyfin: undefined } }, { id: 'getMusicDirectorySongs', endpoint: { subsonic: getMusicDirectorySongs, jellyfin: undefined } },
{ id: 'getDownloadUrl', endpoint: { subsonic: getDownloadUrl, jellyfin: undefined } },
]; ];
export const apiController = async (options: { export const apiController = async (options: {
@ -71,14 +77,13 @@ export const apiController = async (options: {
endpoint: APIEndpoints; endpoint: APIEndpoints;
args?: any; args?: any;
}) => { }) => {
const selectedEndpoint = endpoints.find((e) => e.id === options.endpoint)?.endpoint[ const selectedEndpoint = endpoints.find((e) => e.id === options.endpoint);
options.serverType const selectedEndpointFn = selectedEndpoint!.endpoint[options.serverType];
];
if (!selectedEndpoint) { if (!selectedEndpointFn || !selectedEndpoint) {
return notifyToast('warning', `[${options.endpoint}] not available`); return notifyToast('warning', `[${options.endpoint}] not available`);
} }
const res = await selectedEndpoint(options.args); const res = await selectedEndpointFn(options.args);
return res; return res;
}; };

2
src/api/jellyfinApi.ts

@ -3,7 +3,7 @@ import _ from 'lodash';
import { nanoid } from 'nanoid/non-secure'; import { nanoid } from 'nanoid/non-secure';
import { handleDisconnect } from '../components/settings/DisconnectButton'; import { handleDisconnect } from '../components/settings/DisconnectButton';
import { notifyToast } from '../components/shared/toast'; import { notifyToast } from '../components/shared/toast';
import { Item } from './types'; import { Item } from '../types';
const getAuth = () => { const getAuth = () => {
return { return {

2
src/redux/configSlice.ts

@ -3,7 +3,7 @@ import { createSlice, PayloadAction } from '@reduxjs/toolkit';
import settings from 'electron-settings'; import settings from 'electron-settings';
import { mockSettings } from '../shared/mockSettings'; import { mockSettings } from '../shared/mockSettings';
import { moveSelectedToIndex } from '../shared/utils'; 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(); const parsedSettings: any = process.env.NODE_ENV === 'test' ? mockSettings : settings.getSync();

39
src/api/types.ts → src/types.ts

@ -13,7 +13,44 @@ export enum Item {
} }
export type ServerType = Server.Subsonic | Server.Jellyfin; 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 { export interface Album {
id: string; id: string;
Loading…
Cancel
Save