) {
+ const record: ServiceRecord = {
+ poll: service.poll || pollURL,
+ config: service.config || {}
+ };
+
+ services[type] = record;
+}
+
+//eslint-disable-next-line @typescript-eslint/no-explicit-any
function registerComponent(type: string, component: any) {
components[type] = component;
}
-export function getServiceHandler(type: string): ServiceHandler | undefined {
- return services[type];
+export function getServiceRecord(type: string): ServiceRecord {
+ return services[type] || { poll: pollURL, config: {} };
}
+//eslint-disable-next-line @typescript-eslint/no-explicit-any
export function getServiceComponent(type: string): any {
return components[type];
}
@@ -25,12 +49,13 @@ export async function initServices() {
for (const [modulePath, load] of Object.entries(services)) {
try {
- const { handle } = (await load()) as any;
- if (handle == undefined) {
- throw new Error(`${modulePath} does not export 'handle'`);
+ //eslint-disable-next-line @typescript-eslint/no-explicit-any
+ const { poll, config } = (await load()) as any;
+ if (poll == undefined && config == undefined) {
+ throw new Error(`${modulePath} does not export 'poll' or 'config'`);
}
const typeName = modulePath.slice(18, -12);
- registerService(typeName, handle);
+ registerService(typeName, { poll, config });
} catch (err) {
console.error(`Could not load service definition from '${modulePath}': ${err}`);
}
@@ -42,6 +67,7 @@ export async function initComponents() {
for (const [componentPath, load] of Object.entries(services)) {
try {
+ //eslint-disable-next-line @typescript-eslint/no-explicit-any
const module = (await load()) as any;
if (module == undefined) {
diff --git a/src/lib/services/sonarr/+content.svelte b/src/lib/services/sonarr/+content.svelte
index b7895de..473d34a 100644
--- a/src/lib/services/sonarr/+content.svelte
+++ b/src/lib/services/sonarr/+content.svelte
@@ -1,8 +1,8 @@
diff --git a/src/lib/services/sonarr/+service.ts b/src/lib/services/sonarr/+service.ts
index 7f93155..a19fa3e 100644
--- a/src/lib/services/sonarr/+service.ts
+++ b/src/lib/services/sonarr/+service.ts
@@ -1,11 +1,12 @@
import type { ServiceConfig } from '$lib/config';
-import type { ServiceHandler } from '../service';
+import type { ServicePoller, ServiceStatus } from '../service';
interface Status {
warnings: number;
errors: number;
}
+//eslint-disable-next-line @typescript-eslint/no-explicit-any
function buildStatus(statuses: any[]): Status {
let warnings = 0;
let errors = 0;
@@ -26,6 +27,8 @@ interface Queue {
nextDate?: Date;
total: number;
}
+
+//eslint-disable-next-line @typescript-eslint/no-explicit-any
function recordEstimatedCompletionTime(record: any): number {
if (record.estimatedCompletionTime == undefined) {
return Infinity;
@@ -33,6 +36,7 @@ function recordEstimatedCompletionTime(record: any): number {
return new Date(record.estimatedCompletionTime).getTime();
}
+//eslint-disable-next-line @typescript-eslint/no-explicit-any
function buildQueue(queue: any): Queue {
if (queue?.records?.length === 0) {
return { total: 0 };
@@ -51,12 +55,13 @@ function buildQueue(queue: any): Queue {
};
}
-export const handle: ServiceHandler = async (config: ServiceConfig) => {
- const res = {
- logo: 'https://cdn.rawgit.com/Sonarr/Sonarr/develop/Logo/Sonarr.svg',
- subtitle: 'TV Show tracker'
- };
+export const config: Partial = {
+ title: 'Sonarr',
+ logo: 'https://cdn.rawgit.com/Sonarr/Sonarr/develop/Logo/Sonarr.svg',
+ subtitle: 'TV Show tracker'
+};
+export const poll: ServicePoller = async (config: ServiceConfig) => {
const params = '?apikey=' + config.api_key;
const requests = [
@@ -65,21 +70,22 @@ export const handle: ServiceHandler = async (config: ServiceConfig) => {
];
const [health, queue] = await Promise.allSettled(requests);
- res.status = 'online';
+ let status: ServiceStatus = 'online';
+ const data: Record = {};
if (health.status != 'fulfilled') {
- console.warn("Could not fetch '" + config.url + "' status: " + health.value);
- res.status = 'offline';
+ console.warn("Could not fetch '" + config.url + "' status: " + health.reason);
+ status = 'offline';
} else if (health.value.ok == true) {
- res.health = buildStatus(await health.value.json());
+ data.health = buildStatus(await health.value.json());
}
if (queue.status != 'fulfilled') {
- console.warn("Could not fetch '" + config.url + "' queue: " + queue.value);
- res.status = 'offline';
+ console.warn("Could not fetch '" + config.url + "' queue: " + queue.reason);
+ data.status = 'offline';
} else if (queue.value.ok == true) {
- res.queue = buildQueue(await queue.value.json());
+ data.queue = buildQueue(await queue.value.json());
}
- return res;
+ return { status, data };
};
diff --git a/static/config.yml b/static/config.yml
deleted file mode 100644
index de9dbac..0000000
--- a/static/config.yml
+++ /dev/null
@@ -1,14 +0,0 @@
-title: 'Hello World !!'
-subtitle: 'actually, I am a new pilot.'
-
-services:
- - title: '/Cloud'
- subtitle: 'Private Cloud Utilities'
- icon: 'fas fa-cloud'
- items:
- - title: 'NAS'
- subtitle: 'Network Attached Storage'
- icon: 'fas fa-hard-drive'
- target: '_blank'
- url: '/NAS'
- keywords: 'cloud storage files'