diff --git a/src/api/api.ts b/src/api/api.ts index 0b997a9..8c4bdb1 100644 --- a/src/api/api.ts +++ b/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 }) => { const { data } = await api.get(`/getPlaylist?id=${options.id}`); return normalizePlaylist(data.playlist); @@ -424,14 +431,12 @@ export const getArtistSongs = async (options: { id: string }) => { export const startScan = async () => { const { data } = await api.get(`/startScan`); - const scanStatus = data?.scanStatus; - return scanStatus; + return normalizeScanStatus(data.scanStatus); }; export const getScanStatus = async () => { const { data } = await api.get(`/getScanStatus`); - const scanStatus = data?.scanStatus; - return scanStatus; + return normalizeScanStatus(data.scanStatus); }; export const star = async (options: { id: string; type: string }) => { diff --git a/src/api/controller.ts b/src/api/controller.ts index 47df606..da1029a 100644 --- a/src/api/controller.ts +++ b/src/api/controller.ts @@ -51,6 +51,8 @@ import { getMusicFolders as jfGetMusicFolders, getSearch as jfGetSearch, scrobble as jfScrobble, + startScan as jfStartScan, + getScanStatus as jfGetScanStatus, } from './jellyfinApi'; import { APIEndpoints, ServerType } from '../types'; @@ -65,8 +67,8 @@ const endpoints = [ { id: 'getArtist', endpoint: { subsonic: getArtist, jellyfin: jfGetArtist } }, { id: 'getArtists', endpoint: { subsonic: getArtists, jellyfin: jfGetArtists } }, { id: 'getArtistSongs', endpoint: { subsonic: getArtistSongs, jellyfin: jfGetArtistSongs } }, - { id: 'startScan', endpoint: { subsonic: startScan, jellyfin: undefined } }, - { id: 'getScanStatus', endpoint: { subsonic: getScanStatus, jellyfin: undefined } }, + { id: 'startScan', endpoint: { subsonic: startScan, jellyfin: jfStartScan } }, + { id: 'getScanStatus', endpoint: { subsonic: getScanStatus, jellyfin: jfGetScanStatus } }, { id: 'star', endpoint: { subsonic: star, jellyfin: jfStar } }, { id: 'unstar', endpoint: { subsonic: unstar, jellyfin: jfUnstar } }, { id: 'batchStar', endpoint: { subsonic: batchStar, jellyfin: jfBatchStar } }, diff --git a/src/api/jellyfinApi.ts b/src/api/jellyfinApi.ts index e97b5e0..f4036a5 100644 --- a/src/api/jellyfinApi.ts +++ b/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 }) => { const { data } = await jellyfinApi.get(`/Items`, { params: { @@ -512,3 +519,20 @@ export const scrobble = async (options: { 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(); +}; diff --git a/src/components/settings/Config.tsx b/src/components/settings/Config.tsx index cf8c45b..8ea93a3 100644 --- a/src/components/settings/Config.tsx +++ b/src/components/settings/Config.tsx @@ -24,6 +24,7 @@ const GITHUB_RELEASE_URL = 'https://api.github.com/repos/jeffvli/sonixd/releases const Config = () => { const dispatch = useAppDispatch(); const config = useAppSelector((state) => state.config); + const folder = useAppSelector((state) => state.folder); const [isScanning, setIsScanning] = useState(false); const [scanProgress, setScanProgress] = useState(0); const [latestRelease, setLatestRelease] = useState(packageJson.version); @@ -125,7 +126,11 @@ const Config = () => { { - apiController({ serverType: config.serverType, endpoint: 'startScan' }); + apiController({ + serverType: config.serverType, + endpoint: 'startScan', + args: { musicFolderId: folder.musicFolder }, + }); setIsScanning(true); }} disabled={isScanning} diff --git a/src/types.ts b/src/types.ts index e6d8957..79dd5e3 100644 --- a/src/types.ts +++ b/src/types.ts @@ -160,3 +160,8 @@ export interface Song { type: Item.Music; uniqueId: string; } + +export interface ScanStatus { + scanning: boolean; + count: number | 'N/a'; +}