add scan listener and query invalidation on tag editor save

This commit is contained in:
jeffvli
2026-07-19 21:03:13 -07:00
parent e62242824d
commit 173efa9bfd
17 changed files with 326 additions and 5 deletions
+12
View File
@@ -612,6 +612,18 @@ export const controller: GeneralController = {
server.type,
)?.(addContext({ ...args, apiClientProps: { ...args.apiClientProps, server } }));
},
getScanStatus(args) {
const server = getServerById(args.apiClientProps.serverId);
if (!server) {
throw new Error(`${i18n.t('error.apiRouteError')}: getScanStatus`);
}
return apiController(
'getScanStatus',
server.type,
)?.(addContext({ ...args, apiClientProps: { ...args.apiClientProps, server } }));
},
getServerInfo(args) {
const server = getServerById(args.apiClientProps.serverId);
@@ -206,6 +206,14 @@ export const contract = c.router({
400: jfType._response.error,
},
},
getScheduledTasks: {
method: 'GET',
path: 'ScheduledTasks',
responses: {
200: jfType._response.scheduledTasks,
400: jfType._response.error,
},
},
getServerInfo: {
method: 'GET',
path: 'system/info',
@@ -1161,6 +1161,34 @@ export const JellyfinController: InternalControllerEndpoint = {
};
},
getRoles: async () => [],
getScanStatus: async (args) => {
const { apiClientProps } = args;
const res = await jfApiClient(apiClientProps).getScheduledTasks();
if (res.status !== 200) {
throw new Error('Failed to get scan status');
}
const task =
res.body.find((t) => t.Key === 'RefreshLibrary') ||
res.body.find((t) => t.Name === 'Scan Media Library');
if (!task) {
return {
count: 0,
folderCount: 0,
scanning: false,
};
}
return {
count: 0,
folderCount: 0,
lastScan: task.LastExecutionResult?.EndTimeUtc ?? undefined,
scanning: task.State === 'Running' || task.State === 'Cancelling',
};
},
getServerInfo: async (args) => {
const { apiClientProps } = args;
@@ -723,6 +723,7 @@ export const NavidromeController: InternalControllerEndpoint = {
getRandomSongList: SubsonicController.getRandomSongList,
getRoles: async ({ apiClientProps }) =>
hasFeature(apiClientProps.server, ServerFeature.BFR) ? NAVIDROME_ROLES : [],
getScanStatus: SubsonicController.getScanStatus,
getServerInfo: async (args) => {
const { apiClientProps } = args;
+1
View File
@@ -363,6 +363,7 @@ export const queryKeys: Record<
},
server: {
root: (serverId: string) => [serverId] as const,
scanStatus: (serverId: string) => [serverId, 'server', 'scanStatus'] as const,
},
songs: {
albumRadio: (serverId: string, query?: AlbumRadioQuery) => {
@@ -1355,6 +1355,22 @@ export const SubsonicController: InternalControllerEndpoint = {
final.splice(0, 0, { label: 'all artists', value: '' });
return final;
},
getScanStatus: async (args) => {
const { apiClientProps } = args;
const res = await ssApiClient(apiClientProps).getScanStatus({ query: {} });
if (res.status !== 200) {
throw new Error('Failed to get scan status');
}
return {
count: res.body.scanStatus.count,
folderCount: res.body.scanStatus.folderCount,
lastScan: res.body.scanStatus.lastScan,
scanning: res.body.scanStatus.scanning,
};
},
getServerInfo: async (args) => {
const { apiClientProps } = args;