style: auto-fix lint and format
This commit is contained in:
1 parent
629f3b0955
commit
973baedfcb
4 files changed
+72
-72
No files matched your search
@@ -509,7 +509,7 @@ export const integrationDefs = {
|
|||||||
secretKinds: [["apiKey"]],
|
secretKinds: [["apiKey"]],
|
||||||
iconUrl: "https://cdn.jsdelivr.net/gh/selfhst/icons/png/dawarich.png",
|
iconUrl: "https://cdn.jsdelivr.net/gh/selfhst/icons/png/dawarich.png",
|
||||||
category: ["geolocationTracking"],
|
category: ["geolocationTracking"],
|
||||||
documentationUrl: createDocumentationLink("/docs/integrations/dawarich")
|
documentationUrl: createDocumentationLink("/docs/integrations/dawarich"),
|
||||||
},
|
},
|
||||||
// This integration only returns mock data, it is used during development (but can also be used in production by directly going to the create page)
|
// This integration only returns mock data, it is used during development (but can also be used in production by directly going to the create page)
|
||||||
mock: {
|
mock: {
|
||||||
@@ -624,7 +624,7 @@ export const integrationCategories = [
|
|||||||
"documents",
|
"documents",
|
||||||
"mediaLibrary",
|
"mediaLibrary",
|
||||||
"uptimeMonitoring",
|
"uptimeMonitoring",
|
||||||
"geolocationTracking"
|
"geolocationTracking",
|
||||||
] as const;
|
] as const;
|
||||||
|
|
||||||
export type IntegrationCategory = (typeof integrationCategories)[number];
|
export type IntegrationCategory = (typeof integrationCategories)[number];
|
||||||
@@ -60,7 +60,7 @@ import { UptimeKumaIntegration } from "../uptime-kuma/uptime-kuma-integration";
|
|||||||
import { UnifiControllerIntegration } from "../unifi-controller/unifi-controller-integration";
|
import { UnifiControllerIntegration } from "../unifi-controller/unifi-controller-integration";
|
||||||
import { UnraidIntegration } from "../unraid/unraid-integration";
|
import { UnraidIntegration } from "../unraid/unraid-integration";
|
||||||
import type { Integration, IntegrationInput } from "./integration";
|
import type { Integration, IntegrationInput } from "./integration";
|
||||||
import {DawarichIntegration} from "../dawarich/dawarich-integration";
|
import { DawarichIntegration } from "../dawarich/dawarich-integration";
|
||||||
|
|
||||||
export const createIntegrationAsync = async <TKind extends keyof typeof integrationCreators>(
|
export const createIntegrationAsync = async <TKind extends keyof typeof integrationCreators>(
|
||||||
integration: IntegrationInput & { kind: TKind },
|
integration: IntegrationInput & { kind: TKind },
|
||||||
@@ -144,7 +144,7 @@ export const integrationCreators = {
|
|||||||
uptimeKuma: UptimeKumaIntegration,
|
uptimeKuma: UptimeKumaIntegration,
|
||||||
peaNut: PeaNutIntegration,
|
peaNut: PeaNutIntegration,
|
||||||
beszel: BeszelIntegration,
|
beszel: BeszelIntegration,
|
||||||
dawarich: DawarichIntegration
|
dawarich: DawarichIntegration,
|
||||||
} satisfies Record<IntegrationKind, IntegrationInstance | [(input: IntegrationInput) => Promise<Integration>]>;
|
} satisfies Record<IntegrationKind, IntegrationInstance | [(input: IntegrationInput) => Promise<Integration>]>;
|
||||||
|
|
||||||
type IntegrationInstanceOfKind<TKind extends keyof typeof integrationCreators> = {
|
type IntegrationInstanceOfKind<TKind extends keyof typeof integrationCreators> = {
|
||||||
|
|||||||
@@ -1,53 +1,52 @@
|
|||||||
import {fetchWithTrustedCertificatesAsync} from "@homarr/core/infrastructure/http";
|
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
||||||
import {ResponseError} from "@homarr/common/server";
|
import { ResponseError } from "@homarr/common/server";
|
||||||
import {Integration, IntegrationInput, IntegrationTestingInput} from "../base/integration";
|
import type { IntegrationInput, IntegrationTestingInput } from "../base/integration";
|
||||||
import {dawarichPlacesSchema, dawarichStatisticsSchema} from "./dawarich-schemas";
|
import { Integration } from "../base/integration";
|
||||||
import {z} from "zod/v4";
|
import { dawarichPlacesSchema, dawarichStatisticsSchema } from "./dawarich-schemas";
|
||||||
import {TestingResult} from "../base/test-connection/test-connection-service";
|
import type { z } from "zod/v4";
|
||||||
|
import type { TestingResult } from "../base/test-connection/test-connection-service";
|
||||||
import { TestConnectionError } from "../base/test-connection/test-connection-error";
|
import { TestConnectionError } from "../base/test-connection/test-connection-error";
|
||||||
|
|
||||||
export class DawarichIntegration extends Integration {
|
export class DawarichIntegration extends Integration {
|
||||||
constructor(integration: IntegrationInput) {
|
constructor(integration: IntegrationInput) {
|
||||||
super(integration);
|
super(integration);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async testingAsync(input: IntegrationTestingInput): Promise<TestingResult> {
|
||||||
|
const response = await fetchWithTrustedCertificatesAsync(this.url(`/api/v1/users/me`), {
|
||||||
|
headers: { Authorization: `Bearer ${this.getSecretValue("apiKey")}` },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.status === 200) {
|
||||||
|
return { success: true };
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async testingAsync(input: IntegrationTestingInput): Promise<TestingResult> {
|
return TestConnectionError.StatusResult(response);
|
||||||
const response = await fetchWithTrustedCertificatesAsync(this.url(`/api/v1/users/me`), {
|
}
|
||||||
headers: {Authorization: `Bearer ${this.getSecretValue('apiKey')}`},
|
|
||||||
});
|
|
||||||
|
|
||||||
if (response.status === 200) {
|
async getStatisticsAsync(): Promise<{
|
||||||
return { success: true };
|
totalDistanceKm: number;
|
||||||
}
|
totalPointsTracked: number;
|
||||||
|
totalReverseGeocodedPoints: number;
|
||||||
|
totalCountriesVisited: number;
|
||||||
|
totalCitiesVisited: number;
|
||||||
|
}> {
|
||||||
|
const response = await fetchWithTrustedCertificatesAsync(this.url("/api/v1/stats"), {
|
||||||
|
headers: { Authorization: `Bearer ${this.getSecretValue("apiKey")}` },
|
||||||
|
});
|
||||||
|
|
||||||
return TestConnectionError.StatusResult(response);
|
if (!response.ok) throw new ResponseError(response);
|
||||||
}
|
|
||||||
|
|
||||||
async getStatisticsAsync(): Promise<{
|
return dawarichStatisticsSchema.parseAsync(await response.json());
|
||||||
totalDistanceKm: number,
|
}
|
||||||
totalPointsTracked: number,
|
|
||||||
totalReverseGeocodedPoints: number,
|
|
||||||
totalCountriesVisited: number,
|
|
||||||
totalCitiesVisited: number
|
|
||||||
}> {
|
|
||||||
const response = await fetchWithTrustedCertificatesAsync(this.url('/api/v1/stats'), {
|
|
||||||
headers: {Authorization: `Bearer ${this.getSecretValue('apiKey')}`},
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!response.ok)
|
async getPlacesAsync(): Promise<z.infer<typeof dawarichPlacesSchema>> {
|
||||||
throw new ResponseError(response);
|
const response = await fetchWithTrustedCertificatesAsync(this.url("/api/v1/places"), {
|
||||||
|
headers: { Authorization: `Bearer ${this.getSecretValue("apiKey")}` },
|
||||||
|
});
|
||||||
|
|
||||||
return dawarichStatisticsSchema.parseAsync(await response.json());
|
if (!response.ok) throw new ResponseError(response);
|
||||||
}
|
|
||||||
|
|
||||||
async getPlacesAsync(): Promise<z.infer<typeof dawarichPlacesSchema>> {
|
return dawarichPlacesSchema.parseAsync(await response.json());
|
||||||
const response = await fetchWithTrustedCertificatesAsync(this.url('/api/v1/places'), {
|
}
|
||||||
headers: {Authorization: `Bearer ${this.getSecretValue('apiKey')}`},
|
}
|
||||||
});
|
|
||||||
|
|
||||||
if (!response.ok)
|
|
||||||
throw new ResponseError(response);
|
|
||||||
|
|
||||||
return dawarichPlacesSchema.parseAsync(await response.json());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,30 +1,31 @@
|
|||||||
import {z} from "zod/v4";
|
import { z } from "zod/v4";
|
||||||
|
|
||||||
export const dawarichStatisticsSchema = z.object({
|
export const dawarichStatisticsSchema = z.object({
|
||||||
"totalDistanceKm": z.number(),
|
totalDistanceKm: z.number(),
|
||||||
"totalPointsTracked": z.number(),
|
totalPointsTracked: z.number(),
|
||||||
"totalReverseGeocodedPoints": z.number(),
|
totalReverseGeocodedPoints: z.number(),
|
||||||
"totalCountriesVisited": z.number(),
|
totalCountriesVisited: z.number(),
|
||||||
"totalCitiesVisited": z.number()
|
totalCitiesVisited: z.number(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const dawarichPlacesSchema = z.array(z.object({
|
export const dawarichPlacesSchema = z.array(
|
||||||
|
z.object({
|
||||||
"id": z.number(),
|
id: z.number(),
|
||||||
"name": z.string(),
|
name: z.string(),
|
||||||
"latitude": z.number(),
|
latitude: z.number(),
|
||||||
"longitude": z.number(),
|
longitude: z.number(),
|
||||||
"source": z.string().optional(),
|
source: z.string().optional(),
|
||||||
"icon": z.string().nullable(),
|
icon: z.string().nullable(),
|
||||||
"color": z.string().nullable(),
|
color: z.string().nullable(),
|
||||||
"visits_count": z.number(),
|
visits_count: z.number(),
|
||||||
"created_at": "2024-07-29T15:51:28.071Z",
|
created_at: "2024-07-29T15:51:28.071Z",
|
||||||
"tags": [
|
tags: [
|
||||||
{
|
{
|
||||||
"id": z.number(),
|
id: z.number(),
|
||||||
"name": z.string(),
|
name: z.string(),
|
||||||
"icon": z.string(),
|
icon: z.string(),
|
||||||
"color": z.string()
|
color: z.string(),
|
||||||
}
|
},
|
||||||
]
|
],
|
||||||
}));
|
}),
|
||||||
|
);
|
||||||
Reference in new issue
Block a user