Compare commits
119
Commits
v1.0.0-beta.13
...
v1.2.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b4b19f486e | ||
|
|
32cf09a62e | ||
|
|
a1ba4372da | ||
|
|
4e153b8046 | ||
|
|
ac788650fb | ||
|
|
a9b0e26c8d | ||
|
|
132db15424 | ||
|
|
860b73fa3f | ||
|
|
e4dd19b574 | ||
|
|
1b4ed02010 | ||
|
|
47b7cbb086 | ||
|
|
7a6477a272 | ||
|
|
bff536008c | ||
|
|
8b040eddef | ||
|
|
ce87d62b35 | ||
|
|
f88cc7381b | ||
|
|
cb54de524b | ||
|
|
7d8c7b9c2d | ||
|
|
73f7d885cd | ||
|
|
470d27e091 | ||
|
|
99c8e5b609 | ||
|
|
b413e2ec7d | ||
|
|
29d4f9e003 | ||
|
|
1f54bf5b9e | ||
|
|
4d8c22a4e6 | ||
|
|
3e9e1e5e4f | ||
|
|
582b981e69 | ||
|
|
f8ec4a43cf | ||
|
|
2a8809551c | ||
|
|
9df59296ff | ||
|
|
701538fcb5 | ||
|
|
0e82f2d199 | ||
|
|
a2b5d60aa8 | ||
|
|
02dabfcd01 | ||
|
|
931f312291 | ||
|
|
175927970b | ||
|
|
c922c5b083 | ||
|
|
73bbcfeee8 | ||
|
|
7a2d97ba91 | ||
|
|
e47d497560 | ||
|
|
b9271ba14a | ||
|
|
9d85677046 | ||
|
|
b30c192b8f | ||
|
|
d4f04da709 | ||
|
|
7960a4cea1 | ||
|
|
243d7e9dd4 | ||
|
|
bdefff636b | ||
|
|
55feb9dff8 | ||
|
|
45af6442a1 | ||
|
|
72debef4b4 | ||
|
|
25635db17e | ||
|
|
1897752e38 | ||
|
|
554853ffbd | ||
|
|
e40237e4a5 | ||
|
|
fa6262cf5e | ||
|
|
49bd02e869 | ||
|
|
3c8fbe371b | ||
|
|
81a8cf4b36 | ||
|
|
b5c008b4ad | ||
|
|
343438391b | ||
|
|
8400b9fb11 | ||
|
|
fe65e73fff | ||
|
|
e023edf9d6 | ||
|
|
927913cf4e | ||
|
|
07d8103051 | ||
|
|
fe08ccf589 | ||
|
|
c55207bd59 | ||
|
|
e35811c921 | ||
|
|
e481e116ff | ||
|
|
32be09a4a7 | ||
|
|
d0a20dbfc5 | ||
|
|
68329965f7 | ||
|
|
f9fea70d39 | ||
|
|
3ed46aecbd | ||
|
|
a31c6a97e0 | ||
|
|
d1be727eb3 | ||
|
|
a1084f91e5 | ||
|
|
7622f0a4d2 | ||
|
|
34cacb3153 | ||
|
|
48cf5d5304 | ||
|
|
8c36c3e36b | ||
|
|
b10b2013af | ||
|
|
ea8acc83ea | ||
|
|
cb96508634 | ||
|
|
5e83847772 | ||
|
|
1557537763 | ||
|
|
5f993d2630 | ||
|
|
44767c46c2 | ||
|
|
aaddf0d987 | ||
|
|
7f8e6e4ea1 | ||
|
|
34a76c98e8 | ||
|
|
0f82a6f63d | ||
|
|
fac522adb9 | ||
|
|
9945425eff | ||
|
|
8cd5833281 | ||
|
|
ef7174aa36 | ||
|
|
4ce76f8a73 | ||
|
|
3e65af9ebe | ||
|
|
c6e5bec348 | ||
|
|
3e74c065f5 | ||
|
|
14ae732d0c | ||
|
|
b97883f44d | ||
|
|
741753fa74 | ||
|
|
1f0f8912b6 | ||
|
|
49d6932218 | ||
|
|
f13fefa64d | ||
|
|
cef567efdf | ||
|
|
db2b79ee7f | ||
|
|
b46d30b04c | ||
|
|
de4283b5fa | ||
|
|
a08d3e387f | ||
|
|
bd1ff01109 | ||
|
|
b24b1cc8a9 | ||
|
|
e81edc898f | ||
|
|
4d864878e3 | ||
|
|
5776ead3e3 | ||
|
|
baf32c3fe6 | ||
|
|
ea408a0fdd | ||
|
|
17f93097f6 |
No files matched your search
@@ -28,6 +28,10 @@ DB_URL='FULL_PATH_TO_YOUR_SQLITE_DB_FILE'
|
|||||||
# DB_PASSWORD='password'
|
# DB_PASSWORD='password'
|
||||||
# DB_NAME='name-of-database'
|
# DB_NAME='name-of-database'
|
||||||
|
|
||||||
|
# The below path can be used to store trusted certificates during development, it is not required and can be left empty.
|
||||||
|
# If it is used, please use the full path to the directory where the certificates are stored.
|
||||||
|
# LOCAL_CERTIFICATE_PATH='FULL_PATH_TO_CERTIFICATES'
|
||||||
|
|
||||||
TURBO_TELEMETRY_DISABLED=1
|
TURBO_TELEMETRY_DISABLED=1
|
||||||
|
|
||||||
# Configure logging to use winston logger
|
# Configure logging to use winston logger
|
||||||
|
|||||||
@@ -31,6 +31,9 @@ body:
|
|||||||
label: Version
|
label: Version
|
||||||
description: What version of Homarr are you running?
|
description: What version of Homarr are you running?
|
||||||
options:
|
options:
|
||||||
|
- 1.1.0
|
||||||
|
- 1.0.1
|
||||||
|
- 1.0.0
|
||||||
- 1.0.0-beta
|
- 1.0.0-beta
|
||||||
- Other (describe in "additional information")
|
- Other (describe in "additional information")
|
||||||
default: 0
|
default: 0
|
||||||
|
|||||||
@@ -6,6 +6,11 @@
|
|||||||
matchPackagePatterns: ["^@homarr/"],
|
matchPackagePatterns: ["^@homarr/"],
|
||||||
enabled: false,
|
enabled: false,
|
||||||
},
|
},
|
||||||
|
// Disable Dockerode updates see https://github.com/apocas/dockerode/issues/787
|
||||||
|
{
|
||||||
|
matchPackagePatterns: ["^dockerode$"],
|
||||||
|
enabled: false,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
matchUpdateTypes: ["minor", "patch", "pin", "digest"],
|
matchUpdateTypes: ["minor", "patch", "pin", "digest"],
|
||||||
automerge: true,
|
automerge: true,
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ jobs:
|
|||||||
token: ${{ github.token }}
|
token: ${{ github.token }}
|
||||||
branch: dev
|
branch: dev
|
||||||
- name: Create pull request
|
- name: Create pull request
|
||||||
run: 'gh pr create --title "chore(release): automatic release ${{ steps.semver.outputs.next }}" --body "**This is an automatic release**.<br/>Manual action may be required for major bumps.<br/>Detected change to be ``${{ steps.semver.outputs.bump }}``<br/>Bump version from ``${{ steps.semver.outputs.current }}`` to ``${{ steps.semver.outputs.next }}``" --base beta --head dev --label automerge'
|
run: 'gh pr create --title "chore(release): automatic release ${{ steps.semver.outputs.next }}" --body "**This is an automatic release**.<br/>Manual action may be required for major bumps.<br/>Detected change to be ``${{ steps.semver.outputs.bump }}``<br/>Bump version from ``${{ steps.semver.outputs.current }}`` to ``${{ steps.semver.outputs.next }}``" --base main --head dev --label automerge'
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
|
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
|
||||||
- name: Discord notification
|
- name: Discord notification
|
||||||
|
|||||||
+1246
File diff suppressed because it is too large.
Load diff
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
FROM node:22.13.0-alpine AS base
|
FROM node:22.13.1-alpine AS base
|
||||||
|
|
||||||
FROM base AS builder
|
FROM base AS builder
|
||||||
RUN apk add --no-cache libc6-compat
|
RUN apk add --no-cache libc6-compat
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
import "@homarr/auth/env";
|
import "@homarr/auth/env";
|
||||||
import "@homarr/db/env";
|
import "@homarr/db/env";
|
||||||
import "@homarr/common/env";
|
import "@homarr/common/env";
|
||||||
|
import "@homarr/docker/env";
|
||||||
|
|
||||||
import type { NextConfig } from "next";
|
import type { NextConfig } from "next";
|
||||||
import MillionLint from "@million/lint";
|
import MillionLint from "@million/lint";
|
||||||
|
|||||||
+19
-16
@@ -18,12 +18,15 @@
|
|||||||
"@homarr/analytics": "workspace:^0.1.0",
|
"@homarr/analytics": "workspace:^0.1.0",
|
||||||
"@homarr/api": "workspace:^0.1.0",
|
"@homarr/api": "workspace:^0.1.0",
|
||||||
"@homarr/auth": "workspace:^0.1.0",
|
"@homarr/auth": "workspace:^0.1.0",
|
||||||
|
"@homarr/certificates": "workspace:^0.1.0",
|
||||||
"@homarr/common": "workspace:^0.1.0",
|
"@homarr/common": "workspace:^0.1.0",
|
||||||
"@homarr/cron-job-status": "workspace:^0.1.0",
|
"@homarr/cron-job-status": "workspace:^0.1.0",
|
||||||
"@homarr/db": "workspace:^0.1.0",
|
"@homarr/db": "workspace:^0.1.0",
|
||||||
"@homarr/definitions": "workspace:^0.1.0",
|
"@homarr/definitions": "workspace:^0.1.0",
|
||||||
|
"@homarr/docker": "workspace:^0.1.0",
|
||||||
"@homarr/form": "workspace:^0.1.0",
|
"@homarr/form": "workspace:^0.1.0",
|
||||||
"@homarr/gridstack": "^1.11.3",
|
"@homarr/gridstack": "^1.12.0",
|
||||||
|
"@homarr/icons": "workspace:^0.1.0",
|
||||||
"@homarr/integrations": "workspace:^0.1.0",
|
"@homarr/integrations": "workspace:^0.1.0",
|
||||||
"@homarr/log": "workspace:^",
|
"@homarr/log": "workspace:^",
|
||||||
"@homarr/modals": "workspace:^0.1.0",
|
"@homarr/modals": "workspace:^0.1.0",
|
||||||
@@ -38,18 +41,18 @@
|
|||||||
"@homarr/ui": "workspace:^0.1.0",
|
"@homarr/ui": "workspace:^0.1.0",
|
||||||
"@homarr/validation": "workspace:^0.1.0",
|
"@homarr/validation": "workspace:^0.1.0",
|
||||||
"@homarr/widgets": "workspace:^0.1.0",
|
"@homarr/widgets": "workspace:^0.1.0",
|
||||||
"@mantine/colors-generator": "^7.16.0",
|
"@mantine/colors-generator": "^7.16.1",
|
||||||
"@mantine/core": "^7.16.0",
|
"@mantine/core": "^7.16.1",
|
||||||
"@mantine/dropzone": "^7.16.0",
|
"@mantine/dropzone": "^7.16.1",
|
||||||
"@mantine/hooks": "^7.16.0",
|
"@mantine/hooks": "^7.16.1",
|
||||||
"@mantine/modals": "^7.16.0",
|
"@mantine/modals": "^7.16.1",
|
||||||
"@mantine/tiptap": "^7.16.0",
|
"@mantine/tiptap": "^7.16.1",
|
||||||
"@million/lint": "1.0.14",
|
"@million/lint": "1.0.14",
|
||||||
"@t3-oss/env-nextjs": "^0.11.1",
|
"@t3-oss/env-nextjs": "^0.11.1",
|
||||||
"@tabler/icons-react": "^3.28.1",
|
"@tabler/icons-react": "^3.29.0",
|
||||||
"@tanstack/react-query": "^5.64.1",
|
"@tanstack/react-query": "^5.64.2",
|
||||||
"@tanstack/react-query-devtools": "^5.64.1",
|
"@tanstack/react-query-devtools": "^5.64.2",
|
||||||
"@tanstack/react-query-next-experimental": "5.64.1",
|
"@tanstack/react-query-next-experimental": "5.64.2",
|
||||||
"@trpc/client": "next",
|
"@trpc/client": "next",
|
||||||
"@trpc/next": "next",
|
"@trpc/next": "next",
|
||||||
"@trpc/react-query": "next",
|
"@trpc/react-query": "next",
|
||||||
@@ -61,11 +64,11 @@
|
|||||||
"clsx": "^2.1.1",
|
"clsx": "^2.1.1",
|
||||||
"dayjs": "^1.11.13",
|
"dayjs": "^1.11.13",
|
||||||
"dotenv": "^16.4.7",
|
"dotenv": "^16.4.7",
|
||||||
"flag-icons": "^7.2.3",
|
"flag-icons": "^7.3.2",
|
||||||
"glob": "^11.0.1",
|
"glob": "^11.0.1",
|
||||||
"jotai": "^2.11.0",
|
"jotai": "^2.11.1",
|
||||||
"mantine-react-table": "2.0.0-beta.8",
|
"mantine-react-table": "2.0.0-beta.8",
|
||||||
"next": "15.1.4",
|
"next": "15.1.6",
|
||||||
"postcss-preset-mantine": "^1.17.0",
|
"postcss-preset-mantine": "^1.17.0",
|
||||||
"prismjs": "^1.29.0",
|
"prismjs": "^1.29.0",
|
||||||
"react": "19.0.0",
|
"react": "19.0.0",
|
||||||
@@ -82,9 +85,9 @@
|
|||||||
"@homarr/prettier-config": "workspace:^0.1.0",
|
"@homarr/prettier-config": "workspace:^0.1.0",
|
||||||
"@homarr/tsconfig": "workspace:^0.1.0",
|
"@homarr/tsconfig": "workspace:^0.1.0",
|
||||||
"@types/chroma-js": "3.1.0",
|
"@types/chroma-js": "3.1.0",
|
||||||
"@types/node": "^22.10.6",
|
"@types/node": "^22.10.10",
|
||||||
"@types/prismjs": "^1.26.5",
|
"@types/prismjs": "^1.26.5",
|
||||||
"@types/react": "19.0.7",
|
"@types/react": "19.0.8",
|
||||||
"@types/react-dom": "19.0.3",
|
"@types/react-dom": "19.0.3",
|
||||||
"@types/swagger-ui-react": "^4.18.3",
|
"@types/swagger-ui-react": "^4.18.3",
|
||||||
"concurrently": "^9.1.2",
|
"concurrently": "^9.1.2",
|
||||||
|
|||||||
@@ -94,6 +94,7 @@ export function TRPCReactProvider(props: PropsWithChildren) {
|
|||||||
false: unstable_httpBatchStreamLink({
|
false: unstable_httpBatchStreamLink({
|
||||||
transformer: superjson,
|
transformer: superjson,
|
||||||
url: getTrpcUrl(),
|
url: getTrpcUrl(),
|
||||||
|
maxURLLength: 2083, // Suggested by tRPC: https://trpc.io/docs/client/links/httpBatchLink#setting-a-maximum-url-length
|
||||||
headers: createHeadersCallbackForSource("nextjs-react (json)"),
|
headers: createHeadersCallbackForSource("nextjs-react (json)"),
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import type { MouseEvent } from "react";
|
import type { MouseEvent } from "react";
|
||||||
import { useCallback, useEffect } from "react";
|
import { useCallback, useEffect } from "react";
|
||||||
|
import Link from "next/link";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import { Group, Menu } from "@mantine/core";
|
import { Group, Menu } from "@mantine/core";
|
||||||
import { useHotkeys } from "@mantine/hooks";
|
import { useHotkeys } from "@mantine/hooks";
|
||||||
@@ -9,9 +10,11 @@ import {
|
|||||||
IconBox,
|
IconBox,
|
||||||
IconBoxAlignTop,
|
IconBoxAlignTop,
|
||||||
IconChevronDown,
|
IconChevronDown,
|
||||||
|
IconLayoutBoard,
|
||||||
IconPencil,
|
IconPencil,
|
||||||
IconPencilOff,
|
IconPencilOff,
|
||||||
IconPlus,
|
IconPlus,
|
||||||
|
IconReplace,
|
||||||
IconResize,
|
IconResize,
|
||||||
IconSettings,
|
IconSettings,
|
||||||
} from "@tabler/icons-react";
|
} from "@tabler/icons-react";
|
||||||
@@ -49,6 +52,8 @@ export const BoardContentHeaderActions = () => {
|
|||||||
<HeaderButton href={`/boards/${board.name}/settings`}>
|
<HeaderButton href={`/boards/${board.name}/settings`}>
|
||||||
<IconSettings stroke={1.5} />
|
<IconSettings stroke={1.5} />
|
||||||
</HeaderButton>
|
</HeaderButton>
|
||||||
|
|
||||||
|
<SelectBoardsMenu />
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@@ -151,6 +156,32 @@ const EditModeMenu = () => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const SelectBoardsMenu = () => {
|
||||||
|
const { data: boards = [] } = clientApi.board.getAllBoards.useQuery();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Menu position="bottom-end" withArrow>
|
||||||
|
<Menu.Target>
|
||||||
|
<HeaderButton w="auto" px={4}>
|
||||||
|
<IconReplace stroke={1.5} />
|
||||||
|
</HeaderButton>
|
||||||
|
</Menu.Target>
|
||||||
|
<Menu.Dropdown style={{ transform: "translate(-7px, 0)" }}>
|
||||||
|
{boards.map((board) => (
|
||||||
|
<Menu.Item
|
||||||
|
key={board.id}
|
||||||
|
component={Link}
|
||||||
|
href={`/boards/${board.name}`}
|
||||||
|
leftSection={<IconLayoutBoard size={20} />}
|
||||||
|
>
|
||||||
|
{board.name}
|
||||||
|
</Menu.Item>
|
||||||
|
))}
|
||||||
|
</Menu.Dropdown>
|
||||||
|
</Menu>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const usePreventLeaveWithDirty = (isDirty: boolean) => {
|
const usePreventLeaveWithDirty = (isDirty: boolean) => {
|
||||||
const t = useI18n();
|
const t = useI18n();
|
||||||
const { openConfirmModal } = useConfirmModal();
|
const { openConfirmModal } = useConfirmModal();
|
||||||
|
|||||||
+3
-1
@@ -1,4 +1,4 @@
|
|||||||
import { IconKey, IconPassword, IconUser } from "@tabler/icons-react";
|
import { IconGrid3x3, IconKey, IconPassword, IconServer, IconUser } from "@tabler/icons-react";
|
||||||
|
|
||||||
import type { IntegrationSecretKind } from "@homarr/definitions";
|
import type { IntegrationSecretKind } from "@homarr/definitions";
|
||||||
import type { TablerIcon } from "@homarr/ui";
|
import type { TablerIcon } from "@homarr/ui";
|
||||||
@@ -7,4 +7,6 @@ export const integrationSecretIcons = {
|
|||||||
username: IconUser,
|
username: IconUser,
|
||||||
apiKey: IconKey,
|
apiKey: IconKey,
|
||||||
password: IconPassword,
|
password: IconPassword,
|
||||||
|
realm: IconServer,
|
||||||
|
tokenId: IconGrid3x3,
|
||||||
} satisfies Record<IntegrationSecretKind, TablerIcon>;
|
} satisfies Record<IntegrationSecretKind, TablerIcon>;
|
||||||
@@ -15,7 +15,9 @@ export const IntegrationCreateDropdownContent = () => {
|
|||||||
const [search, setSearch] = useState("");
|
const [search, setSearch] = useState("");
|
||||||
|
|
||||||
const filteredKinds = useMemo(() => {
|
const filteredKinds = useMemo(() => {
|
||||||
return integrationKinds.filter((kind) => kind.includes(search.toLowerCase()));
|
return integrationKinds.filter((kind) =>
|
||||||
|
getIntegrationName(kind).toLowerCase().includes(search.toLowerCase().trim()),
|
||||||
|
);
|
||||||
}, [search]);
|
}, [search]);
|
||||||
|
|
||||||
const handleSearch = React.useCallback(
|
const handleSearch = React.useCallback(
|
||||||
@@ -29,6 +31,7 @@ export const IntegrationCreateDropdownContent = () => {
|
|||||||
leftSection={<IconSearch stroke={1.5} size={20} />}
|
leftSection={<IconSearch stroke={1.5} size={20} />}
|
||||||
placeholder={t("integration.page.list.search")}
|
placeholder={t("integration.page.list.search")}
|
||||||
value={search}
|
value={search}
|
||||||
|
data-autofocus
|
||||||
onChange={handleSearch}
|
onChange={handleSearch}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
|||||||
@@ -102,7 +102,15 @@ export default async function IntegrationsPage(props: IntegrationsPageProps) {
|
|||||||
|
|
||||||
const IntegrationSelectMenu = ({ children }: PropsWithChildren) => {
|
const IntegrationSelectMenu = ({ children }: PropsWithChildren) => {
|
||||||
return (
|
return (
|
||||||
<Menu width={256} trapFocus position="bottom-end" withinPortal shadow="md" keepMounted={false}>
|
<Menu
|
||||||
|
width={256}
|
||||||
|
trapFocus
|
||||||
|
position="bottom-end"
|
||||||
|
withinPortal
|
||||||
|
shadow="md"
|
||||||
|
keepMounted={false}
|
||||||
|
withInitialFocusPlaceholder={false}
|
||||||
|
>
|
||||||
{children}
|
{children}
|
||||||
<MenuDropdown>
|
<MenuDropdown>
|
||||||
<IntegrationCreateDropdownContent />
|
<IntegrationCreateDropdownContent />
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import {
|
|||||||
IconBrandDiscord,
|
IconBrandDiscord,
|
||||||
IconBrandDocker,
|
IconBrandDocker,
|
||||||
IconBrandGithub,
|
IconBrandGithub,
|
||||||
|
IconCertificate,
|
||||||
IconGitFork,
|
IconGitFork,
|
||||||
IconHome,
|
IconHome,
|
||||||
IconInfoSmall,
|
IconInfoSmall,
|
||||||
@@ -119,6 +120,12 @@ export default async function ManageLayout({ children }: PropsWithChildren) {
|
|||||||
href: "/manage/tools/logs",
|
href: "/manage/tools/logs",
|
||||||
hidden: !session?.user.permissions.includes("other-view-logs"),
|
hidden: !session?.user.permissions.includes("other-view-logs"),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: t("items.tools.items.certificates"),
|
||||||
|
icon: IconCertificate,
|
||||||
|
href: "/manage/tools/certificates",
|
||||||
|
hidden: !session?.user.permissions.includes("admin"),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
label: t("items.tools.items.tasks"),
|
label: t("items.tools.items.tasks"),
|
||||||
icon: IconReport,
|
icon: IconReport,
|
||||||
@@ -146,7 +153,7 @@ export default async function ManageLayout({ children }: PropsWithChildren) {
|
|||||||
{
|
{
|
||||||
label: t("items.help.items.submitIssue"),
|
label: t("items.help.items.submitIssue"),
|
||||||
icon: IconBrandGithub,
|
icon: IconBrandGithub,
|
||||||
href: "https://github.com/ajnart/homarr/issues/new/choose",
|
href: "https://github.com/homarr-labs/homarr/issues/new/choose",
|
||||||
external: true,
|
external: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -158,7 +165,7 @@ export default async function ManageLayout({ children }: PropsWithChildren) {
|
|||||||
{
|
{
|
||||||
label: t("items.help.items.sourceCode"),
|
label: t("items.help.items.sourceCode"),
|
||||||
icon: IconGitFork,
|
icon: IconGitFork,
|
||||||
href: "https://github.com/ajnart/homarr",
|
href: "https://github.com/homarr-labs/homarr",
|
||||||
external: true,
|
external: true,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -15,6 +15,11 @@ export const CopyMedia = ({ media }: CopyMediaProps) => {
|
|||||||
|
|
||||||
const url = typeof window !== "undefined" ? `${window.location.origin}/api/user-medias/${media.id}` : "";
|
const url = typeof window !== "undefined" ? `${window.location.origin}/api/user-medias/${media.id}` : "";
|
||||||
|
|
||||||
|
// Clipboard only works on localhost or secure connections (https)
|
||||||
|
if (url.startsWith("http://") && !url.startsWith("http://localhost")) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<CopyButton value={url}>
|
<CopyButton value={url}>
|
||||||
{({ copy, copied }) => (
|
{({ copy, copied }) => (
|
||||||
|
|||||||
@@ -1,13 +1,28 @@
|
|||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { notFound } from "next/navigation";
|
import { notFound } from "next/navigation";
|
||||||
import { Anchor, Group, Stack, Table, TableTbody, TableTd, TableTh, TableThead, TableTr, Title } from "@mantine/core";
|
import {
|
||||||
|
ActionIcon,
|
||||||
|
Anchor,
|
||||||
|
Group,
|
||||||
|
Stack,
|
||||||
|
Table,
|
||||||
|
TableTbody,
|
||||||
|
TableTd,
|
||||||
|
TableTh,
|
||||||
|
TableThead,
|
||||||
|
TableTr,
|
||||||
|
Title,
|
||||||
|
Tooltip,
|
||||||
|
} from "@mantine/core";
|
||||||
|
import { IconExternalLink } from "@tabler/icons-react";
|
||||||
|
|
||||||
import type { RouterOutputs } from "@homarr/api";
|
import type { RouterOutputs } from "@homarr/api";
|
||||||
import { api } from "@homarr/api/server";
|
import { api } from "@homarr/api/server";
|
||||||
import { auth } from "@homarr/auth/next";
|
import { auth } from "@homarr/auth/next";
|
||||||
import { humanFileSize } from "@homarr/common";
|
import { humanFileSize } from "@homarr/common";
|
||||||
import type { inferSearchParamsFromSchema } from "@homarr/common/types";
|
import type { inferSearchParamsFromSchema } from "@homarr/common/types";
|
||||||
|
import { createLocalImageUrl } from "@homarr/icons/local";
|
||||||
import { getI18n } from "@homarr/translation/server";
|
import { getI18n } from "@homarr/translation/server";
|
||||||
import { SearchInput, TablePagination, UserAvatar } from "@homarr/ui";
|
import { SearchInput, TablePagination, UserAvatar } from "@homarr/ui";
|
||||||
import { z } from "@homarr/validation";
|
import { z } from "@homarr/validation";
|
||||||
@@ -91,13 +106,14 @@ interface RowProps {
|
|||||||
|
|
||||||
const Row = async ({ media }: RowProps) => {
|
const Row = async ({ media }: RowProps) => {
|
||||||
const session = await auth();
|
const session = await auth();
|
||||||
|
const t = await getI18n();
|
||||||
const canDelete = media.creatorId === session?.user.id || session?.user.permissions.includes("media-full-all");
|
const canDelete = media.creatorId === session?.user.id || session?.user.permissions.includes("media-full-all");
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TableTr>
|
<TableTr>
|
||||||
<TableTd w={64}>
|
<TableTd w={64}>
|
||||||
<Image
|
<Image
|
||||||
src={`/api/user-medias/${media.id}`}
|
src={createLocalImageUrl(media.id)}
|
||||||
alt={media.name}
|
alt={media.name}
|
||||||
width={64}
|
width={64}
|
||||||
height={64}
|
height={64}
|
||||||
@@ -121,6 +137,17 @@ const Row = async ({ media }: RowProps) => {
|
|||||||
<TableTd w={64}>
|
<TableTd w={64}>
|
||||||
<Group wrap="nowrap" gap="xs">
|
<Group wrap="nowrap" gap="xs">
|
||||||
<CopyMedia media={media} />
|
<CopyMedia media={media} />
|
||||||
|
<Tooltip label={t("media.action.open.label")} openDelay={500}>
|
||||||
|
<ActionIcon
|
||||||
|
component="a"
|
||||||
|
href={createLocalImageUrl(media.id)}
|
||||||
|
target="_blank"
|
||||||
|
color="gray"
|
||||||
|
variant="subtle"
|
||||||
|
>
|
||||||
|
<IconExternalLink size={16} stroke={1.5} />
|
||||||
|
</ActionIcon>
|
||||||
|
</Tooltip>
|
||||||
{canDelete && <DeleteMedia media={media} />}
|
{canDelete && <DeleteMedia media={media} />}
|
||||||
</Group>
|
</Group>
|
||||||
</TableTd>
|
</TableTd>
|
||||||
|
|||||||
+81
@@ -0,0 +1,81 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { Button, FileInput, Group, Stack } from "@mantine/core";
|
||||||
|
import { IconCertificate } from "@tabler/icons-react";
|
||||||
|
|
||||||
|
import { clientApi } from "@homarr/api/client";
|
||||||
|
import { revalidatePathActionAsync } from "@homarr/common/client";
|
||||||
|
import { useZodForm } from "@homarr/form";
|
||||||
|
import { createModal, useModalAction } from "@homarr/modals";
|
||||||
|
import { showErrorNotification, showSuccessNotification } from "@homarr/notifications";
|
||||||
|
import { useI18n } from "@homarr/translation/client";
|
||||||
|
import { superRefineCertificateFile, z } from "@homarr/validation";
|
||||||
|
|
||||||
|
export const AddCertificateButton = () => {
|
||||||
|
const { openModal } = useModalAction(AddCertificateModal);
|
||||||
|
const t = useI18n();
|
||||||
|
|
||||||
|
const handleClick = () => {
|
||||||
|
openModal({});
|
||||||
|
};
|
||||||
|
|
||||||
|
return <Button onClick={handleClick}>{t("certificate.action.create.label")}</Button>;
|
||||||
|
};
|
||||||
|
|
||||||
|
const AddCertificateModal = createModal(({ actions }) => {
|
||||||
|
const t = useI18n();
|
||||||
|
const form = useZodForm(
|
||||||
|
z.object({
|
||||||
|
file: z.instanceof(File).nullable().superRefine(superRefineCertificateFile),
|
||||||
|
}),
|
||||||
|
{
|
||||||
|
initialValues: {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||||
|
file: null!,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
const { mutateAsync } = clientApi.certificates.addCertificate.useMutation();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<form
|
||||||
|
onSubmit={form.onSubmit(async (values) => {
|
||||||
|
const formData = new FormData();
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||||
|
formData.set("file", values.file!);
|
||||||
|
await mutateAsync(formData, {
|
||||||
|
async onSuccess() {
|
||||||
|
showSuccessNotification({
|
||||||
|
title: t("certificate.action.create.notification.success.title"),
|
||||||
|
message: t("certificate.action.create.notification.success.message"),
|
||||||
|
});
|
||||||
|
await revalidatePathActionAsync("/manage/tools/certificates");
|
||||||
|
actions.closeModal();
|
||||||
|
},
|
||||||
|
onError() {
|
||||||
|
showErrorNotification({
|
||||||
|
title: t("certificate.action.create.notification.error.title"),
|
||||||
|
message: t("certificate.action.create.notification.error.message"),
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
<Stack>
|
||||||
|
<FileInput leftSection={<IconCertificate size={16} />} {...form.getInputProps("file")} />
|
||||||
|
<Group justify="end">
|
||||||
|
<Button onClick={actions.closeModal} variant="subtle" color="gray">
|
||||||
|
{t("common.action.cancel")}
|
||||||
|
</Button>
|
||||||
|
<Button type="submit" loading={form.submitting}>
|
||||||
|
{t("common.action.add")}
|
||||||
|
</Button>
|
||||||
|
</Group>
|
||||||
|
</Stack>
|
||||||
|
</form>
|
||||||
|
);
|
||||||
|
}).withOptions({
|
||||||
|
defaultTitle(t) {
|
||||||
|
return t("certificate.action.create.label");
|
||||||
|
},
|
||||||
|
});
|
||||||
+54
@@ -0,0 +1,54 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { ActionIcon } from "@mantine/core";
|
||||||
|
import { IconTrash } from "@tabler/icons-react";
|
||||||
|
|
||||||
|
import { clientApi } from "@homarr/api/client";
|
||||||
|
import { revalidatePathActionAsync } from "@homarr/common/client";
|
||||||
|
import { useConfirmModal } from "@homarr/modals";
|
||||||
|
import { showErrorNotification, showSuccessNotification } from "@homarr/notifications";
|
||||||
|
import { useI18n } from "@homarr/translation/client";
|
||||||
|
|
||||||
|
interface RemoveCertificateProps {
|
||||||
|
fileName: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const RemoveCertificate = ({ fileName }: RemoveCertificateProps) => {
|
||||||
|
const { openConfirmModal } = useConfirmModal();
|
||||||
|
const { mutateAsync } = clientApi.certificates.removeCertificate.useMutation();
|
||||||
|
const t = useI18n();
|
||||||
|
|
||||||
|
const handleClick = () => {
|
||||||
|
openConfirmModal({
|
||||||
|
title: t("certificate.action.remove.label"),
|
||||||
|
children: t("certificate.action.remove.confirm"),
|
||||||
|
// eslint-disable-next-line no-restricted-syntax
|
||||||
|
async onConfirm() {
|
||||||
|
await mutateAsync(
|
||||||
|
{ fileName },
|
||||||
|
{
|
||||||
|
async onSuccess() {
|
||||||
|
showSuccessNotification({
|
||||||
|
title: t("certificate.action.remove.notification.success.title"),
|
||||||
|
message: t("certificate.action.remove.notification.success.message"),
|
||||||
|
});
|
||||||
|
await revalidatePathActionAsync("/manage/tools/certificates");
|
||||||
|
},
|
||||||
|
onError() {
|
||||||
|
showErrorNotification({
|
||||||
|
title: t("certificate.action.remove.notification.error.title"),
|
||||||
|
message: t("certificate.action.remove.notification.error.message"),
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ActionIcon onClick={handleClick} color="red" variant="subtle">
|
||||||
|
<IconTrash color="red" size={16} />
|
||||||
|
</ActionIcon>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -0,0 +1,104 @@
|
|||||||
|
import { X509Certificate } from "node:crypto";
|
||||||
|
import { notFound } from "next/navigation";
|
||||||
|
import { Card, Group, SimpleGrid, Stack, Text, Title } from "@mantine/core";
|
||||||
|
import { IconCertificate, IconCertificateOff } from "@tabler/icons-react";
|
||||||
|
import dayjs from "dayjs";
|
||||||
|
|
||||||
|
import { auth } from "@homarr/auth/next";
|
||||||
|
import { loadCustomRootCertificatesAsync } from "@homarr/certificates/server";
|
||||||
|
import { getMantineColor } from "@homarr/common";
|
||||||
|
import type { SupportedLanguage } from "@homarr/translation";
|
||||||
|
import { getI18n } from "@homarr/translation/server";
|
||||||
|
|
||||||
|
import { DynamicBreadcrumb } from "~/components/navigation/dynamic-breadcrumb";
|
||||||
|
import { NoResults } from "~/components/no-results";
|
||||||
|
import { AddCertificateButton } from "./_components/add-certificate";
|
||||||
|
import { RemoveCertificate } from "./_components/remove-certificate";
|
||||||
|
|
||||||
|
interface CertificatesPageProps {
|
||||||
|
params: Promise<{
|
||||||
|
locale: SupportedLanguage;
|
||||||
|
}>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default async function CertificatesPage({ params }: CertificatesPageProps) {
|
||||||
|
const session = await auth();
|
||||||
|
if (!session?.user.permissions.includes("admin")) {
|
||||||
|
notFound();
|
||||||
|
}
|
||||||
|
|
||||||
|
const { locale } = await params;
|
||||||
|
const t = await getI18n();
|
||||||
|
const certificates = await loadCustomRootCertificatesAsync();
|
||||||
|
const x509Certificates = certificates
|
||||||
|
.map((cert) => ({
|
||||||
|
...cert,
|
||||||
|
x509: new X509Certificate(cert.content),
|
||||||
|
}))
|
||||||
|
.sort((certA, certB) => certA.x509.validToDate.getTime() - certB.x509.validToDate.getTime());
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<DynamicBreadcrumb />
|
||||||
|
|
||||||
|
<Stack>
|
||||||
|
<Group justify="space-between">
|
||||||
|
<Stack gap={4}>
|
||||||
|
<Title>{t("certificate.page.list.title")}</Title>
|
||||||
|
<Text>{t("certificate.page.list.description")}</Text>
|
||||||
|
</Stack>
|
||||||
|
|
||||||
|
<AddCertificateButton />
|
||||||
|
</Group>
|
||||||
|
|
||||||
|
{x509Certificates.length === 0 && (
|
||||||
|
<NoResults icon={IconCertificateOff} title={t("certificate.page.list.noResults.title")} />
|
||||||
|
)}
|
||||||
|
|
||||||
|
<SimpleGrid cols={{ sm: 1, lg: 2, xl: 3 }} spacing="lg">
|
||||||
|
{x509Certificates.map((cert) => (
|
||||||
|
<Card key={cert.x509.fingerprint} withBorder>
|
||||||
|
<Group wrap="nowrap">
|
||||||
|
<IconCertificate
|
||||||
|
color={getMantineColor(iconColor(cert.x509.validToDate), 6)}
|
||||||
|
style={{ minWidth: 32 }}
|
||||||
|
size={32}
|
||||||
|
stroke={1.5}
|
||||||
|
/>
|
||||||
|
<Stack flex={1} gap="xs" maw="calc(100% - 48px)">
|
||||||
|
<Group justify="space-between" wrap="nowrap">
|
||||||
|
<Text fw={500} lineClamp={1} style={{ wordBreak: "break-all" }}>
|
||||||
|
{cert.x509.subject}
|
||||||
|
</Text>
|
||||||
|
<Text c="gray.6" ta="end" size="sm">
|
||||||
|
{cert.fileName}
|
||||||
|
</Text>
|
||||||
|
</Group>
|
||||||
|
<Group justify="space-between">
|
||||||
|
<Text size="sm" c="gray.6" title={cert.x509.validToDate.toISOString()}>
|
||||||
|
{t("certificate.page.list.expires", {
|
||||||
|
when: new Intl.RelativeTimeFormat(locale).format(
|
||||||
|
dayjs(cert.x509.validToDate).diff(dayjs(), "days"),
|
||||||
|
"days",
|
||||||
|
),
|
||||||
|
})}
|
||||||
|
</Text>
|
||||||
|
<RemoveCertificate fileName={cert.fileName} />
|
||||||
|
</Group>
|
||||||
|
</Stack>
|
||||||
|
</Group>
|
||||||
|
</Card>
|
||||||
|
))}
|
||||||
|
</SimpleGrid>
|
||||||
|
</Stack>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const iconColor = (validTo: Date) => {
|
||||||
|
const daysUntilInvalid = dayjs(validTo).diff(new Date(), "days");
|
||||||
|
if (daysUntilInvalid < 1) return "red";
|
||||||
|
if (daysUntilInvalid < 7) return "orange";
|
||||||
|
if (daysUntilInvalid < 30) return "yellow";
|
||||||
|
return "green";
|
||||||
|
};
|
||||||
@@ -16,7 +16,7 @@ import { MantineReactTable } from "mantine-react-table";
|
|||||||
import type { RouterOutputs } from "@homarr/api";
|
import type { RouterOutputs } from "@homarr/api";
|
||||||
import { clientApi } from "@homarr/api/client";
|
import { clientApi } from "@homarr/api/client";
|
||||||
import { useTimeAgo } from "@homarr/common";
|
import { useTimeAgo } from "@homarr/common";
|
||||||
import type { DockerContainerState } from "@homarr/definitions";
|
import type { ContainerState } from "@homarr/docker";
|
||||||
import { useModalAction } from "@homarr/modals";
|
import { useModalAction } from "@homarr/modals";
|
||||||
import { AddDockerAppToHomarr } from "@homarr/modals-collection";
|
import { AddDockerAppToHomarr } from "@homarr/modals-collection";
|
||||||
import { showErrorNotification, showSuccessNotification } from "@homarr/notifications";
|
import { showErrorNotification, showSuccessNotification } from "@homarr/notifications";
|
||||||
@@ -246,9 +246,9 @@ const containerStates = {
|
|||||||
exited: "red",
|
exited: "red",
|
||||||
removing: "pink",
|
removing: "pink",
|
||||||
dead: "dark",
|
dead: "dark",
|
||||||
} satisfies Record<DockerContainerState, MantineColor>;
|
} satisfies Record<ContainerState, MantineColor>;
|
||||||
|
|
||||||
const ContainerStateBadge = ({ state }: { state: DockerContainerState }) => {
|
const ContainerStateBadge = ({ state }: { state: ContainerState }) => {
|
||||||
const t = useScopedI18n("docker.field.state.option");
|
const t = useScopedI18n("docker.field.state.option");
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
+2
-2
@@ -39,8 +39,8 @@ export const ChangeHomeBoardForm = ({ user, boardsData }: ChangeHomeBoardFormPro
|
|||||||
});
|
});
|
||||||
const form = useZodForm(validation.user.changeHomeBoards, {
|
const form = useZodForm(validation.user.changeHomeBoards, {
|
||||||
initialValues: {
|
initialValues: {
|
||||||
homeBoardId: user.homeBoardId ?? "",
|
homeBoardId: user.homeBoardId,
|
||||||
mobileHomeBoardId: user.mobileHomeBoardId ?? "",
|
mobileHomeBoardId: user.mobileHomeBoardId,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
+4
-1
@@ -51,7 +51,10 @@ export const PingIconsEnabled = ({ user }: PingIconsEnabledProps) => {
|
|||||||
return (
|
return (
|
||||||
<form onSubmit={form.onSubmit(handleSubmit)}>
|
<form onSubmit={form.onSubmit(handleSubmit)}>
|
||||||
<Stack gap="md">
|
<Stack gap="md">
|
||||||
<Switch {...form.getInputProps("pingIconsEnabled")} label={t("user.field.pingIconsEnabled.label")} />
|
<Switch
|
||||||
|
{...form.getInputProps("pingIconsEnabled", { type: "checkbox" })}
|
||||||
|
label={t("user.field.pingIconsEnabled.label")}
|
||||||
|
/>
|
||||||
|
|
||||||
<Group justify="end">
|
<Group justify="end">
|
||||||
<Button type="submit" color="teal" loading={isPending}>
|
<Button type="submit" color="teal" loading={isPending}>
|
||||||
|
|||||||
@@ -83,10 +83,12 @@ export default async function EditUserPage(props: Props) {
|
|||||||
</Box>
|
</Box>
|
||||||
</Group>
|
</Group>
|
||||||
|
|
||||||
<Stack mb="lg">
|
{session?.user.id === user.id && (
|
||||||
<Title order={2}>{tGeneral("item.language")}</Title>
|
<Stack mb="lg">
|
||||||
<CurrentLanguageCombobox />
|
<Title order={2}>{tGeneral("item.language")}</Title>
|
||||||
</Stack>
|
<CurrentLanguageCombobox />
|
||||||
|
</Stack>
|
||||||
|
)}
|
||||||
|
|
||||||
<Stack mb="lg">
|
<Stack mb="lg">
|
||||||
<Title order={2}>{tGeneral("item.board.title")}</Title>
|
<Title order={2}>{tGeneral("item.board.title")}</Title>
|
||||||
|
|||||||
@@ -30,7 +30,9 @@ const handler = auth(async (req) => {
|
|||||||
req,
|
req,
|
||||||
createContext: () => createTRPCContext({ session: req.auth, headers: req.headers }),
|
createContext: () => createTRPCContext({ session: req.auth, headers: req.headers }),
|
||||||
onError({ error, path, type }) {
|
onError({ error, path, type }) {
|
||||||
logger.error(`tRPC Error with ${type} on '${path}': (${error.code}) - ${error.message}`);
|
logger.error(
|
||||||
|
`tRPC Error with ${type} on '${path}': (${error.code}) - ${error.message}\n${error.stack}\n${error.cause}`,
|
||||||
|
);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,62 @@
|
|||||||
|
import type { Modify } from "@homarr/common/types";
|
||||||
|
import { createId } from "@homarr/db/client";
|
||||||
|
import type { WidgetKind } from "@homarr/definitions";
|
||||||
|
|
||||||
|
import type { Board, DynamicSection, EmptySection, Item } from "~/app/[locale]/boards/_types";
|
||||||
|
import { getFirstEmptyPosition } from "./empty-position";
|
||||||
|
|
||||||
|
export interface CreateItemInput {
|
||||||
|
kind: WidgetKind;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const createItemCallback =
|
||||||
|
({ kind }: CreateItemInput) =>
|
||||||
|
(previous: Board): Board => {
|
||||||
|
const firstSection = previous.sections
|
||||||
|
.filter((section): section is EmptySection => section.kind === "empty")
|
||||||
|
.sort((sectionA, sectionB) => sectionA.yOffset - sectionB.yOffset)
|
||||||
|
.at(0);
|
||||||
|
|
||||||
|
if (!firstSection) return previous;
|
||||||
|
|
||||||
|
const dynamicSectionsOfFirstSection = previous.sections.filter(
|
||||||
|
(section): section is DynamicSection => section.kind === "dynamic" && section.parentSectionId === firstSection.id,
|
||||||
|
);
|
||||||
|
const elements = [...firstSection.items, ...dynamicSectionsOfFirstSection];
|
||||||
|
const emptyPosition = getFirstEmptyPosition(elements, previous.columnCount);
|
||||||
|
|
||||||
|
if (!emptyPosition) {
|
||||||
|
console.error("Your board is full");
|
||||||
|
return previous;
|
||||||
|
}
|
||||||
|
|
||||||
|
const widget = {
|
||||||
|
id: createId(),
|
||||||
|
kind,
|
||||||
|
options: {},
|
||||||
|
width: 1,
|
||||||
|
height: 1,
|
||||||
|
...emptyPosition,
|
||||||
|
integrationIds: [],
|
||||||
|
advancedOptions: {
|
||||||
|
customCssClasses: [],
|
||||||
|
},
|
||||||
|
} satisfies Modify<
|
||||||
|
Item,
|
||||||
|
{
|
||||||
|
kind: WidgetKind;
|
||||||
|
}
|
||||||
|
>;
|
||||||
|
|
||||||
|
return {
|
||||||
|
...previous,
|
||||||
|
sections: previous.sections.map((section) => {
|
||||||
|
// Return same section if item is not in it
|
||||||
|
if (section.id !== firstSection.id) return section;
|
||||||
|
return {
|
||||||
|
...section,
|
||||||
|
items: section.items.concat(widget),
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
import { createId } from "@homarr/db/client";
|
||||||
|
|
||||||
|
import type { Board, DynamicSection, EmptySection } from "~/app/[locale]/boards/_types";
|
||||||
|
import { getFirstEmptyPosition } from "./empty-position";
|
||||||
|
|
||||||
|
export interface DuplicateItemInput {
|
||||||
|
itemId: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const duplicateItemCallback =
|
||||||
|
({ itemId }: DuplicateItemInput) =>
|
||||||
|
(previous: Board): Board => {
|
||||||
|
const itemToDuplicate = previous.sections
|
||||||
|
.flatMap((section) => section.items.map((item) => ({ ...item, sectionId: section.id })))
|
||||||
|
.find((item) => item.id === itemId);
|
||||||
|
if (!itemToDuplicate) return previous;
|
||||||
|
|
||||||
|
const currentSection = previous.sections.find((section) => section.id === itemToDuplicate.sectionId);
|
||||||
|
if (!currentSection) return previous;
|
||||||
|
|
||||||
|
const dynamicSectionsOfCurrentSection = previous.sections.filter(
|
||||||
|
(section): section is DynamicSection =>
|
||||||
|
section.kind === "dynamic" && section.parentSectionId === currentSection.id,
|
||||||
|
);
|
||||||
|
const elements = [...currentSection.items, ...dynamicSectionsOfCurrentSection];
|
||||||
|
let sectionId = currentSection.id;
|
||||||
|
let emptyPosition = getFirstEmptyPosition(
|
||||||
|
elements,
|
||||||
|
currentSection.kind === "dynamic" ? currentSection.width : previous.columnCount,
|
||||||
|
currentSection.kind === "dynamic" ? currentSection.height : undefined,
|
||||||
|
{
|
||||||
|
width: itemToDuplicate.width,
|
||||||
|
height: itemToDuplicate.height,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!emptyPosition) {
|
||||||
|
const firstSection = previous.sections
|
||||||
|
.filter((section): section is EmptySection => section.kind === "empty")
|
||||||
|
.sort((sectionA, sectionB) => sectionA.yOffset - sectionB.yOffset)
|
||||||
|
.at(0);
|
||||||
|
|
||||||
|
if (!firstSection) return previous;
|
||||||
|
|
||||||
|
const dynamicSectionsOfFirstSection = previous.sections.filter(
|
||||||
|
(section): section is DynamicSection =>
|
||||||
|
section.kind === "dynamic" && section.parentSectionId === firstSection.id,
|
||||||
|
);
|
||||||
|
const elements = [...firstSection.items, ...dynamicSectionsOfFirstSection];
|
||||||
|
emptyPosition = getFirstEmptyPosition(elements, previous.columnCount, undefined, {
|
||||||
|
width: itemToDuplicate.width,
|
||||||
|
height: itemToDuplicate.height,
|
||||||
|
});
|
||||||
|
if (!emptyPosition) {
|
||||||
|
console.error("Your board is full");
|
||||||
|
return previous;
|
||||||
|
}
|
||||||
|
|
||||||
|
sectionId = firstSection.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
const widget = structuredClone(itemToDuplicate);
|
||||||
|
widget.id = createId();
|
||||||
|
widget.xOffset = emptyPosition.xOffset;
|
||||||
|
widget.yOffset = emptyPosition.yOffset;
|
||||||
|
widget.sectionId = sectionId;
|
||||||
|
|
||||||
|
const result = {
|
||||||
|
...previous,
|
||||||
|
sections: previous.sections.map((section) => {
|
||||||
|
// Return same section if item is not in it
|
||||||
|
if (section.id !== sectionId) return section;
|
||||||
|
return {
|
||||||
|
...section,
|
||||||
|
items: section.items.concat(widget),
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
|
||||||
|
return result;
|
||||||
|
};
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
import type { Item } from "~/app/[locale]/boards/_types";
|
||||||
|
|
||||||
|
export const getFirstEmptyPosition = (
|
||||||
|
elements: Pick<Item, "yOffset" | "xOffset" | "width" | "height">[],
|
||||||
|
columnCount: number,
|
||||||
|
rowCount = 9999,
|
||||||
|
size: { width: number; height: number } = { width: 1, height: 1 },
|
||||||
|
) => {
|
||||||
|
for (let yOffset = 0; yOffset < rowCount + 1 - size.height; yOffset++) {
|
||||||
|
for (let xOffset = 0; xOffset < columnCount; xOffset++) {
|
||||||
|
const isOccupied = elements.some(
|
||||||
|
(element) =>
|
||||||
|
element.yOffset < yOffset + size.height &&
|
||||||
|
element.yOffset + element.height > yOffset &&
|
||||||
|
element.xOffset < xOffset + size.width &&
|
||||||
|
element.xOffset + element.width > xOffset,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!isOccupied) {
|
||||||
|
return { xOffset, yOffset };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
};
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
import { describe, expect, test, vi } from "vitest";
|
||||||
|
|
||||||
|
import type { Board } from "~/app/[locale]/boards/_types";
|
||||||
|
import { createItemCallback } from "../create-item";
|
||||||
|
import * as emptyPosition from "../empty-position";
|
||||||
|
import { createDynamicSection, createEmptySection, createItem } from "./shared";
|
||||||
|
|
||||||
|
describe("item actions create-item", () => {
|
||||||
|
test("should add it to first section", () => {
|
||||||
|
const spy = vi.spyOn(emptyPosition, "getFirstEmptyPosition");
|
||||||
|
spy.mockReturnValue({ xOffset: 5, yOffset: 5 });
|
||||||
|
const input = {
|
||||||
|
sections: [createEmptySection("1", 2), createEmptySection("2", 0), createEmptySection("3", 1)],
|
||||||
|
columnCount: 4,
|
||||||
|
} satisfies Pick<Board, "sections" | "columnCount">;
|
||||||
|
|
||||||
|
const result = createItemCallback({
|
||||||
|
kind: "clock",
|
||||||
|
})(input as unknown as Board);
|
||||||
|
|
||||||
|
const firstSection = result.sections.find((section) => section.id === "2");
|
||||||
|
const item = firstSection?.items.at(0);
|
||||||
|
expect(item).toEqual(expect.objectContaining({ kind: "clock", xOffset: 5, yOffset: 5 }));
|
||||||
|
expect(spy).toHaveBeenCalledWith([], input.columnCount);
|
||||||
|
});
|
||||||
|
test("should correctly pass dynamic section and items to getFirstEmptyPosition", () => {
|
||||||
|
const spy = vi.spyOn(emptyPosition, "getFirstEmptyPosition");
|
||||||
|
spy.mockReturnValue({ xOffset: 5, yOffset: 5 });
|
||||||
|
const firstSection = createEmptySection("2", 0);
|
||||||
|
const expectedItem = createItem({ id: "12", xOffset: 1, yOffset: 2, width: 3, height: 2 });
|
||||||
|
firstSection.items.push(expectedItem);
|
||||||
|
const dynamicSectionInFirst = createDynamicSection({
|
||||||
|
id: "4",
|
||||||
|
parentSectionId: "2",
|
||||||
|
yOffset: 0,
|
||||||
|
xOffset: 0,
|
||||||
|
width: 2,
|
||||||
|
height: 2,
|
||||||
|
});
|
||||||
|
|
||||||
|
const input = {
|
||||||
|
sections: [
|
||||||
|
createEmptySection("1", 2),
|
||||||
|
firstSection,
|
||||||
|
createEmptySection("3", 1),
|
||||||
|
dynamicSectionInFirst,
|
||||||
|
createDynamicSection({ id: "5", parentSectionId: "3", yOffset: 1 }),
|
||||||
|
],
|
||||||
|
columnCount: 4,
|
||||||
|
} satisfies Pick<Board, "sections" | "columnCount">;
|
||||||
|
|
||||||
|
const result = createItemCallback({
|
||||||
|
kind: "clock",
|
||||||
|
})(input as unknown as Board);
|
||||||
|
|
||||||
|
const firstSectionResult = result.sections.find((section) => section.id === "2");
|
||||||
|
const item = firstSectionResult?.items.find((item) => item.id !== "12");
|
||||||
|
expect(item).toEqual(expect.objectContaining({ kind: "clock", xOffset: 5, yOffset: 5 }));
|
||||||
|
expect(spy).toHaveBeenCalledWith([expectedItem, dynamicSectionInFirst], input.columnCount);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
import { describe, expect, test, vi } from "vitest";
|
||||||
|
|
||||||
|
import type { Board } from "~/app/[locale]/boards/_types";
|
||||||
|
import { duplicateItemCallback } from "../duplicate-item";
|
||||||
|
import * as emptyPosition from "../empty-position";
|
||||||
|
import { createEmptySection, createItem } from "./shared";
|
||||||
|
|
||||||
|
describe("item actions duplicate-item", () => {
|
||||||
|
test("should copy it in the same section", () => {
|
||||||
|
const spy = vi.spyOn(emptyPosition, "getFirstEmptyPosition");
|
||||||
|
spy.mockReturnValue({ xOffset: 5, yOffset: 5 });
|
||||||
|
const currentSection = createEmptySection("2", 1);
|
||||||
|
const currentItem = createItem({
|
||||||
|
id: "1",
|
||||||
|
xOffset: 1,
|
||||||
|
yOffset: 3,
|
||||||
|
width: 3,
|
||||||
|
height: 2,
|
||||||
|
kind: "minecraftServerStatus",
|
||||||
|
integrationIds: ["1"],
|
||||||
|
options: { address: "localhost" },
|
||||||
|
advancedOptions: { customCssClasses: ["test"] },
|
||||||
|
});
|
||||||
|
const otherItem = createItem({
|
||||||
|
id: "2",
|
||||||
|
});
|
||||||
|
currentSection.items.push(currentItem, otherItem);
|
||||||
|
const input = {
|
||||||
|
columnCount: 10,
|
||||||
|
sections: [createEmptySection("1", 0), currentSection, createEmptySection("3", 2)],
|
||||||
|
} satisfies Pick<Board, "sections" | "columnCount">;
|
||||||
|
|
||||||
|
const result = duplicateItemCallback({ itemId: currentItem.id })(input as unknown as Board);
|
||||||
|
|
||||||
|
const section = result.sections.find((section) => section.id === "2");
|
||||||
|
expect(section?.items.length).toBe(3);
|
||||||
|
const duplicatedItem = section?.items.find((item) => item.id !== currentItem.id && item.id !== otherItem.id);
|
||||||
|
|
||||||
|
expect(duplicatedItem).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
kind: "minecraftServerStatus",
|
||||||
|
xOffset: 5,
|
||||||
|
yOffset: 5,
|
||||||
|
width: 3,
|
||||||
|
height: 2,
|
||||||
|
integrationIds: ["1"],
|
||||||
|
options: { address: "localhost" },
|
||||||
|
advancedOptions: { customCssClasses: ["test"] },
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,138 @@
|
|||||||
|
import { describe, expect, test } from "vitest";
|
||||||
|
|
||||||
|
import type { Item } from "~/app/[locale]/boards/_types";
|
||||||
|
import { getFirstEmptyPosition } from "../empty-position";
|
||||||
|
|
||||||
|
describe("get first empty position", () => {
|
||||||
|
test.each([
|
||||||
|
[[[" ", " ", " ", " "]], [1, 1], 0, 0],
|
||||||
|
[[["a", " ", " ", " "]], [1, 1], 1, 0],
|
||||||
|
[[[" ", "a", " ", " "]], [1, 1], 0, 0],
|
||||||
|
[
|
||||||
|
[
|
||||||
|
["a", "a", " ", " "],
|
||||||
|
["a", "a", " ", " "],
|
||||||
|
],
|
||||||
|
[1, 1],
|
||||||
|
2,
|
||||||
|
0,
|
||||||
|
],
|
||||||
|
[[["a", "a", "a", "a"]], [1, 1], 0, 1],
|
||||||
|
[
|
||||||
|
[
|
||||||
|
["a", "a", "a", "a"],
|
||||||
|
["a", "a", "a", "a"],
|
||||||
|
],
|
||||||
|
[1, 1],
|
||||||
|
0,
|
||||||
|
2,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
[
|
||||||
|
["a", "a", " ", "b", "b"],
|
||||||
|
["a", "a", " ", "b", "b"],
|
||||||
|
],
|
||||||
|
[1, 2],
|
||||||
|
2,
|
||||||
|
0,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
[
|
||||||
|
["a", "a", " ", " ", "b", "b"],
|
||||||
|
["a", "a", " ", " ", "b", "b"],
|
||||||
|
],
|
||||||
|
[2, 2],
|
||||||
|
2,
|
||||||
|
0,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
[
|
||||||
|
["a", "a", " ", "d", "b", "b"],
|
||||||
|
["a", "a", "c", "e", "b", "b"],
|
||||||
|
],
|
||||||
|
[1, 1],
|
||||||
|
2,
|
||||||
|
0,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
[
|
||||||
|
["a", "a", " ", " ", "b", "b"],
|
||||||
|
["a", "a", " ", "e", "b", "b"],
|
||||||
|
],
|
||||||
|
[2, 2],
|
||||||
|
0,
|
||||||
|
2,
|
||||||
|
],
|
||||||
|
])("should return the first empty position", (layout, size, expectedX, expectedY) => {
|
||||||
|
const elements = createElementsFromLayout(layout);
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||||
|
const result = getFirstEmptyPosition(elements, layout[0]!.length, undefined, { width: size[0]!, height: size[1]! });
|
||||||
|
|
||||||
|
expect(result).toEqual({ xOffset: expectedX, yOffset: expectedY });
|
||||||
|
});
|
||||||
|
|
||||||
|
test.each([
|
||||||
|
[[[" ", " "]], [1, 1], 0, 0, 1],
|
||||||
|
[[["a", " "]], [1, 1], 1, 0, 1],
|
||||||
|
[[["a", "a"]], [1, 1], undefined, undefined, 1],
|
||||||
|
[[["a", "a"]], [1, 1], 0, 1, 2],
|
||||||
|
[
|
||||||
|
[
|
||||||
|
["a", "b", " ", " "],
|
||||||
|
["a", "c", " ", "d"],
|
||||||
|
],
|
||||||
|
[2, 2],
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
3,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
[
|
||||||
|
["a", "b", " ", " "],
|
||||||
|
["a", "c", " ", "d"],
|
||||||
|
],
|
||||||
|
[2, 2],
|
||||||
|
0,
|
||||||
|
2,
|
||||||
|
4,
|
||||||
|
],
|
||||||
|
[[["a", "b"]], [2, 1], 0, 1, 2],
|
||||||
|
])("should return the first empty position with limited rows", (layout, size, expectedX, expectedY, rowCount) => {
|
||||||
|
const elements = createElementsFromLayout(layout);
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||||
|
const result = getFirstEmptyPosition(elements, layout[0]!.length, rowCount, { width: size[0]!, height: size[1]! });
|
||||||
|
|
||||||
|
expect(result).toEqual(expectedX !== undefined ? { xOffset: expectedX, yOffset: expectedY } : undefined);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
const createElementsFromLayout = (layout: string[][]) => {
|
||||||
|
const elements: (Pick<Item, "xOffset" | "yOffset" | "width" | "height"> & { char: string })[] = [];
|
||||||
|
for (let yOffset = 0; yOffset < layout.length; yOffset++) {
|
||||||
|
const row = layout[yOffset];
|
||||||
|
if (!row) continue;
|
||||||
|
for (let xOffset = 0; xOffset < row.length; xOffset++) {
|
||||||
|
const item = row[xOffset];
|
||||||
|
if (item === " " || !item) continue;
|
||||||
|
|
||||||
|
const existing = elements.find((element) => element.char === item);
|
||||||
|
if (existing) {
|
||||||
|
existing.height = yOffset - existing.yOffset + 1;
|
||||||
|
existing.width = xOffset - existing.xOffset + 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
elements.push({
|
||||||
|
yOffset,
|
||||||
|
xOffset,
|
||||||
|
width: 1,
|
||||||
|
height: 1,
|
||||||
|
char: item,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return elements;
|
||||||
|
};
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
import type { DynamicSection, EmptySection, Item } from "~/app/[locale]/boards/_types";
|
||||||
|
|
||||||
|
export const createEmptySection = (id: string, yOffset: number): EmptySection => ({
|
||||||
|
id,
|
||||||
|
kind: "empty",
|
||||||
|
yOffset,
|
||||||
|
xOffset: 0,
|
||||||
|
items: [],
|
||||||
|
});
|
||||||
|
|
||||||
|
export const createDynamicSection = (section: Omit<Partial<DynamicSection>, "kind">): DynamicSection => ({
|
||||||
|
id: section.id ?? "0",
|
||||||
|
kind: "dynamic",
|
||||||
|
parentSectionId: section.parentSectionId ?? "0",
|
||||||
|
height: section.height ?? 1,
|
||||||
|
width: section.width ?? 1,
|
||||||
|
yOffset: section.yOffset ?? 0,
|
||||||
|
xOffset: section.xOffset ?? 0,
|
||||||
|
items: section.items ?? [],
|
||||||
|
});
|
||||||
|
|
||||||
|
export const createItem = (item: Partial<Item>): Item => ({
|
||||||
|
id: item.id ?? "0",
|
||||||
|
width: item.width ?? 1,
|
||||||
|
height: item.height ?? 1,
|
||||||
|
yOffset: item.yOffset ?? 0,
|
||||||
|
xOffset: item.xOffset ?? 0,
|
||||||
|
kind: item.kind ?? "clock",
|
||||||
|
integrationIds: item.integrationIds ?? [],
|
||||||
|
options: item.options ?? {},
|
||||||
|
advancedOptions: item.advancedOptions ?? { customCssClasses: [] },
|
||||||
|
});
|
||||||
@@ -1,12 +1,13 @@
|
|||||||
import { useCallback } from "react";
|
import { useCallback } from "react";
|
||||||
|
|
||||||
import type { Modify } from "@homarr/common/types";
|
|
||||||
import { createId } from "@homarr/db/client";
|
|
||||||
import type { WidgetKind } from "@homarr/definitions";
|
|
||||||
import type { BoardItemAdvancedOptions } from "@homarr/validation";
|
import type { BoardItemAdvancedOptions } from "@homarr/validation";
|
||||||
|
|
||||||
import type { EmptySection, Item } from "~/app/[locale]/boards/_types";
|
import type { Item } from "~/app/[locale]/boards/_types";
|
||||||
import { useUpdateBoard } from "~/app/[locale]/boards/(content)/_client";
|
import { useUpdateBoard } from "~/app/[locale]/boards/(content)/_client";
|
||||||
|
import type { CreateItemInput } from "./actions/create-item";
|
||||||
|
import { createItemCallback } from "./actions/create-item";
|
||||||
|
import type { DuplicateItemInput } from "./actions/duplicate-item";
|
||||||
|
import { duplicateItemCallback } from "./actions/duplicate-item";
|
||||||
|
|
||||||
interface MoveAndResizeItem {
|
interface MoveAndResizeItem {
|
||||||
itemId: string;
|
itemId: string;
|
||||||
@@ -42,87 +43,19 @@ interface UpdateItemIntegrations {
|
|||||||
newIntegrations: string[];
|
newIntegrations: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
interface CreateItem {
|
|
||||||
kind: WidgetKind;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface DuplicateItem {
|
|
||||||
itemId: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const useItemActions = () => {
|
export const useItemActions = () => {
|
||||||
const { updateBoard } = useUpdateBoard();
|
const { updateBoard } = useUpdateBoard();
|
||||||
|
|
||||||
const createItem = useCallback(
|
const createItem = useCallback(
|
||||||
({ kind }: CreateItem) => {
|
(input: CreateItemInput) => {
|
||||||
updateBoard((previous) => {
|
updateBoard(createItemCallback(input));
|
||||||
const lastSection = previous.sections
|
|
||||||
.filter((section): section is EmptySection => section.kind === "empty")
|
|
||||||
.sort((sectionA, sectionB) => sectionB.yOffset - sectionA.yOffset)[0];
|
|
||||||
|
|
||||||
if (!lastSection) return previous;
|
|
||||||
|
|
||||||
const widget = {
|
|
||||||
id: createId(),
|
|
||||||
kind,
|
|
||||||
options: {},
|
|
||||||
width: 1,
|
|
||||||
height: 1,
|
|
||||||
integrationIds: [],
|
|
||||||
advancedOptions: {
|
|
||||||
customCssClasses: [],
|
|
||||||
},
|
|
||||||
} satisfies Modify<
|
|
||||||
Omit<Item, "yOffset" | "xOffset">,
|
|
||||||
{
|
|
||||||
kind: WidgetKind;
|
|
||||||
}
|
|
||||||
>;
|
|
||||||
|
|
||||||
return {
|
|
||||||
...previous,
|
|
||||||
sections: previous.sections.map((section) => {
|
|
||||||
// Return same section if item is not in it
|
|
||||||
if (section.id !== lastSection.id) return section;
|
|
||||||
return {
|
|
||||||
...section,
|
|
||||||
items: section.items.concat(widget as unknown as Item),
|
|
||||||
};
|
|
||||||
}),
|
|
||||||
};
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
[updateBoard],
|
[updateBoard],
|
||||||
);
|
);
|
||||||
|
|
||||||
const duplicateItem = useCallback(
|
const duplicateItem = useCallback(
|
||||||
({ itemId }: DuplicateItem) => {
|
({ itemId }: DuplicateItemInput) => {
|
||||||
updateBoard((previous) => {
|
updateBoard(duplicateItemCallback({ itemId }));
|
||||||
const itemToDuplicate = previous.sections
|
|
||||||
.flatMap((section) => section.items)
|
|
||||||
.find((item) => item.id === itemId);
|
|
||||||
|
|
||||||
if (!itemToDuplicate) return previous;
|
|
||||||
|
|
||||||
const newItem = {
|
|
||||||
...itemToDuplicate,
|
|
||||||
id: createId(),
|
|
||||||
yOffset: undefined,
|
|
||||||
xOffset: undefined,
|
|
||||||
} satisfies Modify<Item, { yOffset?: number; xOffset?: number }>;
|
|
||||||
|
|
||||||
return {
|
|
||||||
...previous,
|
|
||||||
sections: previous.sections.map((section) => {
|
|
||||||
// Return same section if item is not in it
|
|
||||||
if (!section.items.some((item) => item.id === itemId)) return section;
|
|
||||||
return {
|
|
||||||
...section,
|
|
||||||
items: section.items.concat(newItem as unknown as Item),
|
|
||||||
};
|
|
||||||
}),
|
|
||||||
};
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
[updateBoard],
|
[updateBoard],
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -79,7 +79,12 @@ const InnerContent = ({ item, ...dimensions }: InnerContentProps) => {
|
|||||||
>
|
>
|
||||||
<Throw
|
<Throw
|
||||||
error={new NoIntegrationSelectedError()}
|
error={new NoIntegrationSelectedError()}
|
||||||
when={widgetSupportsIntegrations && item.integrationIds.length === 0}
|
when={
|
||||||
|
widgetSupportsIntegrations &&
|
||||||
|
item.integrationIds.length === 0 &&
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||||
|
(!("integrationsRequired" in definition) || definition.integrationsRequired !== false)
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
<BoardItemMenu offset={4} item={newItem} />
|
<BoardItemMenu offset={4} item={newItem} />
|
||||||
<Comp
|
<Comp
|
||||||
|
|||||||
@@ -12,11 +12,7 @@ export const env = createEnv({
|
|||||||
* Specify your server-side environment variables schema here. This way you can ensure the app isn't
|
* Specify your server-side environment variables schema here. This way you can ensure the app isn't
|
||||||
* built with invalid env vars.
|
* built with invalid env vars.
|
||||||
*/
|
*/
|
||||||
server: {
|
server: {},
|
||||||
// Comma separated list of docker hostnames that can be used to connect to query the docker endpoints (localhost:2375,host.docker.internal:2375, ...)
|
|
||||||
DOCKER_HOSTNAMES: z.string().optional(),
|
|
||||||
DOCKER_PORTS: z.string().optional(),
|
|
||||||
},
|
|
||||||
/**
|
/**
|
||||||
* Specify your client-side environment variables schema here.
|
* Specify your client-side environment variables schema here.
|
||||||
* For them to be exposed to the client, prefix them with `NEXT_PUBLIC_`.
|
* For them to be exposed to the client, prefix them with `NEXT_PUBLIC_`.
|
||||||
@@ -30,9 +26,8 @@ export const env = createEnv({
|
|||||||
runtimeEnv: {
|
runtimeEnv: {
|
||||||
PORT: process.env.PORT,
|
PORT: process.env.PORT,
|
||||||
NODE_ENV: process.env.NODE_ENV,
|
NODE_ENV: process.env.NODE_ENV,
|
||||||
DOCKER_HOSTNAMES: process.env.DOCKER_HOSTNAMES,
|
|
||||||
DOCKER_PORTS: process.env.DOCKER_PORTS,
|
|
||||||
// NEXT_PUBLIC_CLIENTVAR: process.env.NEXT_PUBLIC_CLIENTVAR,
|
// NEXT_PUBLIC_CLIENTVAR: process.env.NEXT_PUBLIC_CLIENTVAR,
|
||||||
},
|
},
|
||||||
skipValidation: shouldSkipEnvValidation(),
|
skipValidation: shouldSkipEnvValidation(),
|
||||||
|
emptyStringAsUndefined: true,
|
||||||
});
|
});
|
||||||
@@ -38,13 +38,13 @@
|
|||||||
"dayjs": "^1.11.13",
|
"dayjs": "^1.11.13",
|
||||||
"dotenv": "^16.4.7",
|
"dotenv": "^16.4.7",
|
||||||
"superjson": "2.2.2",
|
"superjson": "2.2.2",
|
||||||
"undici": "7.2.1"
|
"undici": "7.3.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@homarr/eslint-config": "workspace:^0.2.0",
|
"@homarr/eslint-config": "workspace:^0.2.0",
|
||||||
"@homarr/prettier-config": "workspace:^0.1.0",
|
"@homarr/prettier-config": "workspace:^0.1.0",
|
||||||
"@homarr/tsconfig": "workspace:^0.1.0",
|
"@homarr/tsconfig": "workspace:^0.1.0",
|
||||||
"@types/node": "^22.10.6",
|
"@types/node": "^22.10.10",
|
||||||
"dotenv-cli": "^8.0.0",
|
"dotenv-cli": "^8.0.0",
|
||||||
"eslint": "^9.18.0",
|
"eslint": "^9.18.0",
|
||||||
"prettier": "^3.4.2",
|
"prettier": "^3.4.2",
|
||||||
|
|||||||
@@ -1,35 +1,6 @@
|
|||||||
import type { Dispatcher } from "undici";
|
import { setGlobalDispatcher } from "undici";
|
||||||
import { Agent, setGlobalDispatcher } from "undici";
|
|
||||||
|
|
||||||
import { logger } from "@homarr/log";
|
import { LoggingAgent } from "@homarr/common/server";
|
||||||
|
|
||||||
export class LoggingAgent extends Agent {
|
|
||||||
constructor(...props: ConstructorParameters<typeof Agent>) {
|
|
||||||
super(...props);
|
|
||||||
}
|
|
||||||
|
|
||||||
dispatch(options: Dispatcher.DispatchOptions, handler: Dispatcher.DispatchHandler): boolean {
|
|
||||||
const url = new URL(`${options.origin as string}${options.path}`);
|
|
||||||
|
|
||||||
// The below code should prevent sensitive data from being logged as
|
|
||||||
// some integrations use query parameters for auth
|
|
||||||
url.searchParams.forEach((value, key) => {
|
|
||||||
if (value === "") return; // Skip empty values
|
|
||||||
if (/^-?\d{1,12}$/.test(value)) return; // Skip small numbers
|
|
||||||
if (value === "true" || value === "false") return; // Skip boolean values
|
|
||||||
if (/^[a-zA-Z]{1,12}$/.test(value)) return; // Skip short strings
|
|
||||||
if (/^\d{4}-\d{2}-\d{2}$/.test(value)) return; // Skip dates
|
|
||||||
if (/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/.test(value)) return; // Skip date times
|
|
||||||
|
|
||||||
url.searchParams.set(key, "REDACTED");
|
|
||||||
});
|
|
||||||
|
|
||||||
logger.info(
|
|
||||||
`Dispatching request ${url.toString().replaceAll("=&", "&")} (${Object.keys(options.headers ?? {}).length} headers)`,
|
|
||||||
);
|
|
||||||
return super.dispatch(options, handler);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const agent = new LoggingAgent();
|
const agent = new LoggingAgent();
|
||||||
setGlobalDispatcher(agent);
|
setGlobalDispatcher(agent);
|
||||||
@@ -33,7 +33,7 @@
|
|||||||
"@homarr/eslint-config": "workspace:^0.2.0",
|
"@homarr/eslint-config": "workspace:^0.2.0",
|
||||||
"@homarr/prettier-config": "workspace:^0.1.0",
|
"@homarr/prettier-config": "workspace:^0.1.0",
|
||||||
"@homarr/tsconfig": "workspace:^0.1.0",
|
"@homarr/tsconfig": "workspace:^0.1.0",
|
||||||
"@types/ws": "^8.5.13",
|
"@types/ws": "^8.5.14",
|
||||||
"eslint": "^9.18.0",
|
"eslint": "^9.18.0",
|
||||||
"prettier": "^3.4.2",
|
"prettier": "^3.4.2",
|
||||||
"typescript": "^5.7.3"
|
"typescript": "^5.7.3"
|
||||||
|
|||||||
+3
-10
@@ -24,10 +24,10 @@
|
|||||||
<strong>Demo ✨</strong>
|
<strong>Demo ✨</strong>
|
||||||
</a>
|
</a>
|
||||||
•
|
•
|
||||||
<a href="https://homarr.dev/docs/getting-started/installation/">
|
<a href="https://homarr.dev/docs/category/installation-1/">
|
||||||
<strong>Install 💻</strong>
|
<strong>Install 💻</strong>
|
||||||
</a> •
|
</a> •
|
||||||
<a href="https://translate.homarr.dev/">
|
<a href="https://crowdin.com/project/homarr_labs">
|
||||||
<strong>Translations 🈺</strong>
|
<strong>Translations 🈺</strong>
|
||||||
</a> •
|
</a> •
|
||||||
<a href="https://discord.com/invite/aCsmEV5RgA">
|
<a href="https://discord.com/invite/aCsmEV5RgA">
|
||||||
@@ -35,13 +35,6 @@
|
|||||||
</a>
|
</a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
> [!WARNING]
|
|
||||||
> This is a beta version of Homarr. You can download the old but stable version at https://github.com/ajnart/homarr/. Running this version is at your own risk.
|
|
||||||
|
|
||||||
Simplify the management of your server with Homarr - a sleek, modern dashboard that puts all of your apps and services at your fingertips. With Homarr, you can access and control everything in one location. Homarr seamlessly integrates with the apps you've added, providing you with valuable information and giving you complete control. Installation is a breeze, and Homarr supports a wide range of deployment methods.
|
|
||||||
|
|
||||||
<br/>
|
|
||||||
<br/>
|
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
@@ -100,7 +93,7 @@ Homarr has a [built-in collection of widgets and integrations](https://homarr.de
|
|||||||
Since we are updating Homarr very frequently, we recommend reading our official installation guides:
|
Since we are updating Homarr very frequently, we recommend reading our official installation guides:
|
||||||
|
|
||||||
<h2>
|
<h2>
|
||||||
<a href="https://homarr.dev/docs/getting-started/installation/">
|
<a href="https://homarr.dev/docs/category/installation-1/">
|
||||||
Please click here for official installation instructions
|
Please click here for official installation instructions
|
||||||
</a>
|
</a>
|
||||||
</h2>
|
</h2>
|
||||||
|
|||||||
@@ -49,9 +49,9 @@ describe("Onboarding", () => {
|
|||||||
environment: {
|
environment: {
|
||||||
AUTH_PROVIDERS: "ldap",
|
AUTH_PROVIDERS: "ldap",
|
||||||
AUTH_LDAP_URI: "ldap://host.docker.internal:3890",
|
AUTH_LDAP_URI: "ldap://host.docker.internal:3890",
|
||||||
AUTH_LDAP_BASE: "",
|
AUTH_LDAP_BASE: "not-used",
|
||||||
AUTH_LDAP_BIND_DN: "",
|
AUTH_LDAP_BIND_DN: "not-used",
|
||||||
AUTH_LDAP_BIND_PASSWORD: "",
|
AUTH_LDAP_BIND_PASSWORD: "not-used",
|
||||||
},
|
},
|
||||||
mounts: {
|
mounts: {
|
||||||
"/appdata": localMountPath,
|
"/appdata": localMountPath,
|
||||||
|
|||||||
+11
-8
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "homarr",
|
"name": "homarr",
|
||||||
"version": "1.0.0-beta.12",
|
"version": "1.2.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "cross-env CI=true turbo build",
|
"build": "cross-env CI=true turbo build",
|
||||||
@@ -38,27 +38,30 @@
|
|||||||
"@semantic-release/github": "^11.0.1",
|
"@semantic-release/github": "^11.0.1",
|
||||||
"@semantic-release/npm": "^12.0.1",
|
"@semantic-release/npm": "^12.0.1",
|
||||||
"@semantic-release/release-notes-generator": "^14.0.3",
|
"@semantic-release/release-notes-generator": "^14.0.3",
|
||||||
"@turbo/gen": "^2.3.3",
|
"@turbo/gen": "^2.3.4",
|
||||||
"@vitejs/plugin-react": "^4.3.4",
|
"@vitejs/plugin-react": "^4.3.4",
|
||||||
"@vitest/coverage-v8": "^2.1.8",
|
"@vitest/coverage-v8": "^3.0.4",
|
||||||
"@vitest/ui": "^2.1.8",
|
"@vitest/ui": "^3.0.4",
|
||||||
"conventional-changelog-conventionalcommits": "^8.0.0",
|
"conventional-changelog-conventionalcommits": "^8.0.0",
|
||||||
"cross-env": "^7.0.3",
|
"cross-env": "^7.0.3",
|
||||||
"jsdom": "^26.0.0",
|
"jsdom": "^26.0.0",
|
||||||
"prettier": "^3.4.2",
|
"prettier": "^3.4.2",
|
||||||
"semantic-release": "^24.2.1",
|
"semantic-release": "^24.2.1",
|
||||||
"testcontainers": "^10.16.0",
|
"testcontainers": "^10.17.1",
|
||||||
"turbo": "^2.3.3",
|
"turbo": "^2.3.4",
|
||||||
"typescript": "^5.7.3",
|
"typescript": "^5.7.3",
|
||||||
"vite-tsconfig-paths": "^5.1.4",
|
"vite-tsconfig-paths": "^5.1.4",
|
||||||
"vitest": "^2.1.8"
|
"vitest": "^3.0.4"
|
||||||
},
|
},
|
||||||
"packageManager": "pnpm@9.15.4",
|
"packageManager": "pnpm@9.15.4",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=22.13.0"
|
"node": ">=22.13.1"
|
||||||
},
|
},
|
||||||
"pnpm": {
|
"pnpm": {
|
||||||
"allowNonAppliedPatches": true,
|
"allowNonAppliedPatches": true,
|
||||||
|
"overrides": {
|
||||||
|
"proxmox-api>undici": "7.3.0"
|
||||||
|
},
|
||||||
"patchedDependencies": {
|
"patchedDependencies": {
|
||||||
"pretty-print-error": "patches/pretty-print-error.patch"
|
"pretty-print-error": "patches/pretty-print-error.patch"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,12 +22,14 @@
|
|||||||
"prettier": "@homarr/prettier-config",
|
"prettier": "@homarr/prettier-config",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@homarr/auth": "workspace:^0.1.0",
|
"@homarr/auth": "workspace:^0.1.0",
|
||||||
|
"@homarr/certificates": "workspace:^0.1.0",
|
||||||
"@homarr/common": "workspace:^0.1.0",
|
"@homarr/common": "workspace:^0.1.0",
|
||||||
"@homarr/cron-job-runner": "workspace:^0.1.0",
|
"@homarr/cron-job-runner": "workspace:^0.1.0",
|
||||||
"@homarr/cron-job-status": "workspace:^0.1.0",
|
"@homarr/cron-job-status": "workspace:^0.1.0",
|
||||||
"@homarr/cron-jobs": "workspace:^0.1.0",
|
"@homarr/cron-jobs": "workspace:^0.1.0",
|
||||||
"@homarr/db": "workspace:^0.1.0",
|
"@homarr/db": "workspace:^0.1.0",
|
||||||
"@homarr/definitions": "workspace:^0.1.0",
|
"@homarr/definitions": "workspace:^0.1.0",
|
||||||
|
"@homarr/docker": "workspace:^0.1.0",
|
||||||
"@homarr/icons": "workspace:^0.1.0",
|
"@homarr/icons": "workspace:^0.1.0",
|
||||||
"@homarr/integrations": "workspace:^0.1.0",
|
"@homarr/integrations": "workspace:^0.1.0",
|
||||||
"@homarr/log": "workspace:^",
|
"@homarr/log": "workspace:^",
|
||||||
@@ -41,9 +43,8 @@
|
|||||||
"@trpc/client": "next",
|
"@trpc/client": "next",
|
||||||
"@trpc/react-query": "next",
|
"@trpc/react-query": "next",
|
||||||
"@trpc/server": "next",
|
"@trpc/server": "next",
|
||||||
"dockerode": "^4.0.3",
|
|
||||||
"lodash.clonedeep": "^4.5.0",
|
"lodash.clonedeep": "^4.5.0",
|
||||||
"next": "15.1.4",
|
"next": "15.1.6",
|
||||||
"react": "19.0.0",
|
"react": "19.0.0",
|
||||||
"react-dom": "19.0.0",
|
"react-dom": "19.0.0",
|
||||||
"superjson": "2.2.2",
|
"superjson": "2.2.2",
|
||||||
@@ -53,7 +54,6 @@
|
|||||||
"@homarr/eslint-config": "workspace:^0.2.0",
|
"@homarr/eslint-config": "workspace:^0.2.0",
|
||||||
"@homarr/prettier-config": "workspace:^0.1.0",
|
"@homarr/prettier-config": "workspace:^0.1.0",
|
||||||
"@homarr/tsconfig": "workspace:^0.1.0",
|
"@homarr/tsconfig": "workspace:^0.1.0",
|
||||||
"@types/dockerode": "^3.3.34",
|
|
||||||
"eslint": "^9.18.0",
|
"eslint": "^9.18.0",
|
||||||
"prettier": "^3.4.2",
|
"prettier": "^3.4.2",
|
||||||
"typescript": "^5.7.3"
|
"typescript": "^5.7.3"
|
||||||
|
|||||||
@@ -98,56 +98,59 @@ export const createManyIntegrationMiddleware = <TKind extends IntegrationKind>(
|
|||||||
action: IntegrationAction,
|
action: IntegrationAction,
|
||||||
...kinds: AtLeastOneOf<TKind> // Ensure at least one kind is provided
|
...kinds: AtLeastOneOf<TKind> // Ensure at least one kind is provided
|
||||||
) => {
|
) => {
|
||||||
return publicProcedure
|
return publicProcedure.input(z.object({ integrationIds: z.array(z.string()) })).use(async ({ ctx, input, next }) => {
|
||||||
.input(z.object({ integrationIds: z.array(z.string()).min(1) }))
|
const dbIntegrations =
|
||||||
.use(async ({ ctx, input, next }) => {
|
input.integrationIds.length >= 1
|
||||||
const dbIntegrations = await ctx.db.query.integrations.findMany({
|
? await ctx.db.query.integrations.findMany({
|
||||||
where: and(inArray(integrations.id, input.integrationIds), inArray(integrations.kind, kinds)),
|
where: and(inArray(integrations.id, input.integrationIds), inArray(integrations.kind, kinds)),
|
||||||
with: {
|
|
||||||
secrets: true,
|
|
||||||
items: {
|
|
||||||
with: {
|
with: {
|
||||||
item: {
|
secrets: true,
|
||||||
|
items: {
|
||||||
with: {
|
with: {
|
||||||
section: {
|
item: {
|
||||||
columns: {
|
with: {
|
||||||
boardId: true,
|
section: {
|
||||||
|
columns: {
|
||||||
|
boardId: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
userPermissions: true,
|
||||||
|
groupPermissions: true,
|
||||||
},
|
},
|
||||||
},
|
})
|
||||||
userPermissions: true,
|
: [];
|
||||||
groupPermissions: true,
|
|
||||||
},
|
const offset = input.integrationIds.length - dbIntegrations.length;
|
||||||
|
if (offset !== 0) {
|
||||||
|
throw new TRPCError({
|
||||||
|
code: "NOT_FOUND",
|
||||||
|
message: `${offset} of the specified integrations not found or not of kinds ${kinds.join(",")}: ([${input.integrationIds.join(",")}] compared to [${dbIntegrations.map(({ id, kind }) => `${kind}:${id}`).join(",")}])`,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const offset = input.integrationIds.length - dbIntegrations.length;
|
if (dbIntegrations.length >= 1) {
|
||||||
if (offset !== 0) {
|
|
||||||
throw new TRPCError({
|
|
||||||
code: "NOT_FOUND",
|
|
||||||
message: `${offset} of the specified integrations not found or not of kinds ${kinds.join(",")}: ([${input.integrationIds.join(",")}] compared to [${dbIntegrations.map(({ id, kind }) => `${kind}:${id}`).join(",")}])`,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
await throwIfActionIsNotAllowedAsync(action, ctx.db, dbIntegrations, ctx.session);
|
await throwIfActionIsNotAllowedAsync(action, ctx.db, dbIntegrations, ctx.session);
|
||||||
|
}
|
||||||
|
|
||||||
return next({
|
return next({
|
||||||
ctx: {
|
ctx: {
|
||||||
integrations: dbIntegrations.map(
|
integrations: dbIntegrations.map(
|
||||||
({ secrets, kind, items: _ignore1, groupPermissions: _ignore2, userPermissions: _ignore3, ...rest }) => ({
|
({ secrets, kind, items: _ignore1, groupPermissions: _ignore2, userPermissions: _ignore3, ...rest }) => ({
|
||||||
...rest,
|
...rest,
|
||||||
kind: kind as TKind,
|
kind: kind as TKind,
|
||||||
decryptedSecrets: secrets.map((secret) => ({
|
decryptedSecrets: secrets.map((secret) => ({
|
||||||
...secret,
|
...secret,
|
||||||
value: decryptSecret(secret.value),
|
value: decryptSecret(secret.value),
|
||||||
})),
|
})),
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { apiKeysRouter } from "./router/apiKeys";
|
import { apiKeysRouter } from "./router/apiKeys";
|
||||||
import { appRouter as innerAppRouter } from "./router/app";
|
import { appRouter as innerAppRouter } from "./router/app";
|
||||||
import { boardRouter } from "./router/board";
|
import { boardRouter } from "./router/board";
|
||||||
|
import { certificateRouter } from "./router/certificates/certificate-router";
|
||||||
import { cronJobsRouter } from "./router/cron-jobs";
|
import { cronJobsRouter } from "./router/cron-jobs";
|
||||||
import { dockerRouter } from "./router/docker/docker-router";
|
import { dockerRouter } from "./router/docker/docker-router";
|
||||||
import { groupRouter } from "./router/group";
|
import { groupRouter } from "./router/group";
|
||||||
@@ -41,6 +42,7 @@ export const appRouter = createTRPCRouter({
|
|||||||
apiKeys: apiKeysRouter,
|
apiKeys: apiKeysRouter,
|
||||||
media: mediaRouter,
|
media: mediaRouter,
|
||||||
updateChecker: updateCheckerRouter,
|
updateChecker: updateCheckerRouter,
|
||||||
|
certificates: certificateRouter,
|
||||||
});
|
});
|
||||||
|
|
||||||
// export type definition of API
|
// export type definition of API
|
||||||
|
|||||||
+460
-193
@@ -4,7 +4,7 @@ import superjson from "superjson";
|
|||||||
import { constructBoardPermissions } from "@homarr/auth/shared";
|
import { constructBoardPermissions } from "@homarr/auth/shared";
|
||||||
import type { DeviceType } from "@homarr/common/server";
|
import type { DeviceType } from "@homarr/common/server";
|
||||||
import type { Database, InferInsertModel, InferSelectModel, SQL } from "@homarr/db";
|
import type { Database, InferInsertModel, InferSelectModel, SQL } from "@homarr/db";
|
||||||
import { and, createId, eq, inArray, like, or } from "@homarr/db";
|
import { and, createId, eq, handleTransactionsAsync, inArray, like, or } from "@homarr/db";
|
||||||
import { getServerSettingByKeyAsync } from "@homarr/db/queries";
|
import { getServerSettingByKeyAsync } from "@homarr/db/queries";
|
||||||
import {
|
import {
|
||||||
boardGroupPermissions,
|
boardGroupPermissions,
|
||||||
@@ -204,21 +204,49 @@ export const boardRouter = createTRPCRouter({
|
|||||||
.input(validation.board.create)
|
.input(validation.board.create)
|
||||||
.mutation(async ({ ctx, input }) => {
|
.mutation(async ({ ctx, input }) => {
|
||||||
const boardId = createId();
|
const boardId = createId();
|
||||||
await ctx.db.transaction(async (transaction) => {
|
await handleTransactionsAsync(ctx.db, {
|
||||||
await transaction.insert(boards).values({
|
async handleAsync(db, schema) {
|
||||||
id: boardId,
|
await db.transaction(async (transaction) => {
|
||||||
name: input.name,
|
await transaction.insert(schema.boards).values({
|
||||||
isPublic: input.isPublic,
|
id: boardId,
|
||||||
columnCount: input.columnCount,
|
name: input.name,
|
||||||
creatorId: ctx.session.user.id,
|
isPublic: input.isPublic,
|
||||||
});
|
columnCount: input.columnCount,
|
||||||
await transaction.insert(sections).values({
|
creatorId: ctx.session.user.id,
|
||||||
id: createId(),
|
});
|
||||||
kind: "empty",
|
await transaction.insert(schema.sections).values({
|
||||||
xOffset: 0,
|
id: createId(),
|
||||||
yOffset: 0,
|
kind: "empty",
|
||||||
boardId,
|
xOffset: 0,
|
||||||
});
|
yOffset: 0,
|
||||||
|
boardId,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
handleSync(db) {
|
||||||
|
db.transaction((transaction) => {
|
||||||
|
transaction
|
||||||
|
.insert(boards)
|
||||||
|
.values({
|
||||||
|
id: boardId,
|
||||||
|
name: input.name,
|
||||||
|
isPublic: input.isPublic,
|
||||||
|
columnCount: input.columnCount,
|
||||||
|
creatorId: ctx.session.user.id,
|
||||||
|
})
|
||||||
|
.run();
|
||||||
|
transaction
|
||||||
|
.insert(sections)
|
||||||
|
.values({
|
||||||
|
id: createId(),
|
||||||
|
kind: "empty",
|
||||||
|
xOffset: 0,
|
||||||
|
yOffset: 0,
|
||||||
|
boardId,
|
||||||
|
})
|
||||||
|
.run();
|
||||||
|
});
|
||||||
|
},
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
duplicateBoard: permissionRequiredProcedure
|
duplicateBoard: permissionRequiredProcedure
|
||||||
@@ -302,28 +330,54 @@ export const boardRouter = createTRPCRouter({
|
|||||||
})),
|
})),
|
||||||
);
|
);
|
||||||
|
|
||||||
ctx.db.transaction((transaction) => {
|
await handleTransactionsAsync(ctx.db, {
|
||||||
transaction
|
async handleAsync(db, schema) {
|
||||||
.insert(boards)
|
await db.transaction(async (transaction) => {
|
||||||
.values({
|
transaction.insert(schema.boards).values({
|
||||||
...boardProps,
|
...boardProps,
|
||||||
id: newBoardId,
|
id: newBoardId,
|
||||||
name: input.name,
|
name: input.name,
|
||||||
creatorId: ctx.session.user.id,
|
creatorId: ctx.session.user.id,
|
||||||
})
|
});
|
||||||
.run();
|
|
||||||
|
|
||||||
if (sectionsToInsert.length > 0) {
|
if (sectionsToInsert.length > 0) {
|
||||||
transaction.insert(sections).values(sectionsToInsert).run();
|
await transaction.insert(schema.sections).values(sectionsToInsert);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (itemsToInsert.length > 0) {
|
if (itemsToInsert.length > 0) {
|
||||||
transaction.insert(items).values(itemsToInsert).run();
|
await transaction.insert(schema.items).values(itemsToInsert);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (itemIntegrationsToInsert.length > 0) {
|
if (itemIntegrationsToInsert.length > 0) {
|
||||||
transaction.insert(integrationItems).values(itemIntegrationsToInsert).run();
|
await transaction.insert(schema.integrationItems).values(itemIntegrationsToInsert);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
handleSync(db) {
|
||||||
|
db.transaction((transaction) => {
|
||||||
|
transaction
|
||||||
|
.insert(boards)
|
||||||
|
.values({
|
||||||
|
...boardProps,
|
||||||
|
id: newBoardId,
|
||||||
|
name: input.name,
|
||||||
|
creatorId: ctx.session.user.id,
|
||||||
|
})
|
||||||
|
.run();
|
||||||
|
|
||||||
|
if (sectionsToInsert.length > 0) {
|
||||||
|
transaction.insert(sections).values(sectionsToInsert).run();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (itemsToInsert.length > 0) {
|
||||||
|
transaction.insert(items).values(itemsToInsert).run();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (itemIntegrationsToInsert.length > 0) {
|
||||||
|
transaction.insert(integrationItems).values(itemIntegrationsToInsert).run();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
renameBoard: protectedProcedure.input(validation.board.rename).mutation(async ({ ctx, input }) => {
|
renameBoard: protectedProcedure.input(validation.board.rename).mutation(async ({ ctx, input }) => {
|
||||||
@@ -434,148 +488,313 @@ export const boardRouter = createTRPCRouter({
|
|||||||
saveBoard: protectedProcedure.input(validation.board.save).mutation(async ({ input, ctx }) => {
|
saveBoard: protectedProcedure.input(validation.board.save).mutation(async ({ input, ctx }) => {
|
||||||
await throwIfActionForbiddenAsync(ctx, eq(boards.id, input.id), "modify");
|
await throwIfActionForbiddenAsync(ctx, eq(boards.id, input.id), "modify");
|
||||||
|
|
||||||
await ctx.db.transaction(async (transaction) => {
|
const dbBoard = await getFullBoardWithWhereAsync(ctx.db, eq(boards.id, input.id), ctx.session.user.id);
|
||||||
const dbBoard = await getFullBoardWithWhereAsync(transaction, eq(boards.id, input.id), ctx.session.user.id);
|
|
||||||
|
|
||||||
const addedSections = filterAddedItems(input.sections, dbBoard.sections);
|
await handleTransactionsAsync(ctx.db, {
|
||||||
|
async handleAsync(db, schema) {
|
||||||
|
await db.transaction(async (transaction) => {
|
||||||
|
const addedSections = filterAddedItems(input.sections, dbBoard.sections);
|
||||||
|
|
||||||
if (addedSections.length > 0) {
|
if (addedSections.length > 0) {
|
||||||
await transaction.insert(sections).values(
|
await transaction.insert(schema.sections).values(
|
||||||
addedSections.map((section) => ({
|
addedSections.map((section) => ({
|
||||||
id: section.id,
|
id: section.id,
|
||||||
kind: section.kind,
|
kind: section.kind,
|
||||||
yOffset: section.yOffset,
|
yOffset: section.yOffset,
|
||||||
xOffset: section.kind === "dynamic" ? section.xOffset : 0,
|
xOffset: section.kind === "dynamic" ? section.xOffset : 0,
|
||||||
height: "height" in section ? section.height : null,
|
height: "height" in section ? section.height : null,
|
||||||
width: "width" in section ? section.width : null,
|
width: "width" in section ? section.width : null,
|
||||||
parentSectionId: "parentSectionId" in section ? section.parentSectionId : null,
|
parentSectionId: "parentSectionId" in section ? section.parentSectionId : null,
|
||||||
name: "name" in section ? section.name : null,
|
name: "name" in section ? section.name : null,
|
||||||
boardId: dbBoard.id,
|
boardId: dbBoard.id,
|
||||||
})),
|
})),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const inputItems = input.sections.flatMap((section) =>
|
const inputItems = input.sections.flatMap((section) =>
|
||||||
section.items.map((item) => ({ ...item, sectionId: section.id })),
|
section.items.map((item) => ({ ...item, sectionId: section.id })),
|
||||||
);
|
);
|
||||||
const dbItems = dbBoard.sections.flatMap((section) =>
|
const dbItems = dbBoard.sections.flatMap((section) =>
|
||||||
section.items.map((item) => ({ ...item, sectionId: section.id })),
|
section.items.map((item) => ({ ...item, sectionId: section.id })),
|
||||||
);
|
|
||||||
|
|
||||||
const addedItems = filterAddedItems(inputItems, dbItems);
|
|
||||||
|
|
||||||
if (addedItems.length > 0) {
|
|
||||||
await transaction.insert(items).values(
|
|
||||||
addedItems.map((item) => ({
|
|
||||||
id: item.id,
|
|
||||||
kind: item.kind,
|
|
||||||
height: item.height,
|
|
||||||
width: item.width,
|
|
||||||
xOffset: item.xOffset,
|
|
||||||
yOffset: item.yOffset,
|
|
||||||
options: superjson.stringify(item.options),
|
|
||||||
advancedOptions: superjson.stringify(item.advancedOptions),
|
|
||||||
sectionId: item.sectionId,
|
|
||||||
})),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const inputIntegrationRelations = inputItems.flatMap(({ integrationIds, id: itemId }) =>
|
|
||||||
integrationIds.map((integrationId) => ({
|
|
||||||
integrationId,
|
|
||||||
itemId,
|
|
||||||
})),
|
|
||||||
);
|
|
||||||
const dbIntegrationRelations = dbItems.flatMap(({ integrationIds, id: itemId }) =>
|
|
||||||
integrationIds.map((integrationId) => ({
|
|
||||||
integrationId,
|
|
||||||
itemId,
|
|
||||||
})),
|
|
||||||
);
|
|
||||||
const addedIntegrationRelations = inputIntegrationRelations.filter(
|
|
||||||
(inputRelation) =>
|
|
||||||
!dbIntegrationRelations.some(
|
|
||||||
(dbRelation) =>
|
|
||||||
dbRelation.itemId === inputRelation.itemId && dbRelation.integrationId === inputRelation.integrationId,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
if (addedIntegrationRelations.length > 0) {
|
|
||||||
await transaction.insert(integrationItems).values(
|
|
||||||
addedIntegrationRelations.map((relation) => ({
|
|
||||||
itemId: relation.itemId,
|
|
||||||
integrationId: relation.integrationId,
|
|
||||||
})),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const updatedItems = filterUpdatedItems(inputItems, dbItems);
|
|
||||||
|
|
||||||
for (const item of updatedItems) {
|
|
||||||
await transaction
|
|
||||||
.update(items)
|
|
||||||
.set({
|
|
||||||
kind: item.kind,
|
|
||||||
height: item.height,
|
|
||||||
width: item.width,
|
|
||||||
xOffset: item.xOffset,
|
|
||||||
yOffset: item.yOffset,
|
|
||||||
options: superjson.stringify(item.options),
|
|
||||||
advancedOptions: superjson.stringify(item.advancedOptions),
|
|
||||||
sectionId: item.sectionId,
|
|
||||||
})
|
|
||||||
.where(eq(items.id, item.id));
|
|
||||||
}
|
|
||||||
|
|
||||||
const updatedSections = filterUpdatedItems(input.sections, dbBoard.sections);
|
|
||||||
|
|
||||||
for (const section of updatedSections) {
|
|
||||||
const prev = dbBoard.sections.find((dbSection) => dbSection.id === section.id);
|
|
||||||
await transaction
|
|
||||||
.update(sections)
|
|
||||||
.set({
|
|
||||||
yOffset: section.yOffset,
|
|
||||||
xOffset: section.xOffset,
|
|
||||||
height: prev?.kind === "dynamic" && "height" in section ? section.height : null,
|
|
||||||
width: prev?.kind === "dynamic" && "width" in section ? section.width : null,
|
|
||||||
parentSectionId: prev?.kind === "dynamic" && "parentSectionId" in section ? section.parentSectionId : null,
|
|
||||||
name: prev?.kind === "category" && "name" in section ? section.name : null,
|
|
||||||
})
|
|
||||||
.where(eq(sections.id, section.id));
|
|
||||||
}
|
|
||||||
|
|
||||||
const removedIntegrationRelations = dbIntegrationRelations.filter(
|
|
||||||
(dbRelation) =>
|
|
||||||
!inputIntegrationRelations.some(
|
|
||||||
(inputRelation) =>
|
|
||||||
dbRelation.itemId === inputRelation.itemId && dbRelation.integrationId === inputRelation.integrationId,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
for (const relation of removedIntegrationRelations) {
|
|
||||||
await transaction
|
|
||||||
.delete(integrationItems)
|
|
||||||
.where(
|
|
||||||
and(
|
|
||||||
eq(integrationItems.itemId, relation.itemId),
|
|
||||||
eq(integrationItems.integrationId, relation.integrationId),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
const removedItems = filterRemovedItems(inputItems, dbItems);
|
const addedItems = filterAddedItems(inputItems, dbItems);
|
||||||
|
|
||||||
const itemIds = removedItems.map((item) => item.id);
|
if (addedItems.length > 0) {
|
||||||
if (itemIds.length > 0) {
|
await transaction.insert(schema.items).values(
|
||||||
await transaction.delete(items).where(inArray(items.id, itemIds));
|
addedItems.map((item) => ({
|
||||||
}
|
id: item.id,
|
||||||
|
kind: item.kind,
|
||||||
|
height: item.height,
|
||||||
|
width: item.width,
|
||||||
|
xOffset: item.xOffset,
|
||||||
|
yOffset: item.yOffset,
|
||||||
|
options: superjson.stringify(item.options),
|
||||||
|
advancedOptions: superjson.stringify(item.advancedOptions),
|
||||||
|
sectionId: item.sectionId,
|
||||||
|
})),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const removedSections = filterRemovedItems(input.sections, dbBoard.sections);
|
const inputIntegrationRelations = inputItems.flatMap(({ integrationIds, id: itemId }) =>
|
||||||
const sectionIds = removedSections.map((section) => section.id);
|
integrationIds.map((integrationId) => ({
|
||||||
|
integrationId,
|
||||||
|
itemId,
|
||||||
|
})),
|
||||||
|
);
|
||||||
|
const dbIntegrationRelations = dbItems.flatMap(({ integrationIds, id: itemId }) =>
|
||||||
|
integrationIds.map((integrationId) => ({
|
||||||
|
integrationId,
|
||||||
|
itemId,
|
||||||
|
})),
|
||||||
|
);
|
||||||
|
const addedIntegrationRelations = inputIntegrationRelations.filter(
|
||||||
|
(inputRelation) =>
|
||||||
|
!dbIntegrationRelations.some(
|
||||||
|
(dbRelation) =>
|
||||||
|
dbRelation.itemId === inputRelation.itemId &&
|
||||||
|
dbRelation.integrationId === inputRelation.integrationId,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
if (sectionIds.length > 0) {
|
if (addedIntegrationRelations.length > 0) {
|
||||||
await transaction.delete(sections).where(inArray(sections.id, sectionIds));
|
await transaction.insert(schema.integrationItems).values(
|
||||||
}
|
addedIntegrationRelations.map((relation) => ({
|
||||||
|
itemId: relation.itemId,
|
||||||
|
integrationId: relation.integrationId,
|
||||||
|
})),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const updatedItems = filterUpdatedItems(inputItems, dbItems);
|
||||||
|
|
||||||
|
for (const item of updatedItems) {
|
||||||
|
await transaction
|
||||||
|
.update(schema.items)
|
||||||
|
.set({
|
||||||
|
kind: item.kind,
|
||||||
|
height: item.height,
|
||||||
|
width: item.width,
|
||||||
|
xOffset: item.xOffset,
|
||||||
|
yOffset: item.yOffset,
|
||||||
|
options: superjson.stringify(item.options),
|
||||||
|
advancedOptions: superjson.stringify(item.advancedOptions),
|
||||||
|
sectionId: item.sectionId,
|
||||||
|
})
|
||||||
|
.where(eq(items.id, item.id));
|
||||||
|
}
|
||||||
|
|
||||||
|
const updatedSections = filterUpdatedItems(input.sections, dbBoard.sections);
|
||||||
|
|
||||||
|
for (const section of updatedSections) {
|
||||||
|
const prev = dbBoard.sections.find((dbSection) => dbSection.id === section.id);
|
||||||
|
await transaction
|
||||||
|
.update(schema.sections)
|
||||||
|
.set({
|
||||||
|
yOffset: section.yOffset,
|
||||||
|
xOffset: section.xOffset,
|
||||||
|
height: prev?.kind === "dynamic" && "height" in section ? section.height : null,
|
||||||
|
width: prev?.kind === "dynamic" && "width" in section ? section.width : null,
|
||||||
|
parentSectionId:
|
||||||
|
prev?.kind === "dynamic" && "parentSectionId" in section ? section.parentSectionId : null,
|
||||||
|
name: prev?.kind === "category" && "name" in section ? section.name : null,
|
||||||
|
})
|
||||||
|
.where(eq(sections.id, section.id));
|
||||||
|
}
|
||||||
|
|
||||||
|
const removedIntegrationRelations = dbIntegrationRelations.filter(
|
||||||
|
(dbRelation) =>
|
||||||
|
!inputIntegrationRelations.some(
|
||||||
|
(inputRelation) =>
|
||||||
|
dbRelation.itemId === inputRelation.itemId &&
|
||||||
|
dbRelation.integrationId === inputRelation.integrationId,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
for (const relation of removedIntegrationRelations) {
|
||||||
|
await transaction
|
||||||
|
.delete(schema.integrationItems)
|
||||||
|
.where(
|
||||||
|
and(
|
||||||
|
eq(integrationItems.itemId, relation.itemId),
|
||||||
|
eq(integrationItems.integrationId, relation.integrationId),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const removedItems = filterRemovedItems(inputItems, dbItems);
|
||||||
|
|
||||||
|
const itemIds = removedItems.map((item) => item.id);
|
||||||
|
if (itemIds.length > 0) {
|
||||||
|
await transaction.delete(schema.items).where(inArray(items.id, itemIds));
|
||||||
|
}
|
||||||
|
|
||||||
|
const removedSections = filterRemovedItems(input.sections, dbBoard.sections);
|
||||||
|
const sectionIds = removedSections.map((section) => section.id);
|
||||||
|
|
||||||
|
if (sectionIds.length > 0) {
|
||||||
|
await transaction.delete(schema.sections).where(inArray(sections.id, sectionIds));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
handleSync(db) {
|
||||||
|
db.transaction((transaction) => {
|
||||||
|
const addedSections = filterAddedItems(input.sections, dbBoard.sections);
|
||||||
|
|
||||||
|
if (addedSections.length > 0) {
|
||||||
|
transaction
|
||||||
|
.insert(sections)
|
||||||
|
.values(
|
||||||
|
addedSections.map((section) => ({
|
||||||
|
id: section.id,
|
||||||
|
kind: section.kind,
|
||||||
|
yOffset: section.yOffset,
|
||||||
|
xOffset: section.kind === "dynamic" ? section.xOffset : 0,
|
||||||
|
height: "height" in section ? section.height : null,
|
||||||
|
width: "width" in section ? section.width : null,
|
||||||
|
parentSectionId: "parentSectionId" in section ? section.parentSectionId : null,
|
||||||
|
name: "name" in section ? section.name : null,
|
||||||
|
boardId: dbBoard.id,
|
||||||
|
})),
|
||||||
|
)
|
||||||
|
.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
const inputItems = input.sections.flatMap((section) =>
|
||||||
|
section.items.map((item) => ({ ...item, sectionId: section.id })),
|
||||||
|
);
|
||||||
|
const dbItems = dbBoard.sections.flatMap((section) =>
|
||||||
|
section.items.map((item) => ({ ...item, sectionId: section.id })),
|
||||||
|
);
|
||||||
|
|
||||||
|
const addedItems = filterAddedItems(inputItems, dbItems);
|
||||||
|
|
||||||
|
if (addedItems.length > 0) {
|
||||||
|
transaction
|
||||||
|
.insert(items)
|
||||||
|
.values(
|
||||||
|
addedItems.map((item) => ({
|
||||||
|
id: item.id,
|
||||||
|
kind: item.kind,
|
||||||
|
height: item.height,
|
||||||
|
width: item.width,
|
||||||
|
xOffset: item.xOffset,
|
||||||
|
yOffset: item.yOffset,
|
||||||
|
options: superjson.stringify(item.options),
|
||||||
|
advancedOptions: superjson.stringify(item.advancedOptions),
|
||||||
|
sectionId: item.sectionId,
|
||||||
|
})),
|
||||||
|
)
|
||||||
|
.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
const inputIntegrationRelations = inputItems.flatMap(({ integrationIds, id: itemId }) =>
|
||||||
|
integrationIds.map((integrationId) => ({
|
||||||
|
integrationId,
|
||||||
|
itemId,
|
||||||
|
})),
|
||||||
|
);
|
||||||
|
const dbIntegrationRelations = dbItems.flatMap(({ integrationIds, id: itemId }) =>
|
||||||
|
integrationIds.map((integrationId) => ({
|
||||||
|
integrationId,
|
||||||
|
itemId,
|
||||||
|
})),
|
||||||
|
);
|
||||||
|
const addedIntegrationRelations = inputIntegrationRelations.filter(
|
||||||
|
(inputRelation) =>
|
||||||
|
!dbIntegrationRelations.some(
|
||||||
|
(dbRelation) =>
|
||||||
|
dbRelation.itemId === inputRelation.itemId &&
|
||||||
|
dbRelation.integrationId === inputRelation.integrationId,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (addedIntegrationRelations.length > 0) {
|
||||||
|
transaction
|
||||||
|
.insert(integrationItems)
|
||||||
|
.values(
|
||||||
|
addedIntegrationRelations.map((relation) => ({
|
||||||
|
itemId: relation.itemId,
|
||||||
|
integrationId: relation.integrationId,
|
||||||
|
})),
|
||||||
|
)
|
||||||
|
.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
const updatedItems = filterUpdatedItems(inputItems, dbItems);
|
||||||
|
|
||||||
|
for (const item of updatedItems) {
|
||||||
|
transaction
|
||||||
|
.update(items)
|
||||||
|
.set({
|
||||||
|
kind: item.kind,
|
||||||
|
height: item.height,
|
||||||
|
width: item.width,
|
||||||
|
xOffset: item.xOffset,
|
||||||
|
yOffset: item.yOffset,
|
||||||
|
options: superjson.stringify(item.options),
|
||||||
|
advancedOptions: superjson.stringify(item.advancedOptions),
|
||||||
|
sectionId: item.sectionId,
|
||||||
|
})
|
||||||
|
.where(eq(items.id, item.id))
|
||||||
|
.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
const updatedSections = filterUpdatedItems(input.sections, dbBoard.sections);
|
||||||
|
|
||||||
|
for (const section of updatedSections) {
|
||||||
|
const prev = dbBoard.sections.find((dbSection) => dbSection.id === section.id);
|
||||||
|
transaction
|
||||||
|
.update(sections)
|
||||||
|
.set({
|
||||||
|
yOffset: section.yOffset,
|
||||||
|
xOffset: section.xOffset,
|
||||||
|
height: prev?.kind === "dynamic" && "height" in section ? section.height : null,
|
||||||
|
width: prev?.kind === "dynamic" && "width" in section ? section.width : null,
|
||||||
|
parentSectionId:
|
||||||
|
prev?.kind === "dynamic" && "parentSectionId" in section ? section.parentSectionId : null,
|
||||||
|
name: prev?.kind === "category" && "name" in section ? section.name : null,
|
||||||
|
})
|
||||||
|
.where(eq(sections.id, section.id))
|
||||||
|
.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
const removedIntegrationRelations = dbIntegrationRelations.filter(
|
||||||
|
(dbRelation) =>
|
||||||
|
!inputIntegrationRelations.some(
|
||||||
|
(inputRelation) =>
|
||||||
|
dbRelation.itemId === inputRelation.itemId &&
|
||||||
|
dbRelation.integrationId === inputRelation.integrationId,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
for (const relation of removedIntegrationRelations) {
|
||||||
|
transaction
|
||||||
|
.delete(integrationItems)
|
||||||
|
.where(
|
||||||
|
and(
|
||||||
|
eq(integrationItems.itemId, relation.itemId),
|
||||||
|
eq(integrationItems.integrationId, relation.integrationId),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
const removedItems = filterRemovedItems(inputItems, dbItems);
|
||||||
|
|
||||||
|
const itemIds = removedItems.map((item) => item.id);
|
||||||
|
if (itemIds.length > 0) {
|
||||||
|
transaction.delete(items).where(inArray(items.id, itemIds)).run();
|
||||||
|
}
|
||||||
|
|
||||||
|
const removedSections = filterRemovedItems(input.sections, dbBoard.sections);
|
||||||
|
const sectionIds = removedSections.map((section) => section.id);
|
||||||
|
|
||||||
|
if (sectionIds.length > 0) {
|
||||||
|
transaction.delete(sections).where(inArray(sections.id, sectionIds)).run();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
|
|
||||||
@@ -655,18 +874,42 @@ export const boardRouter = createTRPCRouter({
|
|||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
await throwIfActionForbiddenAsync(ctx, eq(boards.id, input.entityId), "full");
|
await throwIfActionForbiddenAsync(ctx, eq(boards.id, input.entityId), "full");
|
||||||
|
|
||||||
await ctx.db.transaction(async (transaction) => {
|
await handleTransactionsAsync(ctx.db, {
|
||||||
await transaction.delete(boardUserPermissions).where(eq(boardUserPermissions.boardId, input.entityId));
|
async handleAsync(db, schema) {
|
||||||
if (input.permissions.length === 0) {
|
await db.transaction(async (transaction) => {
|
||||||
return;
|
await transaction
|
||||||
}
|
.delete(schema.boardUserPermissions)
|
||||||
await transaction.insert(boardUserPermissions).values(
|
.where(eq(boardUserPermissions.boardId, input.entityId));
|
||||||
input.permissions.map((permission) => ({
|
if (input.permissions.length === 0) {
|
||||||
userId: permission.principalId,
|
return;
|
||||||
permission: permission.permission,
|
}
|
||||||
boardId: input.entityId,
|
await transaction.insert(schema.boardUserPermissions).values(
|
||||||
})),
|
input.permissions.map((permission) => ({
|
||||||
);
|
userId: permission.principalId,
|
||||||
|
permission: permission.permission,
|
||||||
|
boardId: input.entityId,
|
||||||
|
})),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
handleSync(db) {
|
||||||
|
db.transaction((transaction) => {
|
||||||
|
transaction.delete(boardUserPermissions).where(eq(boardUserPermissions.boardId, input.entityId)).run();
|
||||||
|
if (input.permissions.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
transaction
|
||||||
|
.insert(boardUserPermissions)
|
||||||
|
.values(
|
||||||
|
input.permissions.map((permission) => ({
|
||||||
|
userId: permission.principalId,
|
||||||
|
permission: permission.permission,
|
||||||
|
boardId: input.entityId,
|
||||||
|
})),
|
||||||
|
)
|
||||||
|
.run();
|
||||||
|
});
|
||||||
|
},
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
saveGroupBoardPermissions: protectedProcedure
|
saveGroupBoardPermissions: protectedProcedure
|
||||||
@@ -674,18 +917,42 @@ export const boardRouter = createTRPCRouter({
|
|||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
await throwIfActionForbiddenAsync(ctx, eq(boards.id, input.entityId), "full");
|
await throwIfActionForbiddenAsync(ctx, eq(boards.id, input.entityId), "full");
|
||||||
|
|
||||||
await ctx.db.transaction(async (transaction) => {
|
await handleTransactionsAsync(ctx.db, {
|
||||||
await transaction.delete(boardGroupPermissions).where(eq(boardGroupPermissions.boardId, input.entityId));
|
async handleAsync(db, schema) {
|
||||||
if (input.permissions.length === 0) {
|
await db.transaction(async (transaction) => {
|
||||||
return;
|
await transaction
|
||||||
}
|
.delete(schema.boardGroupPermissions)
|
||||||
await transaction.insert(boardGroupPermissions).values(
|
.where(eq(boardGroupPermissions.boardId, input.entityId));
|
||||||
input.permissions.map((permission) => ({
|
if (input.permissions.length === 0) {
|
||||||
groupId: permission.principalId,
|
return;
|
||||||
permission: permission.permission,
|
}
|
||||||
boardId: input.entityId,
|
await transaction.insert(schema.boardGroupPermissions).values(
|
||||||
})),
|
input.permissions.map((permission) => ({
|
||||||
);
|
groupId: permission.principalId,
|
||||||
|
permission: permission.permission,
|
||||||
|
boardId: input.entityId,
|
||||||
|
})),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
handleSync(db) {
|
||||||
|
db.transaction((transaction) => {
|
||||||
|
transaction.delete(boardGroupPermissions).where(eq(boardGroupPermissions.boardId, input.entityId)).run();
|
||||||
|
if (input.permissions.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
transaction
|
||||||
|
.insert(boardGroupPermissions)
|
||||||
|
.values(
|
||||||
|
input.permissions.map((permission) => ({
|
||||||
|
groupId: permission.principalId,
|
||||||
|
permission: permission.permission,
|
||||||
|
boardId: input.entityId,
|
||||||
|
})),
|
||||||
|
)
|
||||||
|
.run();
|
||||||
|
});
|
||||||
|
},
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
importOldmarrConfig: permissionRequiredProcedure
|
importOldmarrConfig: permissionRequiredProcedure
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
import { z } from "zod";
|
||||||
|
import { zfd } from "zod-form-data";
|
||||||
|
|
||||||
|
import { addCustomRootCertificateAsync, removeCustomRootCertificateAsync } from "@homarr/certificates/server";
|
||||||
|
import { superRefineCertificateFile, validation } from "@homarr/validation";
|
||||||
|
|
||||||
|
import { createTRPCRouter, permissionRequiredProcedure } from "../../trpc";
|
||||||
|
|
||||||
|
export const certificateRouter = createTRPCRouter({
|
||||||
|
addCertificate: permissionRequiredProcedure
|
||||||
|
.requiresPermission("admin")
|
||||||
|
.input(
|
||||||
|
zfd.formData({
|
||||||
|
file: zfd.file().superRefine(superRefineCertificateFile),
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.mutation(async ({ input }) => {
|
||||||
|
const content = await input.file.text();
|
||||||
|
await addCustomRootCertificateAsync(input.file.name, content);
|
||||||
|
}),
|
||||||
|
removeCertificate: permissionRequiredProcedure
|
||||||
|
.requiresPermission("admin")
|
||||||
|
.input(z.object({ fileName: validation.certificates.validFileNameSchema }))
|
||||||
|
.mutation(async ({ input }) => {
|
||||||
|
await removeCustomRootCertificateAsync(input.fileName);
|
||||||
|
}),
|
||||||
|
});
|
||||||
@@ -1,26 +1,24 @@
|
|||||||
import { TRPCError } from "@trpc/server";
|
import { TRPCError } from "@trpc/server";
|
||||||
import type Docker from "dockerode";
|
|
||||||
import type { Container } from "dockerode";
|
|
||||||
|
|
||||||
import { db, like, or } from "@homarr/db";
|
import { db, like, or } from "@homarr/db";
|
||||||
import { icons } from "@homarr/db/schema";
|
import { icons } from "@homarr/db/schema";
|
||||||
import type { DockerContainerState } from "@homarr/definitions";
|
import { DockerSingleton } from "@homarr/docker";
|
||||||
|
import type { Container, ContainerInfo, ContainerState, Docker, Port } from "@homarr/docker";
|
||||||
import { logger } from "@homarr/log";
|
import { logger } from "@homarr/log";
|
||||||
import { createCacheChannel } from "@homarr/redis";
|
import { createCacheChannel } from "@homarr/redis";
|
||||||
import { z } from "@homarr/validation";
|
import { z } from "@homarr/validation";
|
||||||
|
|
||||||
import { createTRPCRouter, permissionRequiredProcedure } from "../../trpc";
|
import { createTRPCRouter, permissionRequiredProcedure } from "../../trpc";
|
||||||
import { DockerSingleton } from "./docker-singleton";
|
|
||||||
|
|
||||||
const dockerCache = createCacheChannel<{
|
const dockerCache = createCacheChannel<{
|
||||||
containers: (Docker.ContainerInfo & { instance: string; iconUrl: string | null })[];
|
containers: (ContainerInfo & { instance: string; iconUrl: string | null })[];
|
||||||
}>("docker-containers", 5 * 60 * 1000);
|
}>("docker-containers", 5 * 60 * 1000);
|
||||||
|
|
||||||
export const dockerRouter = createTRPCRouter({
|
export const dockerRouter = createTRPCRouter({
|
||||||
getContainers: permissionRequiredProcedure.requiresPermission("admin").query(async () => {
|
getContainers: permissionRequiredProcedure.requiresPermission("admin").query(async () => {
|
||||||
const result = await dockerCache
|
const result = await dockerCache
|
||||||
.consumeAsync(async () => {
|
.consumeAsync(async () => {
|
||||||
const dockerInstances = DockerSingleton.getInstance();
|
const dockerInstances = DockerSingleton.getInstances();
|
||||||
const containers = await Promise.all(
|
const containers = await Promise.all(
|
||||||
// Return all the containers of all the instances into only one item
|
// Return all the containers of all the instances into only one item
|
||||||
dockerInstances.map(({ instance, host: key }) =>
|
dockerInstances.map(({ instance, host: key }) =>
|
||||||
@@ -33,8 +31,7 @@ export const dockerRouter = createTRPCRouter({
|
|||||||
),
|
),
|
||||||
).then((containers) => containers.flat());
|
).then((containers) => containers.flat());
|
||||||
|
|
||||||
const extractImage = (container: Docker.ContainerInfo) =>
|
const extractImage = (container: ContainerInfo) => container.Image.split("/").at(-1)?.split(":").at(0) ?? "";
|
||||||
container.Image.split("/").at(-1)?.split(":").at(0) ?? "";
|
|
||||||
const likeQueries = containers.map((container) => like(icons.name, `%${extractImage(container)}%`));
|
const likeQueries = containers.map((container) => like(icons.name, `%${extractImage(container)}%`));
|
||||||
const dbIcons =
|
const dbIcons =
|
||||||
likeQueries.length >= 1
|
likeQueries.length >= 1
|
||||||
@@ -151,7 +148,7 @@ const getContainerOrDefaultAsync = async (instance: Docker, id: string) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const getContainerOrThrowAsync = async (id: string) => {
|
const getContainerOrThrowAsync = async (id: string) => {
|
||||||
const dockerInstances = DockerSingleton.getInstance();
|
const dockerInstances = DockerSingleton.getInstances();
|
||||||
const containers = await Promise.all(dockerInstances.map(({ instance }) => getContainerOrDefaultAsync(instance, id)));
|
const containers = await Promise.all(dockerInstances.map(({ instance }) => getContainerOrDefaultAsync(instance, id)));
|
||||||
const foundContainer = containers.find((container) => container) ?? null;
|
const foundContainer = containers.find((container) => container) ?? null;
|
||||||
|
|
||||||
@@ -168,21 +165,21 @@ const getContainerOrThrowAsync = async (id: string) => {
|
|||||||
interface DockerContainer {
|
interface DockerContainer {
|
||||||
name: string;
|
name: string;
|
||||||
id: string;
|
id: string;
|
||||||
state: DockerContainerState;
|
state: ContainerState;
|
||||||
image: string;
|
image: string;
|
||||||
ports: Docker.Port[];
|
ports: Port[];
|
||||||
iconUrl: string | null;
|
iconUrl: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function sanitizeContainers(
|
function sanitizeContainers(
|
||||||
containers: (Docker.ContainerInfo & { instance: string; iconUrl: string | null })[],
|
containers: (ContainerInfo & { instance: string; iconUrl: string | null })[],
|
||||||
): DockerContainer[] {
|
): DockerContainer[] {
|
||||||
return containers.map((container) => {
|
return containers.map((container) => {
|
||||||
return {
|
return {
|
||||||
name: container.Names[0]?.split("/")[1] ?? "Unknown",
|
name: container.Names[0]?.split("/")[1] ?? "Unknown",
|
||||||
id: container.Id,
|
id: container.Id,
|
||||||
instance: container.instance,
|
instance: container.instance,
|
||||||
state: container.State as DockerContainerState,
|
state: container.State as ContainerState,
|
||||||
image: container.Image,
|
image: container.Image,
|
||||||
ports: container.Ports,
|
ports: container.Ports,
|
||||||
iconUrl: container.iconUrl,
|
iconUrl: container.iconUrl,
|
||||||
|
|||||||
@@ -1,51 +0,0 @@
|
|||||||
import Docker from "dockerode";
|
|
||||||
|
|
||||||
interface DockerInstance {
|
|
||||||
host: string;
|
|
||||||
instance: Docker;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class DockerSingleton {
|
|
||||||
private static instances: DockerInstance[];
|
|
||||||
|
|
||||||
private createInstances() {
|
|
||||||
const instances: DockerInstance[] = [];
|
|
||||||
const hostVariable = process.env.DOCKER_HOST;
|
|
||||||
const portVariable = process.env.DOCKER_PORT;
|
|
||||||
if (hostVariable === undefined || portVariable === undefined) {
|
|
||||||
instances.push({ host: "socket", instance: new Docker() });
|
|
||||||
return instances;
|
|
||||||
}
|
|
||||||
const hosts = hostVariable.split(",");
|
|
||||||
const ports = portVariable.split(",");
|
|
||||||
|
|
||||||
if (hosts.length !== ports.length) {
|
|
||||||
throw new Error("The number of hosts and ports must match");
|
|
||||||
}
|
|
||||||
|
|
||||||
hosts.forEach((host, i) => {
|
|
||||||
instances.push({
|
|
||||||
host: `${host}:${ports[i]}`,
|
|
||||||
instance: new Docker({
|
|
||||||
host,
|
|
||||||
port: parseInt(ports[i] ?? "", 10),
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
return instances;
|
|
||||||
});
|
|
||||||
return instances;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static findInstance(key: string): DockerInstance | undefined {
|
|
||||||
return this.instances.find((instance) => instance.host === key);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static getInstance(): DockerInstance[] {
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
||||||
if (!DockerSingleton.instances) {
|
|
||||||
DockerSingleton.instances = new DockerSingleton().createInstances();
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.instances;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -3,7 +3,7 @@ import { TRPCError } from "@trpc/server";
|
|||||||
import { objectEntries } from "@homarr/common";
|
import { objectEntries } from "@homarr/common";
|
||||||
import { decryptSecret, encryptSecret } from "@homarr/common/server";
|
import { decryptSecret, encryptSecret } from "@homarr/common/server";
|
||||||
import type { Database } from "@homarr/db";
|
import type { Database } from "@homarr/db";
|
||||||
import { and, asc, createId, eq, inArray, like } from "@homarr/db";
|
import { and, asc, createId, eq, handleTransactionsAsync, inArray, like } from "@homarr/db";
|
||||||
import {
|
import {
|
||||||
groupMembers,
|
groupMembers,
|
||||||
groupPermissions,
|
groupPermissions,
|
||||||
@@ -130,6 +130,16 @@ export const integrationRouter = createTRPCRouter({
|
|||||||
limit: input.limit,
|
limit: input.limit,
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
|
// This is used to get the integrations by their ids it's public because it's needed to get integrations data in the boards
|
||||||
|
byIds: publicProcedure.input(z.array(z.string())).query(async ({ ctx, input }) => {
|
||||||
|
return await ctx.db.query.integrations.findMany({
|
||||||
|
where: inArray(integrations.id, input),
|
||||||
|
columns: {
|
||||||
|
id: true,
|
||||||
|
kind: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}),
|
||||||
byId: protectedProcedure.input(validation.integration.byId).query(async ({ ctx, input }) => {
|
byId: protectedProcedure.input(validation.integration.byId).query(async ({ ctx, input }) => {
|
||||||
await throwIfActionForbiddenAsync(ctx, eq(integrations.id, input.id), "full");
|
await throwIfActionForbiddenAsync(ctx, eq(integrations.id, input.id), "full");
|
||||||
const integration = await ctx.db.query.integrations.findFirst({
|
const integration = await ctx.db.query.integrations.findFirst({
|
||||||
@@ -360,20 +370,45 @@ export const integrationRouter = createTRPCRouter({
|
|||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
await throwIfActionForbiddenAsync(ctx, eq(integrations.id, input.entityId), "full");
|
await throwIfActionForbiddenAsync(ctx, eq(integrations.id, input.entityId), "full");
|
||||||
|
|
||||||
await ctx.db.transaction(async (transaction) => {
|
await handleTransactionsAsync(ctx.db, {
|
||||||
await transaction
|
async handleAsync(db, schema) {
|
||||||
.delete(integrationUserPermissions)
|
await ctx.db.transaction(async (transaction) => {
|
||||||
.where(eq(integrationUserPermissions.integrationId, input.entityId));
|
await transaction
|
||||||
if (input.permissions.length === 0) {
|
.delete(schema.integrationUserPermissions)
|
||||||
return;
|
.where(eq(schema.integrationUserPermissions.integrationId, input.entityId));
|
||||||
}
|
if (input.permissions.length === 0) {
|
||||||
await transaction.insert(integrationUserPermissions).values(
|
return;
|
||||||
input.permissions.map((permission) => ({
|
}
|
||||||
userId: permission.principalId,
|
await transaction.insert(schema.integrationUserPermissions).values(
|
||||||
permission: permission.permission,
|
input.permissions.map((permission) => ({
|
||||||
integrationId: input.entityId,
|
userId: permission.principalId,
|
||||||
})),
|
permission: permission.permission,
|
||||||
);
|
integrationId: input.entityId,
|
||||||
|
})),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
handleSync(db) {
|
||||||
|
db.transaction((transaction) => {
|
||||||
|
transaction
|
||||||
|
.delete(integrationUserPermissions)
|
||||||
|
.where(eq(integrationUserPermissions.integrationId, input.entityId))
|
||||||
|
.run();
|
||||||
|
if (input.permissions.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
transaction
|
||||||
|
.insert(integrationUserPermissions)
|
||||||
|
.values(
|
||||||
|
input.permissions.map((permission) => ({
|
||||||
|
userId: permission.principalId,
|
||||||
|
permission: permission.permission,
|
||||||
|
integrationId: input.entityId,
|
||||||
|
})),
|
||||||
|
)
|
||||||
|
.run();
|
||||||
|
});
|
||||||
|
},
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
saveGroupIntegrationPermissions: protectedProcedure
|
saveGroupIntegrationPermissions: protectedProcedure
|
||||||
@@ -381,20 +416,45 @@ export const integrationRouter = createTRPCRouter({
|
|||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
await throwIfActionForbiddenAsync(ctx, eq(integrations.id, input.entityId), "full");
|
await throwIfActionForbiddenAsync(ctx, eq(integrations.id, input.entityId), "full");
|
||||||
|
|
||||||
await ctx.db.transaction(async (transaction) => {
|
await handleTransactionsAsync(ctx.db, {
|
||||||
await transaction
|
async handleAsync(db, schema) {
|
||||||
.delete(integrationGroupPermissions)
|
await db.transaction(async (transaction) => {
|
||||||
.where(eq(integrationGroupPermissions.integrationId, input.entityId));
|
await transaction
|
||||||
if (input.permissions.length === 0) {
|
.delete(schema.integrationGroupPermissions)
|
||||||
return;
|
.where(eq(schema.integrationGroupPermissions.integrationId, input.entityId));
|
||||||
}
|
if (input.permissions.length === 0) {
|
||||||
await transaction.insert(integrationGroupPermissions).values(
|
return;
|
||||||
input.permissions.map((permission) => ({
|
}
|
||||||
groupId: permission.principalId,
|
await transaction.insert(schema.integrationGroupPermissions).values(
|
||||||
permission: permission.permission,
|
input.permissions.map((permission) => ({
|
||||||
integrationId: input.entityId,
|
groupId: permission.principalId,
|
||||||
})),
|
permission: permission.permission,
|
||||||
);
|
integrationId: input.entityId,
|
||||||
|
})),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
handleSync(db) {
|
||||||
|
db.transaction((transaction) => {
|
||||||
|
transaction
|
||||||
|
.delete(integrationGroupPermissions)
|
||||||
|
.where(eq(integrationGroupPermissions.integrationId, input.entityId))
|
||||||
|
.run();
|
||||||
|
if (input.permissions.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
transaction
|
||||||
|
.insert(integrationGroupPermissions)
|
||||||
|
.values(
|
||||||
|
input.permissions.map((permission) => ({
|
||||||
|
groupId: permission.principalId,
|
||||||
|
permission: permission.permission,
|
||||||
|
integrationId: input.entityId,
|
||||||
|
})),
|
||||||
|
)
|
||||||
|
.run();
|
||||||
|
});
|
||||||
|
},
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
searchInIntegration: protectedProcedure
|
searchInIntegration: protectedProcedure
|
||||||
|
|||||||
@@ -404,7 +404,13 @@ export const userRouter = createTRPCRouter({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
await throwIfActionForbiddenAsync(ctx, eq(boards.id, input.userId), "view");
|
// Only allow user to select boards they have access to
|
||||||
|
if (input.homeBoardId) {
|
||||||
|
await throwIfActionForbiddenAsync(ctx, eq(boards.id, input.homeBoardId), "view");
|
||||||
|
}
|
||||||
|
if (input.mobileHomeBoardId) {
|
||||||
|
await throwIfActionForbiddenAsync(ctx, eq(boards.id, input.mobileHomeBoardId), "view");
|
||||||
|
}
|
||||||
|
|
||||||
await ctx.db
|
await ctx.db
|
||||||
.update(users)
|
.update(users)
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
import { observable } from "@trpc/server/observable";
|
import { observable } from "@trpc/server/observable";
|
||||||
|
|
||||||
import { getIntegrationKindsByCategory } from "@homarr/definitions";
|
|
||||||
import type { HealthMonitoring } from "@homarr/integrations";
|
import type { HealthMonitoring } from "@homarr/integrations";
|
||||||
import { systemInfoRequestHandler } from "@homarr/request-handler/health-monitoring";
|
import type { ProxmoxClusterInfo } from "@homarr/integrations/types";
|
||||||
|
import { clusterInfoRequestHandler, systemInfoRequestHandler } from "@homarr/request-handler/health-monitoring";
|
||||||
|
|
||||||
import { createManyIntegrationMiddleware } from "../../middlewares/integration";
|
import { createManyIntegrationMiddleware, createOneIntegrationMiddleware } from "../../middlewares/integration";
|
||||||
import { createTRPCRouter, publicProcedure } from "../../trpc";
|
import { createTRPCRouter, publicProcedure } from "../../trpc";
|
||||||
|
|
||||||
export const healthMonitoringRouter = createTRPCRouter({
|
export const healthMonitoringRouter = createTRPCRouter({
|
||||||
getHealthStatus: publicProcedure
|
getSystemHealthStatus: publicProcedure
|
||||||
.unstable_concat(createManyIntegrationMiddleware("query", ...getIntegrationKindsByCategory("healthMonitoring")))
|
.unstable_concat(createManyIntegrationMiddleware("query", "openmediavault", "dashDot"))
|
||||||
.query(async ({ ctx }) => {
|
.query(async ({ ctx }) => {
|
||||||
return await Promise.all(
|
return await Promise.all(
|
||||||
ctx.integrations.map(async (integration) => {
|
ctx.integrations.map(async (integration) => {
|
||||||
@@ -25,9 +25,8 @@ export const healthMonitoringRouter = createTRPCRouter({
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
|
subscribeSystemHealthStatus: publicProcedure
|
||||||
subscribeHealthStatus: publicProcedure
|
.unstable_concat(createManyIntegrationMiddleware("query", "openmediavault", "dashDot"))
|
||||||
.unstable_concat(createManyIntegrationMiddleware("query", ...getIntegrationKindsByCategory("healthMonitoring")))
|
|
||||||
.subscription(({ ctx }) => {
|
.subscription(({ ctx }) => {
|
||||||
return observable<{ integrationId: string; healthInfo: HealthMonitoring; timestamp: Date }>((emit) => {
|
return observable<{ integrationId: string; healthInfo: HealthMonitoring; timestamp: Date }>((emit) => {
|
||||||
const unsubscribes: (() => void)[] = [];
|
const unsubscribes: (() => void)[] = [];
|
||||||
@@ -49,4 +48,26 @@ export const healthMonitoringRouter = createTRPCRouter({
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
|
getClusterHealthStatus: publicProcedure
|
||||||
|
.unstable_concat(createOneIntegrationMiddleware("query", "proxmox"))
|
||||||
|
.query(async ({ ctx }) => {
|
||||||
|
const innerHandler = clusterInfoRequestHandler.handler(ctx.integration, {});
|
||||||
|
const { data } = await innerHandler.getCachedOrUpdatedDataAsync({ forceUpdate: false });
|
||||||
|
return data;
|
||||||
|
}),
|
||||||
|
subscribeClusterHealthStatus: publicProcedure
|
||||||
|
.unstable_concat(createOneIntegrationMiddleware("query", "proxmox"))
|
||||||
|
.subscription(({ ctx }) => {
|
||||||
|
return observable<ProxmoxClusterInfo>((emit) => {
|
||||||
|
const unsubscribes: (() => void)[] = [];
|
||||||
|
const innerHandler = clusterInfoRequestHandler.handler(ctx.integration, {});
|
||||||
|
const unsubscribe = innerHandler.subscribe((healthInfo) => {
|
||||||
|
emit.next(healthInfo);
|
||||||
|
});
|
||||||
|
unsubscribes.push(unsubscribe);
|
||||||
|
return () => {
|
||||||
|
unsubscribe();
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
@@ -1,12 +1,36 @@
|
|||||||
import type { RssFeed } from "@homarr/cron-jobs";
|
import { rssFeedsRequestHandler } from "@homarr/request-handler/rss-feeds";
|
||||||
import { createItemChannel } from "@homarr/redis";
|
import { z } from "@homarr/validation";
|
||||||
|
|
||||||
import { createOneItemMiddleware } from "../../middlewares/item";
|
|
||||||
import { createTRPCRouter, publicProcedure } from "../../trpc";
|
import { createTRPCRouter, publicProcedure } from "../../trpc";
|
||||||
|
|
||||||
export const rssFeedRouter = createTRPCRouter({
|
export const rssFeedRouter = createTRPCRouter({
|
||||||
getFeeds: publicProcedure.unstable_concat(createOneItemMiddleware("rssFeed")).query(async ({ input }) => {
|
getFeeds: publicProcedure
|
||||||
const channel = createItemChannel<RssFeed[]>(input.itemId);
|
.input(
|
||||||
return await channel.getAsync();
|
z.object({
|
||||||
}),
|
urls: z.array(z.string()),
|
||||||
|
maximumAmountPosts: z.number(),
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.query(async ({ input }) => {
|
||||||
|
const rssFeeds = await Promise.all(
|
||||||
|
input.urls.map(async (url) => {
|
||||||
|
const innerHandler = rssFeedsRequestHandler.handler({
|
||||||
|
url,
|
||||||
|
count: input.maximumAmountPosts,
|
||||||
|
});
|
||||||
|
return await innerHandler.getCachedOrUpdatedDataAsync({
|
||||||
|
forceUpdate: false,
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
return rssFeeds
|
||||||
|
.flatMap((rssFeed) => rssFeed.data.entries)
|
||||||
|
.slice(0, input.maximumAmountPosts)
|
||||||
|
.sort((entryA, entryB) => {
|
||||||
|
return entryA.published && entryB.published
|
||||||
|
? new Date(entryB.published).getTime() - new Date(entryA.published).getTime()
|
||||||
|
: 0;
|
||||||
|
});
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
@@ -2,9 +2,11 @@ import type { ReadonlyHeaders } from "next/dist/server/web/spec-extension/adapte
|
|||||||
import { cookies } from "next/headers";
|
import { cookies } from "next/headers";
|
||||||
import NextAuth from "next-auth";
|
import NextAuth from "next-auth";
|
||||||
import Credentials from "next-auth/providers/credentials";
|
import Credentials from "next-auth/providers/credentials";
|
||||||
|
import { formatError } from "pretty-print-error";
|
||||||
|
|
||||||
import { db } from "@homarr/db";
|
import { db } from "@homarr/db";
|
||||||
import type { SupportedAuthProvider } from "@homarr/definitions";
|
import type { SupportedAuthProvider } from "@homarr/definitions";
|
||||||
|
import { logger } from "@homarr/log";
|
||||||
|
|
||||||
import { createAdapter } from "./adapter";
|
import { createAdapter } from "./adapter";
|
||||||
import { createSessionCallback } from "./callbacks";
|
import { createSessionCallback } from "./callbacks";
|
||||||
@@ -26,15 +28,16 @@ export const createConfiguration = (
|
|||||||
const adapter = createAdapter(db, provider);
|
const adapter = createAdapter(db, provider);
|
||||||
return NextAuth({
|
return NextAuth({
|
||||||
logger: {
|
logger: {
|
||||||
error: (code, ...message) => {
|
error: (error) => {
|
||||||
// Remove the big error message for failed login attempts
|
// Remove the big error message for failed login attempts
|
||||||
// as it is not useful for the user.
|
// as it is not useful for the user.
|
||||||
if (code.name === "CredentialsSignin") {
|
if (error.name === "CredentialsSignin") {
|
||||||
console.warn("The login attempt of a user was not successful.");
|
logger.warn("The login attempt of a user was not successful.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.error(code, ...message);
|
logger.error(formatError(error));
|
||||||
|
logger.error(formatError(error.cause));
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
trustHost: true,
|
trustHost: true,
|
||||||
|
|||||||
@@ -86,4 +86,5 @@ export const env = createEnv({
|
|||||||
AUTH_OIDC_NAME_ATTRIBUTE_OVERWRITE: process.env.AUTH_OIDC_NAME_ATTRIBUTE_OVERWRITE,
|
AUTH_OIDC_NAME_ATTRIBUTE_OVERWRITE: process.env.AUTH_OIDC_NAME_ATTRIBUTE_OVERWRITE,
|
||||||
},
|
},
|
||||||
skipValidation,
|
skipValidation,
|
||||||
|
emptyStringAsUndefined: true,
|
||||||
});
|
});
|
||||||
@@ -34,8 +34,9 @@
|
|||||||
"bcrypt": "^5.1.1",
|
"bcrypt": "^5.1.1",
|
||||||
"cookies": "^0.9.1",
|
"cookies": "^0.9.1",
|
||||||
"ldapts": "7.3.1",
|
"ldapts": "7.3.1",
|
||||||
"next": "15.1.4",
|
"next": "15.1.6",
|
||||||
"next-auth": "5.0.0-beta.25",
|
"next-auth": "5.0.0-beta.25",
|
||||||
|
"pretty-print-error": "^1.1.2",
|
||||||
"react": "19.0.0",
|
"react": "19.0.0",
|
||||||
"react-dom": "19.0.0"
|
"react-dom": "19.0.0"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { CredentialsSignin } from "@auth/core/errors";
|
import { CredentialsSignin } from "@auth/core/errors";
|
||||||
|
|
||||||
|
import { extractErrorMessage } from "@homarr/common";
|
||||||
import type { Database, InferInsertModel } from "@homarr/db";
|
import type { Database, InferInsertModel } from "@homarr/db";
|
||||||
import { and, createId, eq } from "@homarr/db";
|
import { and, createId, eq } from "@homarr/db";
|
||||||
import { users } from "@homarr/db/schema";
|
import { users } from "@homarr/db/schema";
|
||||||
@@ -21,8 +22,8 @@ export const authorizeWithLdapCredentialsAsync = async (
|
|||||||
distinguishedName: env.AUTH_LDAP_BIND_DN,
|
distinguishedName: env.AUTH_LDAP_BIND_DN,
|
||||||
password: env.AUTH_LDAP_BIND_PASSWORD,
|
password: env.AUTH_LDAP_BIND_PASSWORD,
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch((error) => {
|
||||||
logger.error("Failed to connect to LDAP server");
|
logger.error(`Failed to connect to LDAP server ${extractErrorMessage(error)}`);
|
||||||
throw new CredentialsSignin();
|
throw new CredentialsSignin();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
import baseConfig from "@homarr/eslint-config/base";
|
||||||
|
|
||||||
|
/** @type {import('typescript-eslint').Config} */
|
||||||
|
export default [
|
||||||
|
{
|
||||||
|
ignores: [],
|
||||||
|
},
|
||||||
|
...baseConfig,
|
||||||
|
];
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
{
|
||||||
|
"name": "@homarr/certificates",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"private": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"type": "module",
|
||||||
|
"exports": {
|
||||||
|
"./server": "./src/server.ts"
|
||||||
|
},
|
||||||
|
"typesVersions": {
|
||||||
|
"*": {
|
||||||
|
"*": [
|
||||||
|
"src/*"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"clean": "rm -rf .turbo node_modules",
|
||||||
|
"format": "prettier --check . --ignore-path ../../.gitignore",
|
||||||
|
"lint": "eslint",
|
||||||
|
"typecheck": "tsc --noEmit"
|
||||||
|
},
|
||||||
|
"prettier": "@homarr/prettier-config",
|
||||||
|
"dependencies": {
|
||||||
|
"@homarr/common": "workspace:^0.1.0",
|
||||||
|
"undici": "7.3.0"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@homarr/eslint-config": "workspace:^0.2.0",
|
||||||
|
"@homarr/prettier-config": "workspace:^0.1.0",
|
||||||
|
"@homarr/tsconfig": "workspace:^0.1.0",
|
||||||
|
"eslint": "^9.18.0",
|
||||||
|
"typescript": "^5.7.3"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
import fsSync from "node:fs";
|
||||||
|
import fs from "node:fs/promises";
|
||||||
|
import { Agent } from "node:https";
|
||||||
|
import path from "node:path";
|
||||||
|
import { rootCertificates } from "node:tls";
|
||||||
|
import axios from "axios";
|
||||||
|
import { fetch } from "undici";
|
||||||
|
|
||||||
|
import { LoggingAgent } from "@homarr/common/server";
|
||||||
|
|
||||||
|
const getCertificateFolder = () => {
|
||||||
|
return process.env.NODE_ENV === "production"
|
||||||
|
? path.join("/appdata", "trusted-certificates")
|
||||||
|
: process.env.LOCAL_CERTIFICATE_PATH;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const loadCustomRootCertificatesAsync = async () => {
|
||||||
|
const folder = getCertificateFolder();
|
||||||
|
|
||||||
|
if (!folder) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!fsSync.existsSync(folder)) {
|
||||||
|
await fs.mkdir(folder, { recursive: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
const dirContent = await fs.readdir(folder);
|
||||||
|
return await Promise.all(
|
||||||
|
dirContent
|
||||||
|
.filter((file) => file.endsWith(".crt"))
|
||||||
|
.map(async (file) => ({
|
||||||
|
content: await fs.readFile(path.join(folder, file), "utf8"),
|
||||||
|
fileName: file,
|
||||||
|
})),
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const removeCustomRootCertificateAsync = async (fileName: string) => {
|
||||||
|
const folder = getCertificateFolder();
|
||||||
|
if (!folder) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await fs.rm(path.join(folder, fileName));
|
||||||
|
};
|
||||||
|
|
||||||
|
export const addCustomRootCertificateAsync = async (fileName: string, content: string) => {
|
||||||
|
const folder = getCertificateFolder();
|
||||||
|
if (!folder) {
|
||||||
|
throw new Error(
|
||||||
|
"When you want to use custom certificates locally you need to set LOCAL_CERTIFICATE_PATH to an absolute path",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fileName.includes("/")) {
|
||||||
|
throw new Error("Invalid file name");
|
||||||
|
}
|
||||||
|
|
||||||
|
await fs.writeFile(path.join(folder, fileName), content);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const createCertificateAgentAsync = async () => {
|
||||||
|
const customCertificates = await loadCustomRootCertificatesAsync();
|
||||||
|
return new LoggingAgent({
|
||||||
|
connect: {
|
||||||
|
ca: rootCertificates.concat(customCertificates.map((cert) => cert.content)),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const createAxiosCertificateInstanceAsync = async () => {
|
||||||
|
const customCertificates = await loadCustomRootCertificatesAsync();
|
||||||
|
return axios.create({
|
||||||
|
httpsAgent: new Agent({
|
||||||
|
ca: rootCertificates.concat(customCertificates.map((cert) => cert.content)),
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const fetchWithTrustedCertificatesAsync: typeof fetch = async (url, options) => {
|
||||||
|
const agent = await createCertificateAgentAsync();
|
||||||
|
return fetch(url, {
|
||||||
|
...options,
|
||||||
|
dispatcher: agent,
|
||||||
|
});
|
||||||
|
};
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"extends": "@homarr/tsconfig/base.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"tsBuildInfoFile": "node_modules/.cache/tsbuildinfo.json"
|
||||||
|
},
|
||||||
|
"include": ["*.ts", "src"],
|
||||||
|
"exclude": ["node_modules"]
|
||||||
|
}
|
||||||
@@ -26,4 +26,5 @@ export const env = createEnv({
|
|||||||
SECRET_ENCRYPTION_KEY: process.env.SECRET_ENCRYPTION_KEY,
|
SECRET_ENCRYPTION_KEY: process.env.SECRET_ENCRYPTION_KEY,
|
||||||
},
|
},
|
||||||
skipValidation: shouldSkipEnvValidation(),
|
skipValidation: shouldSkipEnvValidation(),
|
||||||
|
emptyStringAsUndefined: true,
|
||||||
});
|
});
|
||||||
@@ -29,9 +29,10 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@homarr/log": "workspace:^0.1.0",
|
"@homarr/log": "workspace:^0.1.0",
|
||||||
"dayjs": "^1.11.13",
|
"dayjs": "^1.11.13",
|
||||||
"next": "15.1.4",
|
"next": "15.1.6",
|
||||||
"react": "19.0.0",
|
"react": "19.0.0",
|
||||||
"react-dom": "19.0.0",
|
"react-dom": "19.0.0",
|
||||||
|
"undici": "7.3.0",
|
||||||
"zod": "^3.24.1"
|
"zod": "^3.24.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
import type { Dispatcher } from "undici";
|
||||||
|
import { Agent } from "undici";
|
||||||
|
|
||||||
|
import { logger } from "@homarr/log";
|
||||||
|
|
||||||
|
export class LoggingAgent extends Agent {
|
||||||
|
constructor(...props: ConstructorParameters<typeof Agent>) {
|
||||||
|
super(...props);
|
||||||
|
}
|
||||||
|
|
||||||
|
dispatch(options: Dispatcher.DispatchOptions, handler: Dispatcher.DispatchHandler): boolean {
|
||||||
|
const url = new URL(`${options.origin as string}${options.path}`);
|
||||||
|
|
||||||
|
// The below code should prevent sensitive data from being logged as
|
||||||
|
// some integrations use query parameters for auth
|
||||||
|
url.searchParams.forEach((value, key) => {
|
||||||
|
if (value === "") return; // Skip empty values
|
||||||
|
if (/^-?\d{1,12}$/.test(value)) return; // Skip small numbers
|
||||||
|
if (value === "true" || value === "false") return; // Skip boolean values
|
||||||
|
if (/^[a-zA-Z]{1,12}$/.test(value)) return; // Skip short strings
|
||||||
|
if (/^\d{4}-\d{2}-\d{2}$/.test(value)) return; // Skip dates
|
||||||
|
if (/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/.test(value)) return; // Skip date times
|
||||||
|
|
||||||
|
url.searchParams.set(key, "REDACTED");
|
||||||
|
});
|
||||||
|
|
||||||
|
logger.info(
|
||||||
|
`Dispatching request ${url.toString().replaceAll("=&", "&")} (${Object.keys(options.headers ?? {}).length} headers)`,
|
||||||
|
);
|
||||||
|
return super.dispatch(options, handler);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
export * from "./security";
|
export * from "./security";
|
||||||
export * from "./encryption";
|
export * from "./encryption";
|
||||||
export * from "./user-agent";
|
export * from "./user-agent";
|
||||||
|
export * from "./fetch-agent";
|
||||||
+1
-1
@@ -3,7 +3,7 @@ import { describe, expect, test, vi } from "vitest";
|
|||||||
|
|
||||||
import { logger } from "@homarr/log";
|
import { logger } from "@homarr/log";
|
||||||
|
|
||||||
import { LoggingAgent } from "~/undici-log-agent-override";
|
import { LoggingAgent } from "../fetch-agent";
|
||||||
|
|
||||||
vi.mock("undici", () => {
|
vi.mock("undici", () => {
|
||||||
return {
|
return {
|
||||||
@@ -22,7 +22,6 @@
|
|||||||
},
|
},
|
||||||
"prettier": "@homarr/prettier-config",
|
"prettier": "@homarr/prettier-config",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@extractus/feed-extractor": "^7.1.3",
|
|
||||||
"@homarr/analytics": "workspace:^0.1.0",
|
"@homarr/analytics": "workspace:^0.1.0",
|
||||||
"@homarr/auth": "workspace:^0.1.0",
|
"@homarr/auth": "workspace:^0.1.0",
|
||||||
"@homarr/common": "workspace:^0.1.0",
|
"@homarr/common": "workspace:^0.1.0",
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import { mediaServerJob } from "./jobs/integrations/media-server";
|
|||||||
import { mediaTranscodingJob } from "./jobs/integrations/media-transcoding";
|
import { mediaTranscodingJob } from "./jobs/integrations/media-transcoding";
|
||||||
import { minecraftServerStatusJob } from "./jobs/minecraft-server-status";
|
import { minecraftServerStatusJob } from "./jobs/minecraft-server-status";
|
||||||
import { pingJob } from "./jobs/ping";
|
import { pingJob } from "./jobs/ping";
|
||||||
import type { RssFeed } from "./jobs/rss-feeds";
|
|
||||||
import { rssFeedsJob } from "./jobs/rss-feeds";
|
import { rssFeedsJob } from "./jobs/rss-feeds";
|
||||||
import { sessionCleanupJob } from "./jobs/session-cleanup";
|
import { sessionCleanupJob } from "./jobs/session-cleanup";
|
||||||
import { updateCheckerJob } from "./jobs/update-checker";
|
import { updateCheckerJob } from "./jobs/update-checker";
|
||||||
@@ -38,4 +37,3 @@ export const jobGroup = createCronJobGroup({
|
|||||||
});
|
});
|
||||||
|
|
||||||
export type JobGroupKeys = ReturnType<(typeof jobGroup)["getKeys"]>[number];
|
export type JobGroupKeys = ReturnType<(typeof jobGroup)["getKeys"]>[number];
|
||||||
export type { RssFeed };
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import { splitToNChunks, Stopwatch } from "@homarr/common";
|
import { splitToNChunks, Stopwatch } from "@homarr/common";
|
||||||
import { EVERY_WEEK } from "@homarr/cron-jobs-core/expressions";
|
import { EVERY_WEEK } from "@homarr/cron-jobs-core/expressions";
|
||||||
import type { InferInsertModel } from "@homarr/db";
|
import type { InferInsertModel } from "@homarr/db";
|
||||||
import { db, inArray, sql } from "@homarr/db";
|
import { db, handleTransactionsAsync, inArray, sql } from "@homarr/db";
|
||||||
import { createId } from "@homarr/db/client";
|
import { createId } from "@homarr/db/client";
|
||||||
import { iconRepositories, icons } from "@homarr/db/schema";
|
import { iconRepositories, icons } from "@homarr/db/schema";
|
||||||
import { fetchIconsAsync } from "@homarr/icons";
|
import { fetchIconsAsync } from "@homarr/icons";
|
||||||
@@ -83,43 +83,81 @@ export const iconsUpdaterJob = createCronJob("iconsUpdater", EVERY_WEEK, {
|
|||||||
(iconRepository) => !repositoryIconGroups.some((group) => group.slug === iconRepository.slug),
|
(iconRepository) => !repositoryIconGroups.some((group) => group.slug === iconRepository.slug),
|
||||||
);
|
);
|
||||||
|
|
||||||
db.transaction((transaction) => {
|
await handleTransactionsAsync(db, {
|
||||||
if (newIconRepositories.length >= 1) {
|
async handleAsync(db, schema) {
|
||||||
transaction.insert(iconRepositories).values(newIconRepositories).run();
|
await db.transaction(async (transaction) => {
|
||||||
}
|
if (newIconRepositories.length >= 1) {
|
||||||
|
await transaction.insert(schema.iconRepositories).values(newIconRepositories);
|
||||||
|
}
|
||||||
|
|
||||||
if (newIcons.length >= 1) {
|
if (newIcons.length >= 1) {
|
||||||
// We only insert 5000 icons at a time to avoid SQLite limitations
|
// We only insert 5000 icons at a time to avoid SQLite limitations
|
||||||
for (const chunck of splitToNChunks(newIcons, Math.ceil(newIcons.length / 5000))) {
|
for (const chunck of splitToNChunks(newIcons, Math.ceil(newIcons.length / 5000))) {
|
||||||
transaction.insert(icons).values(chunck).run();
|
await transaction.insert(schema.icons).values(chunck);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (deadIcons.length >= 1) {
|
if (deadIcons.length >= 1) {
|
||||||
transaction
|
await transaction.delete(schema.icons).where(
|
||||||
.delete(icons)
|
inArray(
|
||||||
.where(
|
// Combine iconRepositoryId and checksum to allow same icons on different repositories
|
||||||
inArray(
|
sql`concat(${icons.iconRepositoryId}, '.', ${icons.checksum})`,
|
||||||
// Combine iconRepositoryId and checksum to allow same icons on different repositories
|
deadIcons.map((icon) => `${icon.iconRepositoryId}.${icon.checksum}`),
|
||||||
sql`concat(${icons.iconRepositoryId}, '.', ${icons.checksum})`,
|
),
|
||||||
deadIcons.map((icon) => `${icon.iconRepositoryId}.${icon.checksum}`),
|
);
|
||||||
),
|
}
|
||||||
)
|
|
||||||
.run();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (deadIconRepositories.length >= 1) {
|
if (deadIconRepositories.length >= 1) {
|
||||||
transaction
|
await transaction.delete(schema.iconRepositories).where(
|
||||||
.delete(iconRepositories)
|
inArray(
|
||||||
.where(
|
iconRepositories.id,
|
||||||
inArray(
|
deadIconRepositories.map((iconRepository) => iconRepository.id),
|
||||||
iconRepositories.id,
|
),
|
||||||
deadIconRepositories.map((iconRepository) => iconRepository.id),
|
);
|
||||||
),
|
}
|
||||||
)
|
|
||||||
.run();
|
|
||||||
}
|
|
||||||
|
|
||||||
countDeleted += deadIcons.length;
|
countDeleted += deadIcons.length;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
handleSync() {
|
||||||
|
db.transaction((transaction) => {
|
||||||
|
if (newIconRepositories.length >= 1) {
|
||||||
|
transaction.insert(iconRepositories).values(newIconRepositories).run();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newIcons.length >= 1) {
|
||||||
|
// We only insert 5000 icons at a time to avoid SQLite limitations
|
||||||
|
for (const chunck of splitToNChunks(newIcons, Math.ceil(newIcons.length / 5000))) {
|
||||||
|
transaction.insert(icons).values(chunck).run();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (deadIcons.length >= 1) {
|
||||||
|
transaction
|
||||||
|
.delete(icons)
|
||||||
|
.where(
|
||||||
|
inArray(
|
||||||
|
// Combine iconRepositoryId and checksum to allow same icons on different repositories
|
||||||
|
sql`concat(${icons.iconRepositoryId}, '.', ${icons.checksum})`,
|
||||||
|
deadIcons.map((icon) => `${icon.iconRepositoryId}.${icon.checksum}`),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (deadIconRepositories.length >= 1) {
|
||||||
|
transaction
|
||||||
|
.delete(iconRepositories)
|
||||||
|
.where(
|
||||||
|
inArray(
|
||||||
|
iconRepositories.id,
|
||||||
|
deadIconRepositories.map((iconRepository) => iconRepository.id),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
countDeleted += deadIcons.length;
|
||||||
|
});
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
logger.info(`Updated database within ${stopWatch.getElapsedInHumanWords()} (-${countDeleted}, +${countInserted})`);
|
logger.info(`Updated database within ${stopWatch.getElapsedInHumanWords()} (-${countDeleted}, +${countInserted})`);
|
||||||
|
|||||||
@@ -1,14 +1,23 @@
|
|||||||
import { EVERY_5_SECONDS } from "@homarr/cron-jobs-core/expressions";
|
import { EVERY_5_SECONDS } from "@homarr/cron-jobs-core/expressions";
|
||||||
import { systemInfoRequestHandler } from "@homarr/request-handler/health-monitoring";
|
import { clusterInfoRequestHandler, systemInfoRequestHandler } from "@homarr/request-handler/health-monitoring";
|
||||||
import { createRequestIntegrationJobHandler } from "@homarr/request-handler/lib/cached-request-integration-job-handler";
|
import { createRequestIntegrationJobHandler } from "@homarr/request-handler/lib/cached-request-integration-job-handler";
|
||||||
|
|
||||||
import { createCronJob } from "../../lib";
|
import { createCronJob } from "../../lib";
|
||||||
|
|
||||||
export const healthMonitoringJob = createCronJob("healthMonitoring", EVERY_5_SECONDS).withCallback(
|
export const healthMonitoringJob = createCronJob("healthMonitoring", EVERY_5_SECONDS).withCallback(
|
||||||
createRequestIntegrationJobHandler(systemInfoRequestHandler.handler, {
|
createRequestIntegrationJobHandler(
|
||||||
widgetKinds: ["healthMonitoring"],
|
(integration, itemOptions: Record<string, never>) => {
|
||||||
getInput: {
|
const { kind } = integration;
|
||||||
healthMonitoring: () => ({}),
|
if (kind !== "proxmox") {
|
||||||
|
return systemInfoRequestHandler.handler({ ...integration, kind }, itemOptions);
|
||||||
|
}
|
||||||
|
return clusterInfoRequestHandler.handler({ ...integration, kind }, itemOptions);
|
||||||
},
|
},
|
||||||
}),
|
{
|
||||||
|
widgetKinds: ["healthMonitoring"],
|
||||||
|
getInput: {
|
||||||
|
healthMonitoring: () => ({}),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
),
|
||||||
);
|
);
|
||||||
@@ -1,139 +1,36 @@
|
|||||||
import type { FeedData, FeedEntry } from "@extractus/feed-extractor";
|
|
||||||
import { extract } from "@extractus/feed-extractor";
|
|
||||||
import SuperJSON from "superjson";
|
import SuperJSON from "superjson";
|
||||||
|
|
||||||
import type { Modify } from "@homarr/common/types";
|
|
||||||
import { EVERY_5_MINUTES } from "@homarr/cron-jobs-core/expressions";
|
import { EVERY_5_MINUTES } from "@homarr/cron-jobs-core/expressions";
|
||||||
import { db, eq } from "@homarr/db";
|
import { db, eq } from "@homarr/db";
|
||||||
import { items } from "@homarr/db/schema";
|
import { items } from "@homarr/db/schema";
|
||||||
import { logger } from "@homarr/log";
|
import { logger } from "@homarr/log";
|
||||||
import { createItemChannel } from "@homarr/redis";
|
|
||||||
import { z } from "@homarr/validation";
|
|
||||||
|
|
||||||
// This import is done that way to avoid circular dependencies.
|
// This import is done that way to avoid circular dependencies.
|
||||||
|
import { rssFeedsRequestHandler } from "@homarr/request-handler/rss-feeds";
|
||||||
|
|
||||||
import type { WidgetComponentProps } from "../../../widgets";
|
import type { WidgetComponentProps } from "../../../widgets";
|
||||||
import { createCronJob } from "../lib";
|
import { createCronJob } from "../lib";
|
||||||
|
|
||||||
export const rssFeedsJob = createCronJob("rssFeeds", EVERY_5_MINUTES).withCallback(async () => {
|
export const rssFeedsJob = createCronJob("rssFeeds", EVERY_5_MINUTES).withCallback(async () => {
|
||||||
const itemsForIntegration = await db.query.items.findMany({
|
const rssItems = await db.query.items.findMany({
|
||||||
where: eq(items.kind, "rssFeed"),
|
where: eq(items.kind, "rssFeed"),
|
||||||
});
|
});
|
||||||
|
|
||||||
for (const item of itemsForIntegration) {
|
const itemOptions = rssItems.map((item) => SuperJSON.parse<WidgetComponentProps<"rssFeed">["options"]>(item.options));
|
||||||
const options = SuperJSON.parse<WidgetComponentProps<"rssFeed">["options"]>(item.options);
|
|
||||||
|
|
||||||
const feeds = await Promise.all(
|
for (const option of itemOptions) {
|
||||||
options.feedUrls.map(async (feedUrl) => ({
|
const maxAmountPosts = typeof option.maximumAmountPosts === "number" ? option.maximumAmountPosts : 100;
|
||||||
feedUrl,
|
for (const url of option.feedUrls) {
|
||||||
feed: (await extract(feedUrl, {
|
try {
|
||||||
getExtraEntryFields: (feedEntry) => {
|
const innerHandler = rssFeedsRequestHandler.handler({
|
||||||
const media = attemptGetImageFromEntry(feedUrl, feedEntry);
|
url,
|
||||||
if (!media) {
|
count: maxAmountPosts,
|
||||||
return {};
|
});
|
||||||
}
|
await innerHandler.getCachedOrUpdatedDataAsync({
|
||||||
return {
|
forceUpdate: true,
|
||||||
enclosure: media,
|
});
|
||||||
};
|
} catch (error) {
|
||||||
},
|
logger.error("Failed to update RSS feed", { url, error });
|
||||||
})) as ExtendedFeedData,
|
}
|
||||||
})),
|
}
|
||||||
);
|
|
||||||
|
|
||||||
const channel = createItemChannel<RssFeed[]>(item.id);
|
|
||||||
await channel.publishAndUpdateLastStateAsync(feeds);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const attemptGetImageFromEntry = (feedUrl: string, entry: object) => {
|
|
||||||
const media = getFirstMediaProperty(entry);
|
|
||||||
if (media !== null) {
|
|
||||||
return media;
|
|
||||||
}
|
|
||||||
return getImageFromStringAsFallback(feedUrl, JSON.stringify(entry));
|
|
||||||
};
|
|
||||||
|
|
||||||
const getImageFromStringAsFallback = (feedUrl: string, content: string) => {
|
|
||||||
const regex = /https?:\/\/\S+?\.(jpg|jpeg|png|gif|bmp|svg|webp|tiff)/i;
|
|
||||||
const result = regex.exec(content);
|
|
||||||
|
|
||||||
if (result == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
console.debug(
|
|
||||||
`Falling back to regex image search for '${feedUrl}'. Found ${result.length} matches in content: ${content}`,
|
|
||||||
);
|
|
||||||
return result[0];
|
|
||||||
};
|
|
||||||
|
|
||||||
const mediaProperties = [
|
|
||||||
{
|
|
||||||
path: ["enclosure", "@_url"],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: ["media:content", "@_url"],
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The RSS and Atom standards are poorly adhered to in most of the web.
|
|
||||||
* We want to show pretty background images on the posts and therefore need to extract
|
|
||||||
* the enclosure (aka. media images). This function uses the dynamic properties defined above
|
|
||||||
* to search through the possible paths and detect valid image URLs.
|
|
||||||
* @param feedObject The object to scan for.
|
|
||||||
* @returns the value of the first path that is found within the object
|
|
||||||
*/
|
|
||||||
const getFirstMediaProperty = (feedObject: object) => {
|
|
||||||
for (const mediaProperty of mediaProperties) {
|
|
||||||
let propertyIndex = 0;
|
|
||||||
let objectAtPath: object = feedObject;
|
|
||||||
while (propertyIndex < mediaProperty.path.length) {
|
|
||||||
const key = mediaProperty.path[propertyIndex];
|
|
||||||
if (key === undefined) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
const propertyEntries = Object.entries(objectAtPath);
|
|
||||||
const propertyEntry = propertyEntries.find(([entryKey]) => entryKey === key);
|
|
||||||
if (!propertyEntry) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
||||||
const [_, propertyEntryValue] = propertyEntry;
|
|
||||||
objectAtPath = propertyEntryValue as object;
|
|
||||||
propertyIndex++;
|
|
||||||
}
|
|
||||||
|
|
||||||
const validationResult = z.string().url().safeParse(objectAtPath);
|
|
||||||
if (!validationResult.success) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.debug(`Found an image in the feed entry: ${validationResult.data}`);
|
|
||||||
return validationResult.data;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* We extend the feed with custom properties.
|
|
||||||
* This interface adds properties on top of the default ones.
|
|
||||||
*/
|
|
||||||
interface ExtendedFeedEntry extends FeedEntry {
|
|
||||||
enclosure?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* We extend the feed with custom properties.
|
|
||||||
* This interface omits the default entries with our custom definition.
|
|
||||||
*/
|
|
||||||
type ExtendedFeedData = Modify<
|
|
||||||
FeedData,
|
|
||||||
{
|
|
||||||
entries?: ExtendedFeedEntry;
|
|
||||||
}
|
|
||||||
>;
|
|
||||||
|
|
||||||
export interface RssFeed {
|
|
||||||
feedUrl: string;
|
|
||||||
feed: ExtendedFeedData;
|
|
||||||
}
|
|
||||||
@@ -2,6 +2,7 @@ import Database from "better-sqlite3";
|
|||||||
import type { Logger } from "drizzle-orm";
|
import type { Logger } from "drizzle-orm";
|
||||||
import type { BetterSQLite3Database } from "drizzle-orm/better-sqlite3";
|
import type { BetterSQLite3Database } from "drizzle-orm/better-sqlite3";
|
||||||
import { drizzle as drizzleSqlite } from "drizzle-orm/better-sqlite3";
|
import { drizzle as drizzleSqlite } from "drizzle-orm/better-sqlite3";
|
||||||
|
import type { MySql2Database } from "drizzle-orm/mysql2";
|
||||||
import { drizzle as drizzleMysql } from "drizzle-orm/mysql2";
|
import { drizzle as drizzleMysql } from "drizzle-orm/mysql2";
|
||||||
import mysql from "mysql2";
|
import mysql from "mysql2";
|
||||||
|
|
||||||
@@ -11,7 +12,8 @@ import { env } from "./env";
|
|||||||
import * as mysqlSchema from "./schema/mysql";
|
import * as mysqlSchema from "./schema/mysql";
|
||||||
import * as sqliteSchema from "./schema/sqlite";
|
import * as sqliteSchema from "./schema/sqlite";
|
||||||
|
|
||||||
type HomarrDatabase = BetterSQLite3Database<typeof sqliteSchema>;
|
export type HomarrDatabase = BetterSQLite3Database<typeof sqliteSchema>;
|
||||||
|
export type HomarrDatabaseMysql = MySql2Database<typeof mysqlSchema>;
|
||||||
|
|
||||||
const init = () => {
|
const init = () => {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||||
|
|||||||
+6
-1
@@ -27,7 +27,11 @@ export const env = createEnv({
|
|||||||
.default(drivers.betterSqlite3),
|
.default(drivers.betterSqlite3),
|
||||||
...(urlRequired
|
...(urlRequired
|
||||||
? {
|
? {
|
||||||
DB_URL: z.string(),
|
DB_URL:
|
||||||
|
// Fallback to the default sqlite file path in production
|
||||||
|
process.env.NODE_ENV === "production" && isDriver("better-sqlite3")
|
||||||
|
? z.string().default("/appdata/db/db.sqlite")
|
||||||
|
: z.string().nonempty(),
|
||||||
}
|
}
|
||||||
: {}),
|
: {}),
|
||||||
...(hostRequired
|
...(hostRequired
|
||||||
@@ -58,4 +62,5 @@ export const env = createEnv({
|
|||||||
DB_PORT: process.env.DB_PORT,
|
DB_PORT: process.env.DB_PORT,
|
||||||
},
|
},
|
||||||
skipValidation: shouldSkipEnvValidation(),
|
skipValidation: shouldSkipEnvValidation(),
|
||||||
|
emptyStringAsUndefined: true,
|
||||||
});
|
});
|
||||||
@@ -7,5 +7,7 @@ export * from "drizzle-orm";
|
|||||||
export const db = database;
|
export const db = database;
|
||||||
|
|
||||||
export type Database = typeof db;
|
export type Database = typeof db;
|
||||||
|
export type { HomarrDatabaseMysql } from "./driver";
|
||||||
|
|
||||||
export { createId } from "@paralleldrive/cuid2";
|
export { createId } from "@paralleldrive/cuid2";
|
||||||
|
export { handleDiffrentDbDriverOperationsAsync as handleTransactionsAsync } from "./transactions";
|
||||||
@@ -44,11 +44,11 @@
|
|||||||
"@homarr/server-settings": "workspace:^0.1.0",
|
"@homarr/server-settings": "workspace:^0.1.0",
|
||||||
"@paralleldrive/cuid2": "^2.2.2",
|
"@paralleldrive/cuid2": "^2.2.2",
|
||||||
"@t3-oss/env-nextjs": "^0.11.1",
|
"@t3-oss/env-nextjs": "^0.11.1",
|
||||||
"@testcontainers/mysql": "^10.16.0",
|
"@testcontainers/mysql": "^10.17.1",
|
||||||
"better-sqlite3": "^11.7.2",
|
"better-sqlite3": "^11.8.1",
|
||||||
"dotenv": "^16.4.7",
|
"dotenv": "^16.4.7",
|
||||||
"drizzle-kit": "^0.30.1",
|
"drizzle-kit": "^0.30.2",
|
||||||
"drizzle-orm": "^0.38.3",
|
"drizzle-orm": "^0.38.4",
|
||||||
"drizzle-zod": "^0.6.1",
|
"drizzle-zod": "^0.6.1",
|
||||||
"mysql2": "3.12.0"
|
"mysql2": "3.12.0"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
import type { HomarrDatabase, HomarrDatabaseMysql } from "./driver";
|
||||||
|
import { env } from "./env";
|
||||||
|
import * as mysqlSchema from "./schema/mysql";
|
||||||
|
|
||||||
|
type MysqlSchema = typeof mysqlSchema;
|
||||||
|
|
||||||
|
interface HandleTransactionInput {
|
||||||
|
handleAsync: (db: HomarrDatabaseMysql, schema: MysqlSchema) => Promise<void>;
|
||||||
|
handleSync: (db: HomarrDatabase) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The below method is mostly used to handle transactions in different database drivers.
|
||||||
|
* As better-sqlite3 transactions have to be synchronous, we have to implement them in a different way.
|
||||||
|
* But it can also generally be used when dealing with different database drivers.
|
||||||
|
*/
|
||||||
|
export const handleDiffrentDbDriverOperationsAsync = async (db: HomarrDatabase, input: HandleTransactionInput) => {
|
||||||
|
if (env.DB_DRIVER !== "mysql2") {
|
||||||
|
input.handleSync(db);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await input.handleAsync(db as unknown as HomarrDatabaseMysql, mysqlSchema);
|
||||||
|
};
|
||||||
@@ -10,6 +10,7 @@ export type HomarrDocumentationPath =
|
|||||||
| "/blog/2024/09/23/version-1.0"
|
| "/blog/2024/09/23/version-1.0"
|
||||||
| "/blog/2024/12/17/open-beta-1.0"
|
| "/blog/2024/12/17/open-beta-1.0"
|
||||||
| "/blog/2024/12/31/migrate-secret-enryption-key"
|
| "/blog/2024/12/31/migrate-secret-enryption-key"
|
||||||
|
| "/blog/2025/01/19/migration-guide-1.0"
|
||||||
| "/blog/archive"
|
| "/blog/archive"
|
||||||
| "/blog/authors"
|
| "/blog/authors"
|
||||||
| "/blog/authors/ajnart"
|
| "/blog/authors/ajnart"
|
||||||
@@ -51,6 +52,7 @@ export type HomarrDocumentationPath =
|
|||||||
| "/docs/tags/bookmark"
|
| "/docs/tags/bookmark"
|
||||||
| "/docs/tags/bookmarks"
|
| "/docs/tags/bookmarks"
|
||||||
| "/docs/tags/caddy"
|
| "/docs/tags/caddy"
|
||||||
|
| "/docs/tags/certificates"
|
||||||
| "/docs/tags/checklist"
|
| "/docs/tags/checklist"
|
||||||
| "/docs/tags/code"
|
| "/docs/tags/code"
|
||||||
| "/docs/tags/community"
|
| "/docs/tags/community"
|
||||||
@@ -113,6 +115,7 @@ export type HomarrDocumentationPath =
|
|||||||
| "/docs/tags/search"
|
| "/docs/tags/search"
|
||||||
| "/docs/tags/search-engines"
|
| "/docs/tags/search-engines"
|
||||||
| "/docs/tags/security"
|
| "/docs/tags/security"
|
||||||
|
| "/docs/tags/self-signed"
|
||||||
| "/docs/tags/seo"
|
| "/docs/tags/seo"
|
||||||
| "/docs/tags/server"
|
| "/docs/tags/server"
|
||||||
| "/docs/tags/settings"
|
| "/docs/tags/settings"
|
||||||
@@ -163,10 +166,10 @@ export type HomarrDocumentationPath =
|
|||||||
| "/docs/getting-started/installation/home-assistant"
|
| "/docs/getting-started/installation/home-assistant"
|
||||||
| "/docs/getting-started/installation/portainer"
|
| "/docs/getting-started/installation/portainer"
|
||||||
| "/docs/getting-started/installation/qnap"
|
| "/docs/getting-started/installation/qnap"
|
||||||
|
| "/docs/getting-started/installation/railway"
|
||||||
| "/docs/getting-started/installation/saltbox"
|
| "/docs/getting-started/installation/saltbox"
|
||||||
| "/docs/getting-started/installation/source"
|
| "/docs/getting-started/installation/source"
|
||||||
| "/docs/getting-started/installation/synology"
|
| "/docs/getting-started/installation/synology"
|
||||||
| "/docs/getting-started/installation/truenas"
|
|
||||||
| "/docs/getting-started/installation/unraid"
|
| "/docs/getting-started/installation/unraid"
|
||||||
| "/docs/integrations/containers"
|
| "/docs/integrations/containers"
|
||||||
| "/docs/integrations/dns"
|
| "/docs/integrations/dns"
|
||||||
@@ -179,6 +182,7 @@ export type HomarrDocumentationPath =
|
|||||||
| "/docs/management/api"
|
| "/docs/management/api"
|
||||||
| "/docs/management/apps"
|
| "/docs/management/apps"
|
||||||
| "/docs/management/boards"
|
| "/docs/management/boards"
|
||||||
|
| "/docs/management/certificates"
|
||||||
| "/docs/management/integrations"
|
| "/docs/management/integrations"
|
||||||
| "/docs/management/media"
|
| "/docs/management/media"
|
||||||
| "/docs/management/search-engines"
|
| "/docs/management/search-engines"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import type { HomarrDocumentationPath } from "./homarr-docs-sitemap";
|
import type { HomarrDocumentationPath } from "./homarr-docs-sitemap";
|
||||||
|
|
||||||
const documentationBaseUrl = "https://deploy-preview-113--homarr-docs.netlify.app";
|
const documentationBaseUrl = "https://homarr.dev";
|
||||||
|
|
||||||
// Please use the method so the path can be checked!
|
// Please use the method so the path can be checked!
|
||||||
export const createDocumentationLink = (path: HomarrDocumentationPath, hashTag?: `#${string}`) =>
|
export const createDocumentationLink = (path: HomarrDocumentationPath, hashTag?: `#${string}`) =>
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ export const integrationSecretKindObject = {
|
|||||||
apiKey: { isPublic: false },
|
apiKey: { isPublic: false },
|
||||||
username: { isPublic: true },
|
username: { isPublic: true },
|
||||||
password: { isPublic: false },
|
password: { isPublic: false },
|
||||||
|
tokenId: { isPublic: true },
|
||||||
|
realm: { isPublic: true },
|
||||||
} satisfies Record<string, { isPublic: boolean }>;
|
} satisfies Record<string, { isPublic: boolean }>;
|
||||||
|
|
||||||
export const integrationSecretKinds = objectKeys(integrationSecretKindObject);
|
export const integrationSecretKinds = objectKeys(integrationSecretKindObject);
|
||||||
@@ -137,6 +139,12 @@ export const integrationDefs = {
|
|||||||
category: ["mediaTranscoding"],
|
category: ["mediaTranscoding"],
|
||||||
iconUrl: "https://cdn.jsdelivr.net/gh/homarr-labs/dashboard-icons@master/png/tdarr.png",
|
iconUrl: "https://cdn.jsdelivr.net/gh/homarr-labs/dashboard-icons@master/png/tdarr.png",
|
||||||
},
|
},
|
||||||
|
proxmox: {
|
||||||
|
name: "Proxmox",
|
||||||
|
secretKinds: [["username", "tokenId", "apiKey", "realm"]],
|
||||||
|
category: ["healthMonitoring"],
|
||||||
|
iconUrl: "https://cdn.jsdelivr.net/gh/walkxcode/dashboard-icons@master/png/proxmox.png",
|
||||||
|
},
|
||||||
} as const satisfies Record<string, integrationDefinition>;
|
} as const satisfies Record<string, integrationDefinition>;
|
||||||
|
|
||||||
export const integrationKinds = objectKeys(integrationDefs) as AtLeastOneOf<IntegrationKind>;
|
export const integrationKinds = objectKeys(integrationDefs) as AtLeastOneOf<IntegrationKind>;
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
import baseConfig from "@homarr/eslint-config/base";
|
||||||
|
|
||||||
|
/** @type {import('typescript-eslint').Config} */
|
||||||
|
export default [
|
||||||
|
{
|
||||||
|
ignores: [],
|
||||||
|
},
|
||||||
|
...baseConfig,
|
||||||
|
];
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
export * from "./src";
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
{
|
||||||
|
"name": "@homarr/docker",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"private": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"type": "module",
|
||||||
|
"exports": {
|
||||||
|
".": "./index.ts",
|
||||||
|
"./env": "./src/env.ts"
|
||||||
|
},
|
||||||
|
"typesVersions": {
|
||||||
|
"*": {
|
||||||
|
"*": [
|
||||||
|
"src/*"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"clean": "rm -rf .turbo node_modules",
|
||||||
|
"format": "prettier --check . --ignore-path ../../.gitignore",
|
||||||
|
"lint": "eslint",
|
||||||
|
"typecheck": "tsc --noEmit"
|
||||||
|
},
|
||||||
|
"prettier": "@homarr/prettier-config",
|
||||||
|
"dependencies": {
|
||||||
|
"@homarr/common": "workspace:^0.1.0",
|
||||||
|
"@t3-oss/env-nextjs": "^0.11.1",
|
||||||
|
"dockerode": "^4.0.4"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@homarr/eslint-config": "workspace:^0.2.0",
|
||||||
|
"@homarr/prettier-config": "workspace:^0.1.0",
|
||||||
|
"@homarr/tsconfig": "workspace:^0.1.0",
|
||||||
|
"@types/dockerode": "^3.3.34",
|
||||||
|
"eslint": "^9.18.0",
|
||||||
|
"typescript": "^5.7.3"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import { createEnv } from "@t3-oss/env-nextjs";
|
||||||
|
import { z } from "zod";
|
||||||
|
|
||||||
|
import { shouldSkipEnvValidation } from "@homarr/common/env-validation";
|
||||||
|
|
||||||
|
export const env = createEnv({
|
||||||
|
server: {
|
||||||
|
// Comma separated list of docker hostnames that can be used to connect to query the docker endpoints (localhost:2375,host.docker.internal:2375, ...)
|
||||||
|
DOCKER_HOSTNAMES: z.string().optional(),
|
||||||
|
DOCKER_PORTS: z.string().optional(),
|
||||||
|
},
|
||||||
|
runtimeEnv: {
|
||||||
|
DOCKER_HOSTNAMES: process.env.DOCKER_HOSTNAMES,
|
||||||
|
DOCKER_PORTS: process.env.DOCKER_PORTS,
|
||||||
|
},
|
||||||
|
skipValidation: shouldSkipEnvValidation(),
|
||||||
|
emptyStringAsUndefined: true,
|
||||||
|
});
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
import type Docker from "dockerode";
|
||||||
|
|
||||||
|
export type { DockerInstance } from "./singleton";
|
||||||
|
export { DockerSingleton } from "./singleton";
|
||||||
|
export type { ContainerInfo, Container, Port } from "dockerode";
|
||||||
|
export type { Docker };
|
||||||
|
|
||||||
|
export const containerStates = ["created", "running", "paused", "restarting", "exited", "removing", "dead"] as const;
|
||||||
|
|
||||||
|
export type ContainerState = (typeof containerStates)[number];
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
import Docker from "dockerode";
|
||||||
|
|
||||||
|
import { env } from "./env";
|
||||||
|
|
||||||
|
export interface DockerInstance {
|
||||||
|
host: string;
|
||||||
|
instance: Docker;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class DockerSingleton {
|
||||||
|
private static instances: DockerInstance[] | null = null;
|
||||||
|
|
||||||
|
private createInstances() {
|
||||||
|
const hostVariable = env.DOCKER_HOSTNAMES;
|
||||||
|
const portVariable = env.DOCKER_PORTS;
|
||||||
|
if (hostVariable === undefined || portVariable === undefined) {
|
||||||
|
return [{ host: "socket", instance: new Docker() }];
|
||||||
|
}
|
||||||
|
const hostnames = hostVariable.split(",");
|
||||||
|
const ports = portVariable.split(",");
|
||||||
|
|
||||||
|
if (hostnames.length !== ports.length) {
|
||||||
|
throw new Error("The number of hosts and ports must match");
|
||||||
|
}
|
||||||
|
|
||||||
|
return hostnames.map((host, i) => {
|
||||||
|
// Check above ensures that ports[i] is not undefined
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||||
|
const port = ports[i]!;
|
||||||
|
|
||||||
|
return {
|
||||||
|
host: `${host}:${port}`,
|
||||||
|
instance: new Docker({
|
||||||
|
host,
|
||||||
|
port: parseInt(port, 10),
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static findInstance(host: string): DockerInstance | undefined {
|
||||||
|
return this.instances?.find((instance) => instance.host === host);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static getInstances(): DockerInstance[] {
|
||||||
|
if (this.instances) {
|
||||||
|
return this.instances;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.instances = new DockerSingleton().createInstances();
|
||||||
|
return this.instances;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"extends": "@homarr/tsconfig/base.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"tsBuildInfoFile": "node_modules/.cache/tsbuildinfo.json"
|
||||||
|
},
|
||||||
|
"include": ["*.ts", "src"],
|
||||||
|
"exclude": ["node_modules"]
|
||||||
|
}
|
||||||
@@ -26,7 +26,7 @@
|
|||||||
"@homarr/common": "workspace:^0.1.0",
|
"@homarr/common": "workspace:^0.1.0",
|
||||||
"@homarr/translation": "workspace:^0.1.0",
|
"@homarr/translation": "workspace:^0.1.0",
|
||||||
"@homarr/validation": "workspace:^0.1.0",
|
"@homarr/validation": "workspace:^0.1.0",
|
||||||
"@mantine/form": "^7.16.0"
|
"@mantine/form": "^7.16.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@homarr/eslint-config": "workspace:^0.2.0",
|
"@homarr/eslint-config": "workspace:^0.2.0",
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
"@ctrl/deluge": "^7.1.0",
|
"@ctrl/deluge": "^7.1.0",
|
||||||
"@ctrl/qbittorrent": "^9.2.0",
|
"@ctrl/qbittorrent": "^9.2.0",
|
||||||
"@ctrl/transmission": "^7.2.0",
|
"@ctrl/transmission": "^7.2.0",
|
||||||
|
"@homarr/certificates": "workspace:^0.1.0",
|
||||||
"@homarr/common": "workspace:^0.1.0",
|
"@homarr/common": "workspace:^0.1.0",
|
||||||
"@homarr/db": "workspace:^0.1.0",
|
"@homarr/db": "workspace:^0.1.0",
|
||||||
"@homarr/definitions": "workspace:^0.1.0",
|
"@homarr/definitions": "workspace:^0.1.0",
|
||||||
@@ -35,6 +36,8 @@
|
|||||||
"@homarr/translation": "workspace:^0.1.0",
|
"@homarr/translation": "workspace:^0.1.0",
|
||||||
"@homarr/validation": "workspace:^0.1.0",
|
"@homarr/validation": "workspace:^0.1.0",
|
||||||
"@jellyfin/sdk": "^0.11.0",
|
"@jellyfin/sdk": "^0.11.0",
|
||||||
|
"proxmox-api": "1.1.1",
|
||||||
|
"undici": "7.3.0",
|
||||||
"xml2js": "^0.6.2"
|
"xml2js": "^0.6.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import { fetchWithTrustedCertificatesAsync } from "@homarr/certificates/server";
|
||||||
|
|
||||||
import { Integration } from "../base/integration";
|
import { Integration } from "../base/integration";
|
||||||
import { IntegrationTestConnectionError } from "../base/test-connection-error";
|
import { IntegrationTestConnectionError } from "../base/test-connection-error";
|
||||||
import type { DnsHoleSummaryIntegration } from "../interfaces/dns-hole-summary/dns-hole-summary-integration";
|
import type { DnsHoleSummaryIntegration } from "../interfaces/dns-hole-summary/dns-hole-summary-integration";
|
||||||
@@ -6,7 +8,7 @@ import { filteringStatusSchema, statsResponseSchema, statusResponseSchema } from
|
|||||||
|
|
||||||
export class AdGuardHomeIntegration extends Integration implements DnsHoleSummaryIntegration {
|
export class AdGuardHomeIntegration extends Integration implements DnsHoleSummaryIntegration {
|
||||||
public async getSummaryAsync(): Promise<DnsHoleSummary> {
|
public async getSummaryAsync(): Promise<DnsHoleSummary> {
|
||||||
const statsResponse = await fetch(this.url("/control/stats"), {
|
const statsResponse = await fetchWithTrustedCertificatesAsync(this.url("/control/stats"), {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Basic ${this.getAuthorizationHeaderValue()}`,
|
Authorization: `Basic ${this.getAuthorizationHeaderValue()}`,
|
||||||
},
|
},
|
||||||
@@ -18,7 +20,7 @@ export class AdGuardHomeIntegration extends Integration implements DnsHoleSummar
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const statusResponse = await fetch(this.url("/control/status"), {
|
const statusResponse = await fetchWithTrustedCertificatesAsync(this.url("/control/status"), {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Basic ${this.getAuthorizationHeaderValue()}`,
|
Authorization: `Basic ${this.getAuthorizationHeaderValue()}`,
|
||||||
},
|
},
|
||||||
@@ -30,7 +32,7 @@ export class AdGuardHomeIntegration extends Integration implements DnsHoleSummar
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const filteringStatusResponse = await fetch(this.url("/control/filtering/status"), {
|
const filteringStatusResponse = await fetchWithTrustedCertificatesAsync(this.url("/control/filtering/status"), {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Basic ${this.getAuthorizationHeaderValue()}`,
|
Authorization: `Basic ${this.getAuthorizationHeaderValue()}`,
|
||||||
},
|
},
|
||||||
@@ -86,7 +88,7 @@ export class AdGuardHomeIntegration extends Integration implements DnsHoleSummar
|
|||||||
public async testConnectionAsync(): Promise<void> {
|
public async testConnectionAsync(): Promise<void> {
|
||||||
await super.handleTestConnectionResponseAsync({
|
await super.handleTestConnectionResponseAsync({
|
||||||
queryFunctionAsync: async () => {
|
queryFunctionAsync: async () => {
|
||||||
return await fetch(this.url("/control/status"), {
|
return await fetchWithTrustedCertificatesAsync(this.url("/control/status"), {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Basic ${this.getAuthorizationHeaderValue()}`,
|
Authorization: `Basic ${this.getAuthorizationHeaderValue()}`,
|
||||||
},
|
},
|
||||||
@@ -94,7 +96,7 @@ export class AdGuardHomeIntegration extends Integration implements DnsHoleSummar
|
|||||||
},
|
},
|
||||||
handleResponseAsync: async (response) => {
|
handleResponseAsync: async (response) => {
|
||||||
try {
|
try {
|
||||||
const result = (await response.json()) as unknown;
|
const result = await response.json();
|
||||||
if (typeof result === "object" && result !== null) return;
|
if (typeof result === "object" && result !== null) return;
|
||||||
} catch {
|
} catch {
|
||||||
throw new IntegrationTestConnectionError("invalidJson");
|
throw new IntegrationTestConnectionError("invalidJson");
|
||||||
@@ -106,7 +108,7 @@ export class AdGuardHomeIntegration extends Integration implements DnsHoleSummar
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async enableAsync(): Promise<void> {
|
public async enableAsync(): Promise<void> {
|
||||||
const response = await fetch(this.url("/control/protection"), {
|
const response = await fetchWithTrustedCertificatesAsync(this.url("/control/protection"), {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@@ -124,7 +126,7 @@ export class AdGuardHomeIntegration extends Integration implements DnsHoleSummar
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async disableAsync(duration = 0): Promise<void> {
|
public async disableAsync(duration = 0): Promise<void> {
|
||||||
const response = await fetch(this.url("/control/protection"), {
|
const response = await fetchWithTrustedCertificatesAsync(this.url("/control/protection"), {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import { OverseerrIntegration } from "../overseerr/overseerr-integration";
|
|||||||
import { PiHoleIntegration } from "../pi-hole/pi-hole-integration";
|
import { PiHoleIntegration } from "../pi-hole/pi-hole-integration";
|
||||||
import { PlexIntegration } from "../plex/plex-integration";
|
import { PlexIntegration } from "../plex/plex-integration";
|
||||||
import { ProwlarrIntegration } from "../prowlarr/prowlarr-integration";
|
import { ProwlarrIntegration } from "../prowlarr/prowlarr-integration";
|
||||||
|
import { ProxmoxIntegration } from "../proxmox/proxmox-integration";
|
||||||
import type { Integration, IntegrationInput } from "./integration";
|
import type { Integration, IntegrationInput } from "./integration";
|
||||||
|
|
||||||
export const integrationCreator = <TKind extends keyof typeof integrationCreators>(
|
export const integrationCreator = <TKind extends keyof typeof integrationCreators>(
|
||||||
@@ -72,4 +73,5 @@ export const integrationCreators = {
|
|||||||
readarr: ReadarrIntegration,
|
readarr: ReadarrIntegration,
|
||||||
dashDot: DashDotIntegration,
|
dashDot: DashDotIntegration,
|
||||||
tdarr: TdarrIntegration,
|
tdarr: TdarrIntegration,
|
||||||
|
proxmox: ProxmoxIntegration,
|
||||||
} satisfies Record<IntegrationKind, new (integration: IntegrationInput) => Integration>;
|
} satisfies Record<IntegrationKind, new (integration: IntegrationInput) => Integration>;
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import type { Response } from "undici";
|
||||||
|
|
||||||
import { extractErrorMessage, removeTrailingSlash } from "@homarr/common";
|
import { extractErrorMessage, removeTrailingSlash } from "@homarr/common";
|
||||||
import type { IntegrationSecretKind } from "@homarr/definitions";
|
import type { IntegrationSecretKind } from "@homarr/definitions";
|
||||||
import { logger } from "@homarr/log";
|
import { logger } from "@homarr/log";
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import "@homarr/redis";
|
|||||||
|
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
|
|
||||||
|
import { fetchWithTrustedCertificatesAsync } from "@homarr/certificates/server";
|
||||||
import { z } from "@homarr/validation";
|
import { z } from "@homarr/validation";
|
||||||
|
|
||||||
import { createChannelEventHistory } from "../../../redis/src/lib/channel";
|
import { createChannelEventHistory } from "../../../redis/src/lib/channel";
|
||||||
@@ -12,7 +13,7 @@ import type { HealthMonitoring } from "../types";
|
|||||||
|
|
||||||
export class DashDotIntegration extends Integration {
|
export class DashDotIntegration extends Integration {
|
||||||
public async testConnectionAsync(): Promise<void> {
|
public async testConnectionAsync(): Promise<void> {
|
||||||
const response = await fetch(this.url("/info"));
|
const response = await fetchWithTrustedCertificatesAsync(this.url("/info"));
|
||||||
await response.json();
|
await response.json();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,7 +53,7 @@ export class DashDotIntegration extends Integration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async getInfoAsync() {
|
private async getInfoAsync() {
|
||||||
const infoResponse = await fetch(this.url("/info"));
|
const infoResponse = await fetchWithTrustedCertificatesAsync(this.url("/info"));
|
||||||
const serverInfo = await internalServerInfoApi.parseAsync(await infoResponse.json());
|
const serverInfo = await internalServerInfoApi.parseAsync(await infoResponse.json());
|
||||||
return {
|
return {
|
||||||
maxAvailableMemoryBytes: serverInfo.ram.size,
|
maxAvailableMemoryBytes: serverInfo.ram.size,
|
||||||
@@ -66,7 +67,7 @@ export class DashDotIntegration extends Integration {
|
|||||||
|
|
||||||
private async getCurrentCpuLoadAsync() {
|
private async getCurrentCpuLoadAsync() {
|
||||||
const channel = this.getChannel();
|
const channel = this.getChannel();
|
||||||
const cpu = await fetch(this.url("/load/cpu"));
|
const cpu = await fetchWithTrustedCertificatesAsync(this.url("/load/cpu"));
|
||||||
const data = await cpuLoadPerCoreApiList.parseAsync(await cpu.json());
|
const data = await cpuLoadPerCoreApiList.parseAsync(await cpu.json());
|
||||||
await channel.pushAsync(data);
|
await channel.pushAsync(data);
|
||||||
return {
|
return {
|
||||||
@@ -88,12 +89,12 @@ export class DashDotIntegration extends Integration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async getCurrentStorageLoadAsync() {
|
private async getCurrentStorageLoadAsync() {
|
||||||
const storageLoad = await fetch(this.url("/load/storage"));
|
const storageLoad = await fetchWithTrustedCertificatesAsync(this.url("/load/storage"));
|
||||||
return (await storageLoad.json()) as number[];
|
return (await storageLoad.json()) as number[];
|
||||||
}
|
}
|
||||||
|
|
||||||
private async getCurrentMemoryLoadAsync() {
|
private async getCurrentMemoryLoadAsync() {
|
||||||
const memoryLoad = await fetch(this.url("/load/ram"));
|
const memoryLoad = await fetchWithTrustedCertificatesAsync(this.url("/load/ram"));
|
||||||
const data = await memoryLoadApi.parseAsync(await memoryLoad.json());
|
const data = await memoryLoadApi.parseAsync(await memoryLoad.json());
|
||||||
return {
|
return {
|
||||||
loadInBytes: data.load,
|
loadInBytes: data.load,
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import { Deluge } from "@ctrl/deluge";
|
import { Deluge } from "@ctrl/deluge";
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
|
|
||||||
|
import { createCertificateAgentAsync } from "@homarr/certificates/server";
|
||||||
|
|
||||||
import type { DownloadClientJobsAndStatus } from "../../interfaces/downloads/download-client-data";
|
import type { DownloadClientJobsAndStatus } from "../../interfaces/downloads/download-client-data";
|
||||||
import { DownloadClientIntegration } from "../../interfaces/downloads/download-client-integration";
|
import { DownloadClientIntegration } from "../../interfaces/downloads/download-client-integration";
|
||||||
import type { DownloadClientItem } from "../../interfaces/downloads/download-client-items";
|
import type { DownloadClientItem } from "../../interfaces/downloads/download-client-items";
|
||||||
@@ -8,13 +10,13 @@ import type { DownloadClientStatus } from "../../interfaces/downloads/download-c
|
|||||||
|
|
||||||
export class DelugeIntegration extends DownloadClientIntegration {
|
export class DelugeIntegration extends DownloadClientIntegration {
|
||||||
public async testConnectionAsync(): Promise<void> {
|
public async testConnectionAsync(): Promise<void> {
|
||||||
const client = this.getClient();
|
const client = await this.getClientAsync();
|
||||||
await client.login();
|
await client.login();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getClientJobsAndStatusAsync(): Promise<DownloadClientJobsAndStatus> {
|
public async getClientJobsAndStatusAsync(): Promise<DownloadClientJobsAndStatus> {
|
||||||
const type = "torrent";
|
const type = "torrent";
|
||||||
const client = this.getClient();
|
const client = await this.getClientAsync();
|
||||||
const {
|
const {
|
||||||
stats: { download_rate, upload_rate },
|
stats: { download_rate, upload_rate },
|
||||||
torrents: rawTorrents,
|
torrents: rawTorrents,
|
||||||
@@ -57,7 +59,7 @@ export class DelugeIntegration extends DownloadClientIntegration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async pauseQueueAsync() {
|
public async pauseQueueAsync() {
|
||||||
const client = this.getClient();
|
const client = await this.getClientAsync();
|
||||||
const store = (await client.listTorrents()).result.torrents;
|
const store = (await client.listTorrents()).result.torrents;
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
Object.entries(store).map(async ([id]) => {
|
Object.entries(store).map(async ([id]) => {
|
||||||
@@ -67,11 +69,12 @@ export class DelugeIntegration extends DownloadClientIntegration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async pauseItemAsync({ id }: DownloadClientItem): Promise<void> {
|
public async pauseItemAsync({ id }: DownloadClientItem): Promise<void> {
|
||||||
await this.getClient().pauseTorrent(id);
|
const client = await this.getClientAsync();
|
||||||
|
await client.pauseTorrent(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async resumeQueueAsync() {
|
public async resumeQueueAsync() {
|
||||||
const client = this.getClient();
|
const client = await this.getClientAsync();
|
||||||
const store = (await client.listTorrents()).result.torrents;
|
const store = (await client.listTorrents()).result.torrents;
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
Object.entries(store).map(async ([id]) => {
|
Object.entries(store).map(async ([id]) => {
|
||||||
@@ -81,17 +84,20 @@ export class DelugeIntegration extends DownloadClientIntegration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async resumeItemAsync({ id }: DownloadClientItem): Promise<void> {
|
public async resumeItemAsync({ id }: DownloadClientItem): Promise<void> {
|
||||||
await this.getClient().resumeTorrent(id);
|
const client = await this.getClientAsync();
|
||||||
|
await client.resumeTorrent(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async deleteItemAsync({ id }: DownloadClientItem, fromDisk: boolean): Promise<void> {
|
public async deleteItemAsync({ id }: DownloadClientItem, fromDisk: boolean): Promise<void> {
|
||||||
await this.getClient().removeTorrent(id, fromDisk);
|
const client = await this.getClientAsync();
|
||||||
|
await client.removeTorrent(id, fromDisk);
|
||||||
}
|
}
|
||||||
|
|
||||||
private getClient() {
|
private async getClientAsync() {
|
||||||
return new Deluge({
|
return new Deluge({
|
||||||
baseUrl: this.url("/").toString(),
|
baseUrl: this.url("/").toString(),
|
||||||
password: this.getSecretValue("password"),
|
password: this.getSecretValue("password"),
|
||||||
|
dispatcher: await createCertificateAgentAsync(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
|
|
||||||
|
import { fetchWithTrustedCertificatesAsync } from "@homarr/certificates/server";
|
||||||
|
|
||||||
import type { DownloadClientJobsAndStatus } from "../../interfaces/downloads/download-client-data";
|
import type { DownloadClientJobsAndStatus } from "../../interfaces/downloads/download-client-data";
|
||||||
import { DownloadClientIntegration } from "../../interfaces/downloads/download-client-integration";
|
import { DownloadClientIntegration } from "../../interfaces/downloads/download-client-integration";
|
||||||
import type { DownloadClientItem } from "../../interfaces/downloads/download-client-items";
|
import type { DownloadClientItem } from "../../interfaces/downloads/download-client-items";
|
||||||
@@ -94,9 +96,9 @@ export class NzbGetIntegration extends DownloadClientIntegration {
|
|||||||
): Promise<ReturnType<NzbGetClient[CallType]>> {
|
): Promise<ReturnType<NzbGetClient[CallType]>> {
|
||||||
const username = this.getSecretValue("username");
|
const username = this.getSecretValue("username");
|
||||||
const password = this.getSecretValue("password");
|
const password = this.getSecretValue("password");
|
||||||
const url = this.url(`/${username}:${password}/jsonrpc`);
|
const url = this.url(`/${encodeURIComponent(username)}:${encodeURIComponent(password)}/jsonrpc`);
|
||||||
const body = JSON.stringify({ method, params });
|
const body = JSON.stringify({ method, params });
|
||||||
return await fetch(url, { method: "POST", body })
|
return await fetchWithTrustedCertificatesAsync(url, { method: "POST", body })
|
||||||
.then(async (response) => {
|
.then(async (response) => {
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error(response.statusText);
|
throw new Error(response.statusText);
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import { QBittorrent } from "@ctrl/qbittorrent";
|
import { QBittorrent } from "@ctrl/qbittorrent";
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
|
|
||||||
|
import { createCertificateAgentAsync } from "@homarr/certificates/server";
|
||||||
|
|
||||||
import type { DownloadClientJobsAndStatus } from "../../interfaces/downloads/download-client-data";
|
import type { DownloadClientJobsAndStatus } from "../../interfaces/downloads/download-client-data";
|
||||||
import { DownloadClientIntegration } from "../../interfaces/downloads/download-client-integration";
|
import { DownloadClientIntegration } from "../../interfaces/downloads/download-client-integration";
|
||||||
import type { DownloadClientItem } from "../../interfaces/downloads/download-client-items";
|
import type { DownloadClientItem } from "../../interfaces/downloads/download-client-items";
|
||||||
@@ -8,13 +10,13 @@ import type { DownloadClientStatus } from "../../interfaces/downloads/download-c
|
|||||||
|
|
||||||
export class QBitTorrentIntegration extends DownloadClientIntegration {
|
export class QBitTorrentIntegration extends DownloadClientIntegration {
|
||||||
public async testConnectionAsync(): Promise<void> {
|
public async testConnectionAsync(): Promise<void> {
|
||||||
const client = this.getClient();
|
const client = await this.getClientAsync();
|
||||||
await client.login();
|
await client.login();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getClientJobsAndStatusAsync(): Promise<DownloadClientJobsAndStatus> {
|
public async getClientJobsAndStatusAsync(): Promise<DownloadClientJobsAndStatus> {
|
||||||
const type = "torrent";
|
const type = "torrent";
|
||||||
const client = this.getClient();
|
const client = await this.getClientAsync();
|
||||||
const torrents = await client.listTorrents();
|
const torrents = await client.listTorrents();
|
||||||
const rates = torrents.reduce(
|
const rates = torrents.reduce(
|
||||||
({ down, up }, { dlspeed, upspeed }) => ({ down: down + dlspeed, up: up + upspeed }),
|
({ down, up }, { dlspeed, upspeed }) => ({ down: down + dlspeed, up: up + upspeed }),
|
||||||
@@ -50,30 +52,36 @@ export class QBitTorrentIntegration extends DownloadClientIntegration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async pauseQueueAsync() {
|
public async pauseQueueAsync() {
|
||||||
await this.getClient().pauseTorrent("all");
|
const client = await this.getClientAsync();
|
||||||
|
await client.pauseTorrent("all");
|
||||||
}
|
}
|
||||||
|
|
||||||
public async pauseItemAsync({ id }: DownloadClientItem): Promise<void> {
|
public async pauseItemAsync({ id }: DownloadClientItem): Promise<void> {
|
||||||
await this.getClient().pauseTorrent(id);
|
const client = await this.getClientAsync();
|
||||||
|
await client.pauseTorrent(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async resumeQueueAsync() {
|
public async resumeQueueAsync() {
|
||||||
await this.getClient().resumeTorrent("all");
|
const client = await this.getClientAsync();
|
||||||
|
await client.resumeTorrent("all");
|
||||||
}
|
}
|
||||||
|
|
||||||
public async resumeItemAsync({ id }: DownloadClientItem): Promise<void> {
|
public async resumeItemAsync({ id }: DownloadClientItem): Promise<void> {
|
||||||
await this.getClient().resumeTorrent(id);
|
const client = await this.getClientAsync();
|
||||||
|
await client.resumeTorrent(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async deleteItemAsync({ id }: DownloadClientItem, fromDisk: boolean): Promise<void> {
|
public async deleteItemAsync({ id }: DownloadClientItem, fromDisk: boolean): Promise<void> {
|
||||||
await this.getClient().removeTorrent(id, fromDisk);
|
const client = await this.getClientAsync();
|
||||||
|
await client.removeTorrent(id, fromDisk);
|
||||||
}
|
}
|
||||||
|
|
||||||
private getClient() {
|
private async getClientAsync() {
|
||||||
return new QBittorrent({
|
return new QBittorrent({
|
||||||
baseUrl: this.url("/").toString(),
|
baseUrl: this.url("/").toString(),
|
||||||
username: this.getSecretValue("username"),
|
username: this.getSecretValue("username"),
|
||||||
password: this.getSecretValue("password"),
|
password: this.getSecretValue("password"),
|
||||||
|
dispatcher: await createCertificateAgentAsync(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
import duration from "dayjs/plugin/duration";
|
import duration from "dayjs/plugin/duration";
|
||||||
|
|
||||||
|
import { fetchWithTrustedCertificatesAsync } from "@homarr/certificates/server";
|
||||||
|
|
||||||
import type { DownloadClientJobsAndStatus } from "../../interfaces/downloads/download-client-data";
|
import type { DownloadClientJobsAndStatus } from "../../interfaces/downloads/download-client-data";
|
||||||
import { DownloadClientIntegration } from "../../interfaces/downloads/download-client-integration";
|
import { DownloadClientIntegration } from "../../interfaces/downloads/download-client-integration";
|
||||||
import type { DownloadClientItem } from "../../interfaces/downloads/download-client-items";
|
import type { DownloadClientItem } from "../../interfaces/downloads/download-client-items";
|
||||||
@@ -106,12 +108,12 @@ export class SabnzbdIntegration extends DownloadClientIntegration {
|
|||||||
apikey: this.getSecretValue("apiKey"),
|
apikey: this.getSecretValue("apiKey"),
|
||||||
});
|
});
|
||||||
|
|
||||||
return await fetch(url)
|
return await fetchWithTrustedCertificatesAsync(url)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error(response.statusText);
|
throw new Error(response.statusText);
|
||||||
}
|
}
|
||||||
return response.json() as Promise<unknown>;
|
return response.json();
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
if (error instanceof Error) {
|
if (error instanceof Error) {
|
||||||
|
|||||||
+17
-10
@@ -1,6 +1,8 @@
|
|||||||
import { Transmission } from "@ctrl/transmission";
|
import { Transmission } from "@ctrl/transmission";
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
|
|
||||||
|
import { createCertificateAgentAsync } from "@homarr/certificates/server";
|
||||||
|
|
||||||
import type { DownloadClientJobsAndStatus } from "../../interfaces/downloads/download-client-data";
|
import type { DownloadClientJobsAndStatus } from "../../interfaces/downloads/download-client-data";
|
||||||
import { DownloadClientIntegration } from "../../interfaces/downloads/download-client-integration";
|
import { DownloadClientIntegration } from "../../interfaces/downloads/download-client-integration";
|
||||||
import type { DownloadClientItem } from "../../interfaces/downloads/download-client-items";
|
import type { DownloadClientItem } from "../../interfaces/downloads/download-client-items";
|
||||||
@@ -8,12 +10,13 @@ import type { DownloadClientStatus } from "../../interfaces/downloads/download-c
|
|||||||
|
|
||||||
export class TransmissionIntegration extends DownloadClientIntegration {
|
export class TransmissionIntegration extends DownloadClientIntegration {
|
||||||
public async testConnectionAsync(): Promise<void> {
|
public async testConnectionAsync(): Promise<void> {
|
||||||
await this.getClient().getSession();
|
const client = await this.getClientAsync();
|
||||||
|
await client.getSession();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getClientJobsAndStatusAsync(): Promise<DownloadClientJobsAndStatus> {
|
public async getClientJobsAndStatusAsync(): Promise<DownloadClientJobsAndStatus> {
|
||||||
const type = "torrent";
|
const type = "torrent";
|
||||||
const client = this.getClient();
|
const client = await this.getClientAsync();
|
||||||
const { torrents } = (await client.listTorrents()).arguments;
|
const { torrents } = (await client.listTorrents()).arguments;
|
||||||
const rates = torrents.reduce(
|
const rates = torrents.reduce(
|
||||||
({ down, up }, { rateDownload, rateUpload }) => ({ down: down + rateDownload, up: up + rateUpload }),
|
({ down, up }, { rateDownload, rateUpload }) => ({ down: down + rateDownload, up: up + rateUpload }),
|
||||||
@@ -47,34 +50,38 @@ export class TransmissionIntegration extends DownloadClientIntegration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async pauseQueueAsync() {
|
public async pauseQueueAsync() {
|
||||||
const client = this.getClient();
|
const client = await this.getClientAsync();
|
||||||
const ids = (await client.listTorrents()).arguments.torrents.map(({ hashString }) => hashString);
|
const ids = (await client.listTorrents()).arguments.torrents.map(({ hashString }) => hashString);
|
||||||
await this.getClient().pauseTorrent(ids);
|
await client.pauseTorrent(ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async pauseItemAsync({ id }: DownloadClientItem): Promise<void> {
|
public async pauseItemAsync({ id }: DownloadClientItem): Promise<void> {
|
||||||
await this.getClient().pauseTorrent(id);
|
const client = await this.getClientAsync();
|
||||||
|
await client.pauseTorrent(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async resumeQueueAsync() {
|
public async resumeQueueAsync() {
|
||||||
const client = this.getClient();
|
const client = await this.getClientAsync();
|
||||||
const ids = (await client.listTorrents()).arguments.torrents.map(({ hashString }) => hashString);
|
const ids = (await client.listTorrents()).arguments.torrents.map(({ hashString }) => hashString);
|
||||||
await this.getClient().resumeTorrent(ids);
|
await client.resumeTorrent(ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async resumeItemAsync({ id }: DownloadClientItem): Promise<void> {
|
public async resumeItemAsync({ id }: DownloadClientItem): Promise<void> {
|
||||||
await this.getClient().resumeTorrent(id);
|
const client = await this.getClientAsync();
|
||||||
|
await client.resumeTorrent(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async deleteItemAsync({ id }: DownloadClientItem, fromDisk: boolean): Promise<void> {
|
public async deleteItemAsync({ id }: DownloadClientItem, fromDisk: boolean): Promise<void> {
|
||||||
await this.getClient().removeTorrent(id, fromDisk);
|
const client = await this.getClientAsync();
|
||||||
|
await client.removeTorrent(id, fromDisk);
|
||||||
}
|
}
|
||||||
|
|
||||||
private getClient() {
|
private async getClientAsync() {
|
||||||
return new Transmission({
|
return new Transmission({
|
||||||
baseUrl: this.url("/").toString(),
|
baseUrl: this.url("/").toString(),
|
||||||
username: this.getSecretValue("username"),
|
username: this.getSecretValue("username"),
|
||||||
password: this.getSecretValue("password"),
|
password: this.getSecretValue("password"),
|
||||||
|
dispatcher: await createCertificateAgentAsync(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { fetchWithTrustedCertificatesAsync } from "@homarr/certificates/server";
|
||||||
import { logger } from "@homarr/log";
|
import { logger } from "@homarr/log";
|
||||||
|
|
||||||
import { Integration } from "../base/integration";
|
import { Integration } from "../base/integration";
|
||||||
@@ -7,7 +8,7 @@ export class HomeAssistantIntegration extends Integration {
|
|||||||
public async getEntityStateAsync(entityId: string) {
|
public async getEntityStateAsync(entityId: string) {
|
||||||
try {
|
try {
|
||||||
const response = await this.getAsync(`/api/states/${entityId}`);
|
const response = await this.getAsync(`/api/states/${entityId}`);
|
||||||
const body = (await response.json()) as unknown;
|
const body = await response.json();
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
logger.warn(`Response did not indicate success`);
|
logger.warn(`Response did not indicate success`);
|
||||||
return {
|
return {
|
||||||
@@ -71,7 +72,7 @@ export class HomeAssistantIntegration extends Integration {
|
|||||||
* @returns the response from the API
|
* @returns the response from the API
|
||||||
*/
|
*/
|
||||||
private async getAsync(path: `/api/${string}`) {
|
private async getAsync(path: `/api/${string}`) {
|
||||||
return await fetch(this.url(path), {
|
return await fetchWithTrustedCertificatesAsync(this.url(path), {
|
||||||
headers: this.getAuthHeaders(),
|
headers: this.getAuthHeaders(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -84,7 +85,7 @@ export class HomeAssistantIntegration extends Integration {
|
|||||||
* @returns the response from the API
|
* @returns the response from the API
|
||||||
*/
|
*/
|
||||||
private async postAsync(path: `/api/${string}`, body: Record<string, string>) {
|
private async postAsync(path: `/api/${string}`, body: Record<string, string>) {
|
||||||
return await fetch(this.url(path), {
|
return await fetchWithTrustedCertificatesAsync(this.url(path), {
|
||||||
headers: this.getAuthHeaders(),
|
headers: this.getAuthHeaders(),
|
||||||
body: JSON.stringify(body),
|
body: JSON.stringify(body),
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ import { Jellyfin } from "@jellyfin/sdk";
|
|||||||
import { getSessionApi } from "@jellyfin/sdk/lib/utils/api/session-api";
|
import { getSessionApi } from "@jellyfin/sdk/lib/utils/api/session-api";
|
||||||
import { getSystemApi } from "@jellyfin/sdk/lib/utils/api/system-api";
|
import { getSystemApi } from "@jellyfin/sdk/lib/utils/api/system-api";
|
||||||
|
|
||||||
|
import { createAxiosCertificateInstanceAsync } from "@homarr/certificates/server";
|
||||||
|
|
||||||
import { Integration } from "../base/integration";
|
import { Integration } from "../base/integration";
|
||||||
import type { StreamSession } from "../interfaces/media-server/session";
|
import type { StreamSession } from "../interfaces/media-server/session";
|
||||||
|
|
||||||
@@ -65,12 +67,13 @@ export class JellyfinIntegration extends Integration {
|
|||||||
* @returns An instance of Api that has been authenticated
|
* @returns An instance of Api that has been authenticated
|
||||||
*/
|
*/
|
||||||
private async getApiAsync() {
|
private async getApiAsync() {
|
||||||
|
const httpsAgent = await createAxiosCertificateInstanceAsync();
|
||||||
if (this.hasSecretValue("apiKey")) {
|
if (this.hasSecretValue("apiKey")) {
|
||||||
const apiKey = this.getSecretValue("apiKey");
|
const apiKey = this.getSecretValue("apiKey");
|
||||||
return this.jellyfin.createApi(this.url("/").toString(), apiKey);
|
return this.jellyfin.createApi(this.url("/").toString(), apiKey, httpsAgent);
|
||||||
}
|
}
|
||||||
|
|
||||||
const apiClient = this.jellyfin.createApi(this.url("/").toString());
|
const apiClient = this.jellyfin.createApi(this.url("/").toString(), undefined, httpsAgent);
|
||||||
// Authentication state is stored internally in the Api class, so now
|
// Authentication state is stored internally in the Api class, so now
|
||||||
// requests that require authentication can be made normally.
|
// requests that require authentication can be made normally.
|
||||||
// see https://typescript-sdk.jellyfin.org/#usage
|
// see https://typescript-sdk.jellyfin.org/#usage
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { fetchWithTrustedCertificatesAsync } from "@homarr/certificates/server";
|
||||||
import { logger } from "@homarr/log";
|
import { logger } from "@homarr/log";
|
||||||
import { z } from "@homarr/validation";
|
import { z } from "@homarr/validation";
|
||||||
|
|
||||||
@@ -8,7 +9,7 @@ export class LidarrIntegration extends MediaOrganizerIntegration {
|
|||||||
public async testConnectionAsync(): Promise<void> {
|
public async testConnectionAsync(): Promise<void> {
|
||||||
await super.handleTestConnectionResponseAsync({
|
await super.handleTestConnectionResponseAsync({
|
||||||
queryFunctionAsync: async () => {
|
queryFunctionAsync: async () => {
|
||||||
return await fetch(this.url("/api"), {
|
return await fetchWithTrustedCertificatesAsync(this.url("/api"), {
|
||||||
headers: { "X-Api-Key": super.getSecretValue("apiKey") },
|
headers: { "X-Api-Key": super.getSecretValue("apiKey") },
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -28,7 +29,7 @@ export class LidarrIntegration extends MediaOrganizerIntegration {
|
|||||||
unmonitored: includeUnmonitored,
|
unmonitored: includeUnmonitored,
|
||||||
});
|
});
|
||||||
|
|
||||||
const response = await fetch(url, {
|
const response = await fetchWithTrustedCertificatesAsync(url, {
|
||||||
headers: {
|
headers: {
|
||||||
"X-Api-Key": super.getSecretValue("apiKey"),
|
"X-Api-Key": super.getSecretValue("apiKey"),
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { fetchWithTrustedCertificatesAsync } from "@homarr/certificates/server";
|
||||||
import type { AtLeastOneOf } from "@homarr/common/types";
|
import type { AtLeastOneOf } from "@homarr/common/types";
|
||||||
import { logger } from "@homarr/log";
|
import { logger } from "@homarr/log";
|
||||||
import { z } from "@homarr/validation";
|
import { z } from "@homarr/validation";
|
||||||
@@ -20,7 +21,7 @@ export class RadarrIntegration extends MediaOrganizerIntegration {
|
|||||||
unmonitored: includeUnmonitored,
|
unmonitored: includeUnmonitored,
|
||||||
});
|
});
|
||||||
|
|
||||||
const response = await fetch(url, {
|
const response = await fetchWithTrustedCertificatesAsync(url, {
|
||||||
headers: {
|
headers: {
|
||||||
"X-Api-Key": super.getSecretValue("apiKey"),
|
"X-Api-Key": super.getSecretValue("apiKey"),
|
||||||
},
|
},
|
||||||
@@ -94,7 +95,7 @@ export class RadarrIntegration extends MediaOrganizerIntegration {
|
|||||||
public async testConnectionAsync(): Promise<void> {
|
public async testConnectionAsync(): Promise<void> {
|
||||||
await super.handleTestConnectionResponseAsync({
|
await super.handleTestConnectionResponseAsync({
|
||||||
queryFunctionAsync: async () => {
|
queryFunctionAsync: async () => {
|
||||||
return await fetch(this.url("/api"), {
|
return await fetchWithTrustedCertificatesAsync(this.url("/api"), {
|
||||||
headers: { "X-Api-Key": super.getSecretValue("apiKey") },
|
headers: { "X-Api-Key": super.getSecretValue("apiKey") },
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|||||||
Loaded 100 of 185 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user