mirror of
https://github.com/informaticker/discord-jellyfin-bot.git
synced 2024-11-25 02:51:57 +01:00
🐛 Fix crash with undefined id in interaction
This commit is contained in:
parent
14cd54fd7d
commit
50a9b15f09
@ -1,6 +1,3 @@
|
|||||||
import { Injectable } from '@nestjs/common';
|
|
||||||
import { JellyfinService } from './jellyfin.service';
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
BaseItemKind,
|
BaseItemKind,
|
||||||
RemoteImageResult,
|
RemoteImageResult,
|
||||||
@ -10,12 +7,17 @@ import { getItemsApi } from '@jellyfin/sdk/lib/utils/api/items-api';
|
|||||||
import { getPlaylistsApi } from '@jellyfin/sdk/lib/utils/api/playlists-api';
|
import { getPlaylistsApi } from '@jellyfin/sdk/lib/utils/api/playlists-api';
|
||||||
import { getRemoteImageApi } from '@jellyfin/sdk/lib/utils/api/remote-image-api';
|
import { getRemoteImageApi } from '@jellyfin/sdk/lib/utils/api/remote-image-api';
|
||||||
import { getSearchApi } from '@jellyfin/sdk/lib/utils/api/search-api';
|
import { getSearchApi } from '@jellyfin/sdk/lib/utils/api/search-api';
|
||||||
|
|
||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
import { Logger } from '@nestjs/common/services';
|
import { Logger } from '@nestjs/common/services';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
JellyfinAudioPlaylist,
|
JellyfinAudioPlaylist,
|
||||||
JellyfinMusicAlbum,
|
JellyfinMusicAlbum,
|
||||||
} from '../../models/jellyfinAudioItems';
|
} from '../../models/jellyfinAudioItems';
|
||||||
|
|
||||||
|
import { JellyfinService } from './jellyfin.service';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class JellyfinSearchService {
|
export class JellyfinSearchService {
|
||||||
private readonly logger = new Logger(JellyfinSearchService.name);
|
private readonly logger = new Logger(JellyfinSearchService.name);
|
||||||
@ -110,23 +112,31 @@ export class JellyfinSearchService {
|
|||||||
const api = this.jellyfinService.getApi();
|
const api = this.jellyfinService.getApi();
|
||||||
const remoteImageApi = getRemoteImageApi(api);
|
const remoteImageApi = getRemoteImageApi(api);
|
||||||
|
|
||||||
const axiosReponse = await remoteImageApi.getRemoteImages({
|
try {
|
||||||
itemId: id,
|
const axiosReponse = await remoteImageApi.getRemoteImages({
|
||||||
includeAllLanguages: true,
|
itemId: id,
|
||||||
limit: 20,
|
includeAllLanguages: true,
|
||||||
});
|
limit: 20,
|
||||||
|
});
|
||||||
|
|
||||||
if (axiosReponse.status !== 200) {
|
if (axiosReponse.status !== 200) {
|
||||||
this.logger.warn(
|
this.logger.warn(
|
||||||
`Failed to retrieve remote images. Response has status ${axiosReponse.status}`,
|
`Failed to retrieve remote images. Response has status ${axiosReponse.status}`,
|
||||||
);
|
);
|
||||||
|
return {
|
||||||
|
Images: [],
|
||||||
|
Providers: [],
|
||||||
|
TotalRecordCount: 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return axiosReponse.data;
|
||||||
|
} catch (err) {
|
||||||
|
this.logger.error(`Failed to retrieve remote images: ${err}`);
|
||||||
return {
|
return {
|
||||||
Images: [],
|
Images: [],
|
||||||
Providers: [],
|
Providers: [],
|
||||||
TotalRecordCount: 0,
|
TotalRecordCount: 0,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return axiosReponse.data;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -198,6 +198,13 @@ export class PlayItemCommand {
|
|||||||
const type = valueParts[0];
|
const type = valueParts[0];
|
||||||
const id = valueParts[1];
|
const id = valueParts[1];
|
||||||
|
|
||||||
|
if (!id) {
|
||||||
|
this.logger.warn(
|
||||||
|
`Failed because ID could not be extracted from interaction`,
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.logger.debug(
|
this.logger.debug(
|
||||||
`Searching for the content using the values [${interaction.values.join(
|
`Searching for the content using the values [${interaction.values.join(
|
||||||
', ',
|
', ',
|
||||||
|
Loading…
Reference in New Issue
Block a user