Browse Source

Add jellyfin scan status

master
jeffvli 3 years ago
committed by Jeff
parent
commit
16fa410456
  1. 13
      src/api/api.ts
  2. 6
      src/api/controller.ts
  3. 24
      src/api/jellyfinApi.ts
  4. 7
      src/components/settings/Config.tsx
  5. 5
      src/types.ts

13
src/api/api.ts

@ -281,6 +281,13 @@ const normalizeFolder = (item: any) => {
}; };
}; };
const normalizeScanStatus = (item: any) => {
return {
scanning: item.scanning,
count: item.count,
};
};
export const getPlaylist = async (options: { id: string }) => { export const getPlaylist = async (options: { id: string }) => {
const { data } = await api.get(`/getPlaylist?id=${options.id}`); const { data } = await api.get(`/getPlaylist?id=${options.id}`);
return normalizePlaylist(data.playlist); return normalizePlaylist(data.playlist);
@ -424,14 +431,12 @@ export const getArtistSongs = async (options: { id: string }) => {
export const startScan = async () => { export const startScan = async () => {
const { data } = await api.get(`/startScan`); const { data } = await api.get(`/startScan`);
const scanStatus = data?.scanStatus; return normalizeScanStatus(data.scanStatus);
return scanStatus;
}; };
export const getScanStatus = async () => { export const getScanStatus = async () => {
const { data } = await api.get(`/getScanStatus`); const { data } = await api.get(`/getScanStatus`);
const scanStatus = data?.scanStatus; return normalizeScanStatus(data.scanStatus);
return scanStatus;
}; };
export const star = async (options: { id: string; type: string }) => { export const star = async (options: { id: string; type: string }) => {

6
src/api/controller.ts

@ -51,6 +51,8 @@ import {
getMusicFolders as jfGetMusicFolders, getMusicFolders as jfGetMusicFolders,
getSearch as jfGetSearch, getSearch as jfGetSearch,
scrobble as jfScrobble, scrobble as jfScrobble,
startScan as jfStartScan,
getScanStatus as jfGetScanStatus,
} from './jellyfinApi'; } from './jellyfinApi';
import { APIEndpoints, ServerType } from '../types'; import { APIEndpoints, ServerType } from '../types';
@ -65,8 +67,8 @@ const endpoints = [
{ id: 'getArtist', endpoint: { subsonic: getArtist, jellyfin: jfGetArtist } }, { id: 'getArtist', endpoint: { subsonic: getArtist, jellyfin: jfGetArtist } },
{ id: 'getArtists', endpoint: { subsonic: getArtists, jellyfin: jfGetArtists } }, { id: 'getArtists', endpoint: { subsonic: getArtists, jellyfin: jfGetArtists } },
{ id: 'getArtistSongs', endpoint: { subsonic: getArtistSongs, jellyfin: jfGetArtistSongs } }, { id: 'getArtistSongs', endpoint: { subsonic: getArtistSongs, jellyfin: jfGetArtistSongs } },
{ id: 'startScan', endpoint: { subsonic: startScan, jellyfin: undefined } }, { id: 'startScan', endpoint: { subsonic: startScan, jellyfin: jfStartScan } },
{ id: 'getScanStatus', endpoint: { subsonic: getScanStatus, jellyfin: undefined } }, { id: 'getScanStatus', endpoint: { subsonic: getScanStatus, jellyfin: jfGetScanStatus } },
{ id: 'star', endpoint: { subsonic: star, jellyfin: jfStar } }, { id: 'star', endpoint: { subsonic: star, jellyfin: jfStar } },
{ id: 'unstar', endpoint: { subsonic: unstar, jellyfin: jfUnstar } }, { id: 'unstar', endpoint: { subsonic: unstar, jellyfin: jfUnstar } },
{ id: 'batchStar', endpoint: { subsonic: batchStar, jellyfin: jfBatchStar } }, { id: 'batchStar', endpoint: { subsonic: batchStar, jellyfin: jfBatchStar } },

24
src/api/jellyfinApi.ts

@ -198,6 +198,13 @@ const normalizeFolder = (item: any) => {
}; };
}; };
const normalizeScanStatus = () => {
return {
scanning: false,
count: 'N/a',
};
};
export const getPlaylist = async (options: { id: string }) => { export const getPlaylist = async (options: { id: string }) => {
const { data } = await jellyfinApi.get(`/Items`, { const { data } = await jellyfinApi.get(`/Items`, {
params: { params: {
@ -512,3 +519,20 @@ export const scrobble = async (options: {
PositionTicks: options.position, PositionTicks: options.position,
}); });
}; };
export const startScan = async (options: { musicFolderId?: string }) => {
if (options.musicFolderId) {
return jellyfinApi.post(`/items/${options.musicFolderId}/refresh`, {
Recursive: true,
ImageRefreshMode: 'Default',
ReplaceAllImages: false,
ReplaceAllMetadata: false,
});
}
return jellyfinApi.post(`/library/refresh`);
};
export const getScanStatus = async () => {
return normalizeScanStatus();
};

7
src/components/settings/Config.tsx

@ -24,6 +24,7 @@ const GITHUB_RELEASE_URL = 'https://api.github.com/repos/jeffvli/sonixd/releases
const Config = () => { const Config = () => {
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
const config = useAppSelector((state) => state.config); const config = useAppSelector((state) => state.config);
const folder = useAppSelector((state) => state.folder);
const [isScanning, setIsScanning] = useState(false); const [isScanning, setIsScanning] = useState(false);
const [scanProgress, setScanProgress] = useState(0); const [scanProgress, setScanProgress] = useState(0);
const [latestRelease, setLatestRelease] = useState(packageJson.version); const [latestRelease, setLatestRelease] = useState(packageJson.version);
@ -125,7 +126,11 @@ const Config = () => {
<StyledButton <StyledButton
size="sm" size="sm"
onClick={async () => { onClick={async () => {
apiController({ serverType: config.serverType, endpoint: 'startScan' }); apiController({
serverType: config.serverType,
endpoint: 'startScan',
args: { musicFolderId: folder.musicFolder },
});
setIsScanning(true); setIsScanning(true);
}} }}
disabled={isScanning} disabled={isScanning}

5
src/types.ts

@ -160,3 +160,8 @@ export interface Song {
type: Item.Music; type: Item.Music;
uniqueId: string; uniqueId: string;
} }
export interface ScanStatus {
scanning: boolean;
count: number | 'N/a';
}

Loading…
Cancel
Save