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"]],
|
||||
iconUrl: "https://cdn.jsdelivr.net/gh/selfhst/icons/png/dawarich.png",
|
||||
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)
|
||||
mock: {
|
||||
@@ -624,7 +624,7 @@ export const integrationCategories = [
|
||||
"documents",
|
||||
"mediaLibrary",
|
||||
"uptimeMonitoring",
|
||||
"geolocationTracking"
|
||||
"geolocationTracking",
|
||||
] as const;
|
||||
|
||||
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 { UnraidIntegration } from "../unraid/unraid-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>(
|
||||
integration: IntegrationInput & { kind: TKind },
|
||||
@@ -144,7 +144,7 @@ export const integrationCreators = {
|
||||
uptimeKuma: UptimeKumaIntegration,
|
||||
peaNut: PeaNutIntegration,
|
||||
beszel: BeszelIntegration,
|
||||
dawarich: DawarichIntegration
|
||||
dawarich: DawarichIntegration,
|
||||
} satisfies Record<IntegrationKind, IntegrationInstance | [(input: IntegrationInput) => Promise<Integration>]>;
|
||||
|
||||
type IntegrationInstanceOfKind<TKind extends keyof typeof integrationCreators> = {
|
||||
|
||||
@@ -1,53 +1,52 @@
|
||||
import {fetchWithTrustedCertificatesAsync} from "@homarr/core/infrastructure/http";
|
||||
import {ResponseError} from "@homarr/common/server";
|
||||
import {Integration, IntegrationInput, IntegrationTestingInput} from "../base/integration";
|
||||
import {dawarichPlacesSchema, dawarichStatisticsSchema} from "./dawarich-schemas";
|
||||
import {z} from "zod/v4";
|
||||
import {TestingResult} from "../base/test-connection/test-connection-service";
|
||||
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
||||
import { ResponseError } from "@homarr/common/server";
|
||||
import type { IntegrationInput, IntegrationTestingInput } from "../base/integration";
|
||||
import { Integration } from "../base/integration";
|
||||
import { dawarichPlacesSchema, dawarichStatisticsSchema } from "./dawarich-schemas";
|
||||
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";
|
||||
|
||||
export class DawarichIntegration extends Integration {
|
||||
constructor(integration: IntegrationInput) {
|
||||
super(integration);
|
||||
constructor(integration: IntegrationInput) {
|
||||
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> {
|
||||
const response = await fetchWithTrustedCertificatesAsync(this.url(`/api/v1/users/me`), {
|
||||
headers: {Authorization: `Bearer ${this.getSecretValue('apiKey')}`},
|
||||
});
|
||||
return TestConnectionError.StatusResult(response);
|
||||
}
|
||||
|
||||
if (response.status === 200) {
|
||||
return { success: true };
|
||||
}
|
||||
async getStatisticsAsync(): Promise<{
|
||||
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<{
|
||||
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 dawarichStatisticsSchema.parseAsync(await response.json());
|
||||
}
|
||||
|
||||
if (!response.ok)
|
||||
throw new ResponseError(response);
|
||||
async getPlacesAsync(): Promise<z.infer<typeof dawarichPlacesSchema>> {
|
||||
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>> {
|
||||
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());
|
||||
}
|
||||
}
|
||||
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({
|
||||
"totalDistanceKm": z.number(),
|
||||
"totalPointsTracked": z.number(),
|
||||
"totalReverseGeocodedPoints": z.number(),
|
||||
"totalCountriesVisited": z.number(),
|
||||
"totalCitiesVisited": z.number()
|
||||
totalDistanceKm: z.number(),
|
||||
totalPointsTracked: z.number(),
|
||||
totalReverseGeocodedPoints: z.number(),
|
||||
totalCountriesVisited: z.number(),
|
||||
totalCitiesVisited: z.number(),
|
||||
});
|
||||
|
||||
export const dawarichPlacesSchema = z.array(z.object({
|
||||
|
||||
"id": z.number(),
|
||||
"name": z.string(),
|
||||
"latitude": z.number(),
|
||||
"longitude": z.number(),
|
||||
"source": z.string().optional(),
|
||||
"icon": z.string().nullable(),
|
||||
"color": z.string().nullable(),
|
||||
"visits_count": z.number(),
|
||||
"created_at": "2024-07-29T15:51:28.071Z",
|
||||
"tags": [
|
||||
{
|
||||
"id": z.number(),
|
||||
"name": z.string(),
|
||||
"icon": z.string(),
|
||||
"color": z.string()
|
||||
}
|
||||
]
|
||||
}));
|
||||
export const dawarichPlacesSchema = z.array(
|
||||
z.object({
|
||||
id: z.number(),
|
||||
name: z.string(),
|
||||
latitude: z.number(),
|
||||
longitude: z.number(),
|
||||
source: z.string().optional(),
|
||||
icon: z.string().nullable(),
|
||||
color: z.string().nullable(),
|
||||
visits_count: z.number(),
|
||||
created_at: "2024-07-29T15:51:28.071Z",
|
||||
tags: [
|
||||
{
|
||||
id: z.number(),
|
||||
name: z.string(),
|
||||
icon: z.string(),
|
||||
color: z.string(),
|
||||
},
|
||||
],
|
||||
}),
|
||||
);
|
||||
Reference in new issue
Block a user