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 App from '../App';
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 mockStore = configureMockStore(middlewares);

8
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}` +

17
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;
};

2
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 {

2
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();

39
src/api/types.ts → 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;
Loading…
Cancel
Save