mirror of
https://github.com/ajnart/homarr.git
synced 2025-11-10 15:35:55 +01:00
Cleanup
This commit is contained in:
@@ -16,7 +16,7 @@ import { useConfig } from '../../tools/state';
|
||||
|
||||
import { SortableAppShelfItem, AppShelfItem } from './AppShelfItem';
|
||||
import { ModuleMenu, ModuleWrapper } from '../../modules/moduleWrapper';
|
||||
import { NzbModule, TorrentsModule } from '../../modules';
|
||||
import { UsenetModule, TorrentsModule } from '../../modules';
|
||||
import TorrentsComponent from '../../modules/torrents/TorrentsModule';
|
||||
|
||||
const AppShelf = (props: any) => {
|
||||
@@ -184,7 +184,7 @@ const AppShelf = (props: any) => {
|
||||
<Stack>
|
||||
{getItems()}
|
||||
<ModuleWrapper mt="xl" module={TorrentsModule} />
|
||||
<ModuleWrapper mt="xl" module={NzbModule} />
|
||||
<ModuleWrapper mt="xl" module={UsenetModule} />
|
||||
</Stack>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -7,4 +7,4 @@ export * from './search';
|
||||
export * from './weather';
|
||||
export * from './docker';
|
||||
export * from './overseerr';
|
||||
export * from './nzb';
|
||||
export * from './usenet';
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
export { NzbModule } from './NzbModule';
|
||||
@@ -34,8 +34,7 @@ export default function TotalDownloadsComponent() {
|
||||
(service) =>
|
||||
service.type === 'qBittorrent' ||
|
||||
service.type === 'Transmission' ||
|
||||
service.type === 'Deluge' ||
|
||||
'Sabnzbd'
|
||||
service.type === 'Deluge'
|
||||
) ?? [];
|
||||
|
||||
const [torrentHistory, torrentHistoryHandlers] = useListState<torrentHistory>([]);
|
||||
|
||||
@@ -1,4 +1,14 @@
|
||||
import { Center, Progress, ScrollArea, Skeleton, Table, Text, Title, Tooltip } from '@mantine/core';
|
||||
import {
|
||||
Center,
|
||||
Progress,
|
||||
ScrollArea,
|
||||
Skeleton,
|
||||
Table,
|
||||
Tabs,
|
||||
Text,
|
||||
Title,
|
||||
Tooltip,
|
||||
} from '@mantine/core';
|
||||
import { showNotification } from '@mantine/notifications';
|
||||
import { IconDownload, IconPlayerPause, IconPlayerPlay } from '@tabler/icons';
|
||||
import axios from 'axios';
|
||||
@@ -11,7 +21,7 @@ import { IModule } from '../ModuleTypes';
|
||||
|
||||
dayjs.extend(duration);
|
||||
|
||||
export const NzbComponent: FunctionComponent = () => {
|
||||
export const UsenetComponent: FunctionComponent = () => {
|
||||
const [nzbs, setNzbs] = useState<DownloadItem[]>([]);
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
|
||||
@@ -20,7 +30,7 @@ export const NzbComponent: FunctionComponent = () => {
|
||||
|
||||
const getData = async () => {
|
||||
try {
|
||||
const response = await axios.get('/api/modules/nzbs');
|
||||
const response = await axios.get('/api/modules/usenet');
|
||||
setNzbs(response.data);
|
||||
} catch (error) {
|
||||
setNzbs([]);
|
||||
@@ -38,7 +48,7 @@ export const NzbComponent: FunctionComponent = () => {
|
||||
}
|
||||
};
|
||||
|
||||
const interval = setInterval(getData, 10000);
|
||||
const interval = setInterval(getData, 5000);
|
||||
getData();
|
||||
|
||||
() => {
|
||||
@@ -112,26 +122,34 @@ export const NzbComponent: FunctionComponent = () => {
|
||||
}
|
||||
|
||||
return (
|
||||
<ScrollArea sx={{ maxHeight: 300, width: '100%' }}>
|
||||
{rows.length > 0 ? (
|
||||
<Table highlightOnHover>
|
||||
<thead>{ths}</thead>
|
||||
<tbody>{rows}</tbody>
|
||||
</Table>
|
||||
) : (
|
||||
<Center style={{ display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
|
||||
<Title order={3}>Queue is empty</Title>
|
||||
</Center>
|
||||
)}
|
||||
</ScrollArea>
|
||||
<Tabs defaultValue="queue">
|
||||
<Tabs.List>
|
||||
<Tabs.Tab value="queue">Queue</Tabs.Tab>
|
||||
<Tabs.Tab value="history">History</Tabs.Tab>
|
||||
</Tabs.List>
|
||||
<Tabs.Panel value="queue">
|
||||
<ScrollArea sx={{ maxHeight: 300, width: '100%' }}>
|
||||
{rows.length > 0 ? (
|
||||
<Table highlightOnHover>
|
||||
<thead>{ths}</thead>
|
||||
<tbody>{rows}</tbody>
|
||||
</Table>
|
||||
) : (
|
||||
<Center style={{ display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
|
||||
<Title order={3}>Queue is empty</Title>
|
||||
</Center>
|
||||
)}
|
||||
</ScrollArea>
|
||||
</Tabs.Panel>
|
||||
</Tabs>
|
||||
);
|
||||
};
|
||||
|
||||
export const NzbModule: IModule = {
|
||||
export const UsenetModule: IModule = {
|
||||
id: 'usenet',
|
||||
title: 'Usenet',
|
||||
icon: IconDownload,
|
||||
component: NzbComponent,
|
||||
component: UsenetComponent,
|
||||
};
|
||||
|
||||
export default NzbComponent;
|
||||
export default UsenetComponent;
|
||||
2
src/modules/usenet/index.ts
Normal file
2
src/modules/usenet/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export { UsenetModule } from './UsenetModule';
|
||||
export * from './types';
|
||||
13
src/modules/usenet/types.ts
Normal file
13
src/modules/usenet/types.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
export interface UsenetQueueItem {
|
||||
name: string;
|
||||
progress: number;
|
||||
size: number;
|
||||
id: string;
|
||||
state: 'paused' | 'downloading' | 'queued';
|
||||
eta: number;
|
||||
}
|
||||
export interface UsenetHistoryItem {
|
||||
name: string;
|
||||
size: number;
|
||||
id: string;
|
||||
}
|
||||
52
src/pages/api/modules/usenet/history.ts
Normal file
52
src/pages/api/modules/usenet/history.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import { getCookie } from 'cookies-next';
|
||||
import dayjs from 'dayjs';
|
||||
import duration from 'dayjs/plugin/duration';
|
||||
import { NextApiRequest, NextApiResponse } from 'next';
|
||||
import { Client } from 'sabnzbd-api';
|
||||
import { UsenetHistoryItem } from '../../../../modules';
|
||||
import { getConfig } from '../../../../tools/getConfig';
|
||||
import { Config } from '../../../../tools/types';
|
||||
|
||||
dayjs.extend(duration);
|
||||
|
||||
async function Get(req: NextApiRequest, res: NextApiResponse) {
|
||||
try {
|
||||
const configName = getCookie('config-name', { req });
|
||||
const { config }: { config: Config } = getConfig(configName?.toString() ?? 'default').props;
|
||||
const nzbServices = config.services.filter((service) => service.type === 'Sabnzbd');
|
||||
|
||||
const history: UsenetHistoryItem[] = [];
|
||||
|
||||
await Promise.all(
|
||||
nzbServices.map(async (service) => {
|
||||
if (!service.apiKey) {
|
||||
throw new Error(`API Key for service "${service.name}" is missing`);
|
||||
}
|
||||
const queue = await new Client(service.url, service.apiKey).history();
|
||||
|
||||
queue.slots.forEach((slot) => {
|
||||
history.push({
|
||||
id: slot.nzo_id,
|
||||
name: slot.name,
|
||||
size: slot.bytes * 1000,
|
||||
});
|
||||
});
|
||||
})
|
||||
);
|
||||
|
||||
return res.status(200).json(history);
|
||||
} catch (err) {
|
||||
return res.status(401).json(err);
|
||||
}
|
||||
}
|
||||
|
||||
export default async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
// Filter out if the reuqest is a POST or a GET
|
||||
if (req.method === 'GET') {
|
||||
return Get(req, res);
|
||||
}
|
||||
return res.status(405).json({
|
||||
statusCode: 405,
|
||||
message: 'Method not allowed',
|
||||
});
|
||||
};
|
||||
@@ -3,8 +3,9 @@ import dayjs from 'dayjs';
|
||||
import duration from 'dayjs/plugin/duration';
|
||||
import { NextApiRequest, NextApiResponse } from 'next';
|
||||
import { Client } from 'sabnzbd-api';
|
||||
import { getConfig } from '../../../tools/getConfig';
|
||||
import { Config, DownloadItem } from '../../../tools/types';
|
||||
import { UsenetQueueItem } from '../../../../modules';
|
||||
import { getConfig } from '../../../../tools/getConfig';
|
||||
import { Config } from '../../../../tools/types';
|
||||
|
||||
dayjs.extend(duration);
|
||||
|
||||
@@ -14,7 +15,7 @@ async function Get(req: NextApiRequest, res: NextApiResponse) {
|
||||
const { config }: { config: Config } = getConfig(configName?.toString() ?? 'default').props;
|
||||
const nzbServices = config.services.filter((service) => service.type === 'Sabnzbd');
|
||||
|
||||
const downloads: DownloadItem[] = [];
|
||||
const downloads: UsenetQueueItem[] = [];
|
||||
|
||||
await Promise.all(
|
||||
nzbServices.map(async (service) => {
|
||||
@@ -188,12 +188,3 @@ export interface serviceItem {
|
||||
newTab?: boolean;
|
||||
status?: string[];
|
||||
}
|
||||
|
||||
export interface DownloadItem {
|
||||
name: string;
|
||||
progress: number;
|
||||
size: number;
|
||||
id: string;
|
||||
state: 'paused' | 'downloading' | 'queued';
|
||||
eta: number;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user