-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
SeDemal
committed
Jul 31, 2024
1 parent
b65f3ae
commit e133977
Showing
45 changed files
with
2,384 additions
and
601 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
.itemCard { | ||
@mixin dark { | ||
background-color: rgba(46, 46, 46, var(--opacity)); | ||
border-color: rgba(66, 66, 66, var(--opacity)); | ||
--background-color: rgb(from var(--mantine-color-dark-6) r g b / var(--opacity)); | ||
--border-color: rgb(from var(--mantine-color-dark-4) r g b / var(--opacity)); | ||
} | ||
@mixin light { | ||
background-color: rgba(255, 255, 255, var(--opacity)); | ||
border-color: rgba(222, 226, 230, var(--opacity)); | ||
--background-color: rgb(from var(--mantine-color-white) r g b / var(--opacity)); | ||
--border-color: rgb(from var(--mantine-color-gray-3) r g b / var(--opacity)); | ||
} | ||
background-color: var(--background-color); | ||
border-color: var(--border-color); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
import { TRPCError } from "@trpc/server"; | ||
import { observable } from "@trpc/server/observable"; | ||
|
||
import type { IntegrationKind } from "@homarr/definitions"; | ||
import type { | ||
DownloadClientData, | ||
DownloadClientIntegration, | ||
IntegrationInput, | ||
SanitizedIntegration, | ||
} from "@homarr/integrations"; | ||
import { integrationCreatorByKind } from "@homarr/integrations"; | ||
import { createItemAndIntegrationChannel } from "@homarr/redis"; | ||
import { z } from "@homarr/validation"; | ||
|
||
import type { DownloadClientItem } from "../../../../integrations/src/interfaces/downloads/download-client-items"; | ||
import { createManyIntegrationMiddleware } from "../../middlewares/integration"; | ||
import { createTRPCRouter, publicProcedure } from "../../trpc"; | ||
|
||
export const downloadsRouter = createTRPCRouter({ | ||
getData: publicProcedure | ||
.unstable_concat( | ||
createManyIntegrationMiddleware("query", "sabNzbd", "nzbGet", "qBittorrent", "deluge", "transmission"), | ||
) | ||
.query(async ({ ctx }) => { | ||
return await Promise.all( | ||
ctx.integrations.map(async ({ decryptedSecrets: _, ...integration }) => { | ||
const channel = createItemAndIntegrationChannel<DownloadClientData>("downloads", integration.id); | ||
const data = await channel.getAsync(); | ||
return { | ||
integration: integration as SanitizedIntegration, | ||
data: data?.data ?? ({} as DownloadClientData), | ||
}; | ||
}), | ||
); | ||
}), | ||
subscribeToData: publicProcedure | ||
.unstable_concat( | ||
createManyIntegrationMiddleware("query", "sabNzbd", "nzbGet", "qBittorrent", "deluge", "transmission"), | ||
) | ||
.subscription(({ ctx }) => { | ||
return observable<{ integration: SanitizedIntegration; data: DownloadClientData }>((emit) => { | ||
const unsubscribes: (() => void)[] = []; | ||
for (const integrationWithSecrets of ctx.integrations) { | ||
const { decryptedSecrets: _, ...integration } = integrationWithSecrets; | ||
const channel = createItemAndIntegrationChannel<DownloadClientData>("downloads", integration.id); | ||
const unsubscribe = channel.subscribe((sessions) => { | ||
emit.next({ | ||
integration: integration as SanitizedIntegration, | ||
data: sessions, | ||
}); | ||
}); | ||
unsubscribes.push(unsubscribe); | ||
} | ||
return () => { | ||
unsubscribes.forEach((unsubscribe) => { | ||
unsubscribe(); | ||
}); | ||
}; | ||
}); | ||
}), | ||
pause: publicProcedure | ||
.unstable_concat( | ||
createManyIntegrationMiddleware("interact", "sabNzbd", "nzbGet", "qBittorrent", "deluge", "transmission"), | ||
) | ||
.mutation(async ({ ctx }) => { | ||
await Promise.all( | ||
ctx.integrations.map(async (integration) => { | ||
const integrationInstance = getIntegrationInstance(integration.kind, integration); | ||
await integrationInstance.pauseQueueAsync(); | ||
}), | ||
); | ||
}), | ||
pauseItem: publicProcedure | ||
.unstable_concat( | ||
createManyIntegrationMiddleware("interact", "sabNzbd", "nzbGet", "qBittorrent", "deluge", "transmission"), | ||
) | ||
.input(z.object({ item: z.any() satisfies z.ZodType<DownloadClientItem> })) | ||
.mutation(async ({ ctx, input }) => { | ||
await Promise.all( | ||
ctx.integrations.map(async (integration) => { | ||
const integrationInstance = getIntegrationInstance(integration.kind, integration); | ||
await integrationInstance.pauseItemAsync(input.item as DownloadClientItem); | ||
}), | ||
); | ||
}), | ||
resume: publicProcedure | ||
.unstable_concat( | ||
createManyIntegrationMiddleware("interact", "sabNzbd", "nzbGet", "qBittorrent", "deluge", "transmission"), | ||
) | ||
.mutation(async ({ ctx }) => { | ||
await Promise.all( | ||
ctx.integrations.map(async (integration) => { | ||
const integrationInstance = getIntegrationInstance(integration.kind, integration); | ||
await integrationInstance.resumeQueueAsync(); | ||
}), | ||
); | ||
}), | ||
resumeItem: publicProcedure | ||
.unstable_concat( | ||
createManyIntegrationMiddleware("interact", "sabNzbd", "nzbGet", "qBittorrent", "deluge", "transmission"), | ||
) | ||
.input(z.object({ item: z.any() satisfies z.ZodType<DownloadClientItem> })) | ||
.mutation(async ({ ctx, input }) => { | ||
await Promise.all( | ||
ctx.integrations.map(async (integration) => { | ||
const integrationInstance = getIntegrationInstance(integration.kind, integration); | ||
await integrationInstance.resumeItemAsync(input.item as DownloadClientItem); | ||
}), | ||
); | ||
}), | ||
deleteItem: publicProcedure | ||
.unstable_concat( | ||
createManyIntegrationMiddleware("interact", "sabNzbd", "nzbGet", "qBittorrent", "deluge", "transmission"), | ||
) | ||
.input(z.object({ item: z.any() satisfies z.ZodType<DownloadClientItem>, fromDisk: z.boolean() })) | ||
.mutation(async ({ ctx, input }) => { | ||
await Promise.all( | ||
ctx.integrations.map(async (integration) => { | ||
const integrationInstance = getIntegrationInstance(integration.kind, integration); | ||
await integrationInstance.deleteItemAsync(input.item as DownloadClientItem, input.fromDisk); | ||
}), | ||
); | ||
}), | ||
}); | ||
|
||
function getIntegrationInstance(kind: IntegrationKind, integration: IntegrationInput): DownloadClientIntegration { | ||
switch (kind) { | ||
case "sabNzbd": | ||
case "nzbGet": | ||
case "qBittorrent": | ||
case "deluge": | ||
case "transmission": | ||
return integrationCreatorByKind(kind, integration) as DownloadClientIntegration; | ||
default: | ||
throw new TRPCError({ | ||
code: "BAD_REQUEST", | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.