Replace entire codebase with homarr-labs/homarr

This commit is contained in:
Thomas Camlong
2026-01-15 21:54:44 +01:00
parent c5bc3b1559
commit 4fdd1fe351
4666 changed files with 409577 additions and 147434 deletions

View File

@@ -0,0 +1,11 @@
import { max } from "drizzle-orm";
import type { HomarrDatabase } from "../driver";
import { groups } from "../schema";
export const getMaxGroupPositionAsync = async (db: HomarrDatabase) => {
return await db
.select({ value: max(groups.position) })
.from(groups)
.then((result) => result[0]?.value ?? 1);
};

View File

@@ -0,0 +1,3 @@
export * from "./item";
export * from "./server-setting";
export * from "./group";

View File

@@ -0,0 +1,48 @@
import type { WidgetKind } from "@homarr/definitions";
import type { Database } from "..";
import { inArray } from "..";
import type { inferSupportedIntegrations } from "../../widgets/src";
import { items } from "../schema";
export const getItemsWithIntegrationsAsync = async <TKind extends WidgetKind>(
db: Database,
{ kinds }: { kinds: TKind[] },
) => {
const itemsForIntegration = await db.query.items.findMany({
where: inArray(items.kind, kinds),
with: {
integrations: {
with: {
integration: {
with: {
app: true,
secrets: {
columns: {
kind: true,
value: true,
},
},
},
},
},
},
},
});
return itemsForIntegration.map((item) => ({
...item,
kind: item.kind as TKind,
integrations: item.integrations.map(({ integration, integrationId }) => {
const integrationWithSecrets = {
...integration,
kind: integration.kind as inferSupportedIntegrations<TKind>,
};
return {
integration: integrationWithSecrets,
integrationId,
};
}),
}));
};

View File

@@ -0,0 +1,63 @@
import SuperJSON from "superjson";
import type { ServerSettings } from "@homarr/server-settings";
import { defaultServerSettings, defaultServerSettingsKeys } from "@homarr/server-settings";
import type { Database } from "..";
import { eq } from "..";
import { serverSettings } from "../schema";
export const getServerSettingsAsync = async (db: Database) => {
const settings = await db.query.serverSettings.findMany();
return defaultServerSettingsKeys.reduce((acc, settingKey) => {
const setting = settings.find((setting) => setting.settingKey === settingKey);
if (!setting) {
// Typescript is not happy because the key is a union and it does not know that they are the same
acc[settingKey] = defaultServerSettings[settingKey] as never;
return acc;
}
acc[settingKey] = {
...defaultServerSettings[settingKey],
...SuperJSON.parse(setting.value),
};
return acc;
}, {} as ServerSettings);
};
export const getServerSettingByKeyAsync = async <TKey extends keyof ServerSettings>(db: Database, key: TKey) => {
const dbSettings = await db.query.serverSettings.findFirst({
where: eq(serverSettings.settingKey, key),
});
if (!dbSettings) {
return defaultServerSettings[key];
}
return SuperJSON.parse<ServerSettings[TKey]>(dbSettings.value);
};
export const updateServerSettingByKeyAsync = async <TKey extends keyof ServerSettings>(
db: Database,
key: TKey,
value: ServerSettings[TKey],
) => {
await db
.update(serverSettings)
.set({
value: SuperJSON.stringify(value),
})
.where(eq(serverSettings.settingKey, key));
};
export const insertServerSettingByKeyAsync = async <TKey extends keyof ServerSettings>(
db: Database,
key: TKey,
value: ServerSettings[TKey],
) => {
await db.insert(serverSettings).values({
settingKey: key,
value: SuperJSON.stringify(value),
});
};