feat: add import for config files from oldmarr (#1019)

* wip: add oldmarr config import

* wip: add support for wrong amount of categories / sections with autofix, color mapping, position adjustments of wrappers

* fix: lockfile broken

* feat: add support for form data trpc requests

* wip: improve file upload

* refactor: restructure import, add import configuration

* wip: add configurations for import to modal

* refactor: move oldmarr import to old-import package

* fix: column count not respects screen size for board

* feat: add beta badge for oldmarr config import

* chore: address pull request feedback

* fix: format issues

* fix: inconsistent versions

* fix: deepsource issues

* fix: revert {} to Record<string, never> convertion to prevent typecheck issue

* fix: inconsistent zod version

* fix: format issue

* chore: address pull request feedback

* fix: wrong import

* fix: broken lock file

* fix: inconsistent versions

* fix: format issues
This commit is contained in:
Meier Lukas
2024-09-07 18:13:24 +02:00
committed by GitHub
parent fc1bff2110
commit 5404cebf5b
65 changed files with 2132 additions and 34 deletions

View File

@@ -0,0 +1,77 @@
import { z } from "zod";
import { tileBaseSchema } from "./tile";
const appBehaviourSchema = z.object({
externalUrl: z.string(),
isOpeningNewTab: z.boolean(),
tooltipDescription: z.string().optional(),
});
const appNetworkSchema = z.object({
enabledStatusChecker: z.boolean(),
okStatus: z.array(z.number()).optional(),
statusCodes: z.array(z.string()),
});
const appAppearanceSchema = z.object({
iconUrl: z.string(),
appNameStatus: z.union([z.literal("normal"), z.literal("hover"), z.literal("hidden")]),
positionAppName: z.union([
z.literal("row"),
z.literal("column"),
z.literal("row-reverse"),
z.literal("column-reverse"),
]),
appNameFontSize: z.number(),
lineClampAppName: z.number(),
});
const integrationSchema = z.enum([
"readarr",
"radarr",
"sonarr",
"lidarr",
"prowlarr",
"sabnzbd",
"jellyseerr",
"overseerr",
"deluge",
"qBittorrent",
"transmission",
"plex",
"jellyfin",
"nzbGet",
"pihole",
"adGuardHome",
"homeAssistant",
"openmediavault",
"proxmox",
"tdarr",
]);
const appIntegrationPropertySchema = z.object({
type: z.enum(["private", "public"]),
field: z.enum(["apiKey", "password", "username"]),
value: z.string().nullable().optional(),
isDefined: z.boolean().optional(),
});
const appIntegrationSchema = z.object({
type: integrationSchema.optional().nullable(),
properties: z.array(appIntegrationPropertySchema),
});
export const oldmarrAppSchema = z
.object({
id: z.string(),
name: z.string(),
url: z.string(),
behaviour: appBehaviourSchema,
network: appNetworkSchema,
appearance: appAppearanceSchema,
integration: appIntegrationSchema.optional(),
})
.and(tileBaseSchema);
export type OldmarrApp = z.infer<typeof oldmarrAppSchema>;

View File

@@ -0,0 +1,30 @@
import { z } from "zod";
import { oldmarrAppSchema } from "./app";
import { settingsSchema } from "./setting";
import { oldmarrWidgetSchema } from "./widget";
const categorySchema = z.object({
id: z.string(),
position: z.number(),
name: z.string(),
});
const wrapperSchema = z.object({
id: z.string(),
position: z.number(),
});
export const oldmarrConfigSchema = z.object({
schemaVersion: z.number(),
configProperties: z.object({
name: z.string(),
}),
categories: z.array(categorySchema),
wrappers: z.array(wrapperSchema),
apps: z.array(oldmarrAppSchema),
widgets: z.array(oldmarrWidgetSchema),
settings: settingsSchema,
});
export type OldmarrConfig = z.infer<typeof oldmarrConfigSchema>;

View File

@@ -0,0 +1,5 @@
export type { OldmarrConfig } from "./config";
export { oldmarrConfigSchema } from "./config";
export type { OldmarrApp } from "./app";
export type { OldmarrWidget, OldmarrWidgetKind } from "./widget";
export { oldmarrWidgetKinds } from "./widget";

View File

@@ -0,0 +1,75 @@
import { z } from "zod";
const baseSearchEngineSchema = z.object({
properties: z.object({
openInNewTab: z.boolean().default(true),
enabled: z.boolean().default(true),
}),
});
const commonSearchEngineSchema = z
.object({
type: z.enum(["google", "duckDuckGo", "bing"]),
})
.and(baseSearchEngineSchema);
const customSearchEngineSchema = z
.object({
type: z.literal("custom"),
properties: z.object({
template: z.string(),
}),
})
.and(baseSearchEngineSchema);
const searchEngineSchema = z.union([commonSearchEngineSchema, customSearchEngineSchema]);
const commonSettingsSchema = z.object({
searchEngine: searchEngineSchema,
});
const accessSettingsSchema = z.object({
allowGuests: z.boolean(),
});
const gridstackSettingsSchema = z.object({
columnCountSmall: z.number(),
columnCountMedium: z.number(),
columnCountLarge: z.number(),
});
const layoutSettingsSchema = z.object({
enabledLeftSidebar: z.boolean(),
enabledRightSidebar: z.boolean(),
enabledDocker: z.boolean(),
enabledPing: z.boolean(),
enabledSearchbar: z.boolean(),
});
const colorsSettingsSchema = z.object({
primary: z.string().optional(),
secondary: z.string().optional(),
shade: z.number().optional(),
});
const customizationSettingsSchema = z.object({
layout: layoutSettingsSchema,
pageTitle: z.string().optional(),
metaTitle: z.string().optional(),
logoImageUrl: z.string().optional(),
faviconUrl: z.string().optional(),
backgroundImageUrl: z.string().optional(),
backgroundImageAttachment: z.enum(["fixed", "scroll"]).optional(),
backgroundImageSize: z.enum(["cover", "contain"]).optional(),
backgroundImageRepeat: z.enum(["no-repeat", "repeat", "repeat-x", "repeat-y"]).optional(),
customCss: z.string().optional(),
colors: colorsSettingsSchema,
appOpacity: z.number().optional(),
gridstack: gridstackSettingsSchema,
});
export const settingsSchema = z.object({
common: commonSettingsSchema,
customization: customizationSettingsSchema,
access: accessSettingsSchema,
});

View File

@@ -0,0 +1,55 @@
import { z } from "zod";
const createAreaSchema = <TType extends string, TPropertiesSchema extends z.AnyZodObject>(
type: TType,
propertiesSchema: TPropertiesSchema,
) =>
z.object({
type: z.literal(type),
properties: propertiesSchema,
});
const wrapperAreaSchema = createAreaSchema(
"wrapper",
z.object({
id: z.string(),
}),
);
const categoryAreaSchema = createAreaSchema(
"category",
z.object({
id: z.string(),
}),
);
const sidebarAreaSchema = createAreaSchema(
"sidebar",
z.object({
location: z.union([z.literal("right"), z.literal("left")]),
}),
);
const areaSchema = z.union([wrapperAreaSchema, categoryAreaSchema, sidebarAreaSchema]);
const sizedShapeSchema = z.object({
location: z.object({
x: z.number(),
y: z.number(),
}),
size: z.object({
width: z.number(),
height: z.number(),
}),
});
const shapeSchema = z.object({
lg: sizedShapeSchema.optional(),
md: sizedShapeSchema.optional(),
sm: sizedShapeSchema.optional(),
});
export const tileBaseSchema = z.object({
area: areaSchema,
shape: shapeSchema,
});

View File

@@ -0,0 +1,40 @@
import { z } from "zod";
import { tileBaseSchema } from "./tile";
export const oldmarrWidgetKinds = [
"calendar",
"indexer-manager",
"dashdot",
"usenet",
"weather",
"torrents-status",
"dlspeed",
"date",
"rss",
"video-stream",
"iframe",
"media-server",
"media-requests-list",
"media-requests-stats",
"dns-hole-summary",
"dns-hole-controls",
"bookmark",
"notebook",
"smart-home/entity-state",
"smart-home/trigger-automation",
"health-monitoring",
"media-transcoding",
] as const;
export type OldmarrWidgetKind = (typeof oldmarrWidgetKinds)[number];
export const oldmarrWidgetSchema = z
.object({
id: z.string(),
type: z.enum(oldmarrWidgetKinds),
properties: z.record(z.unknown()),
})
.and(tileBaseSchema);
export type OldmarrWidget = z.infer<typeof oldmarrWidgetSchema>;