feat: add Bazarr integration and subtitle status widget (#6156)
Co-authored-by: Thomas <thomas@ajnart.fr>
This commit is contained in:
1 parent
7d93df04dd
commit
2c5368dd4e
28 files changed
+635
No files matched your search
@@ -0,0 +1,45 @@
|
||||
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
||||
|
||||
import type { IntegrationTestingInput } from "../base/integration";
|
||||
import { Integration } from "../base/integration";
|
||||
import { TestConnectionError } from "../base/test-connection/test-connection-error";
|
||||
import type { TestingResult } from "../base/test-connection/test-connection-service";
|
||||
import type { BazarrBadges } from "./bazarr-types";
|
||||
import { bazarrBadgesSchema, bazarrSystemStatusSchema } from "./bazarr-types";
|
||||
|
||||
export class BazarrIntegration extends Integration {
|
||||
protected async testingAsync(input: IntegrationTestingInput): Promise<TestingResult> {
|
||||
const response = await input.fetchAsync(this.url("/api/system/status"), {
|
||||
headers: this.getAuthHeaders(),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
return TestConnectionError.StatusResult(response);
|
||||
}
|
||||
|
||||
bazarrSystemStatusSchema.parse(await response.json());
|
||||
return { success: true };
|
||||
}
|
||||
|
||||
public async getBadgesAsync(): Promise<BazarrBadges> {
|
||||
const response = await fetchWithTrustedCertificatesAsync(this.url("/api/badges"), {
|
||||
headers: this.getAuthHeaders(),
|
||||
timeout: 10000,
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(
|
||||
`Failed to fetch Bazarr badges for ${this.integration.name} (${this.integration.id}): ${response.statusText}`,
|
||||
);
|
||||
}
|
||||
|
||||
return bazarrBadgesSchema.parse(await response.json());
|
||||
}
|
||||
|
||||
private getAuthHeaders(): Record<string, string> {
|
||||
return {
|
||||
"X-API-KEY": this.getSecretValue("apiKey"),
|
||||
Accept: "application/json",
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import { z } from "zod/v4";
|
||||
|
||||
export const bazarrBadgesSchema = z.object({
|
||||
episodes: z.number(),
|
||||
movies: z.number(),
|
||||
providers: z.number(),
|
||||
status: z.number(),
|
||||
sonarr_signalr: z.string(),
|
||||
radarr_signalr: z.string(),
|
||||
announcements: z.number(),
|
||||
});
|
||||
|
||||
export type BazarrBadges = z.infer<typeof bazarrBadgesSchema>;
|
||||
|
||||
export const bazarrSystemStatusSchema = z.object({
|
||||
data: z.object({
|
||||
bazarr_version: z.string(),
|
||||
}),
|
||||
});
|
||||
Reference in new issue
Block a user