Skip to content

Commit

Permalink
feat(jellyfin): More robust connection check and logging
Browse files Browse the repository at this point in the history
  • Loading branch information
FoxxMD committed Dec 10, 2024
1 parent d77e6c6 commit 0f0d1d6
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/backend/sources/JellyfinApiSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,14 @@ import {
// @ts-expect-error weird typings?
getLibraryStructureApi,
// @ts-expect-error weird typings?
getImageApi
getImageApi,

} from "@jellyfin/sdk/lib/utils/api/index.js";
import {
// @ts-expect-error weird typings?
SystemInfoIssue
}
from "@jellyfin/sdk/lib/index.js";
import dayjs from "dayjs";
import EventEmitter from "events";
import { nanoid } from "nanoid";
Expand Down Expand Up @@ -178,7 +184,23 @@ export default class JellyfinApiSource extends MemoryPositionalSource {
protected async doCheckConnection(): Promise<true | string | undefined> {
try {
const servers = await this.client.discovery.getRecommendedServerCandidates(this.config.data.url);
if(servers.length === 0) {
throw new Error(`No servers were parseable from the given Jellyfin URL ${this.config.data.url}`);
}
const best = this.client.discovery.findBestServer(servers);
if(best === undefined) {
for(const s of servers) {
const sysError = s.issues.find(x => x instanceof SystemInfoIssue);
if(sysError !== undefined) {
this.logger.warn(new Error(`Server ${s.address} failed to communicate or something went wrong (SystemInfoIssue)`, {cause: sysError.error}));
} else {
for(const i of s.issues) {
this.logger.warn(`Server ${s.address} has an issue (${i.constructor.name})`)
}
}
}
throw new Error('Unable to determine a valid Server to connect to. See warnings above.');
}
this.api = this.client.createApi(best.address);
this.imageApi = getImageApi(this.api);
this.address = best.address;
Expand Down

0 comments on commit 0f0d1d6

Please sign in to comment.