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 { SortableAppShelfItem, AppShelfItem } from './AppShelfItem';
|
||||||
import { ModuleMenu, ModuleWrapper } from '../../modules/moduleWrapper';
|
import { ModuleMenu, ModuleWrapper } from '../../modules/moduleWrapper';
|
||||||
import { NzbModule, TorrentsModule } from '../../modules';
|
import { UsenetModule, TorrentsModule } from '../../modules';
|
||||||
import TorrentsComponent from '../../modules/torrents/TorrentsModule';
|
import TorrentsComponent from '../../modules/torrents/TorrentsModule';
|
||||||
|
|
||||||
const AppShelf = (props: any) => {
|
const AppShelf = (props: any) => {
|
||||||
@@ -184,7 +184,7 @@ const AppShelf = (props: any) => {
|
|||||||
<Stack>
|
<Stack>
|
||||||
{getItems()}
|
{getItems()}
|
||||||
<ModuleWrapper mt="xl" module={TorrentsModule} />
|
<ModuleWrapper mt="xl" module={TorrentsModule} />
|
||||||
<ModuleWrapper mt="xl" module={NzbModule} />
|
<ModuleWrapper mt="xl" module={UsenetModule} />
|
||||||
</Stack>
|
</Stack>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -7,4 +7,4 @@ export * from './search';
|
|||||||
export * from './weather';
|
export * from './weather';
|
||||||
export * from './docker';
|
export * from './docker';
|
||||||
export * from './overseerr';
|
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) =>
|
||||||
service.type === 'qBittorrent' ||
|
service.type === 'qBittorrent' ||
|
||||||
service.type === 'Transmission' ||
|
service.type === 'Transmission' ||
|
||||||
service.type === 'Deluge' ||
|
service.type === 'Deluge'
|
||||||
'Sabnzbd'
|
|
||||||
) ?? [];
|
) ?? [];
|
||||||
|
|
||||||
const [torrentHistory, torrentHistoryHandlers] = useListState<torrentHistory>([]);
|
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 { showNotification } from '@mantine/notifications';
|
||||||
import { IconDownload, IconPlayerPause, IconPlayerPlay } from '@tabler/icons';
|
import { IconDownload, IconPlayerPause, IconPlayerPlay } from '@tabler/icons';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
@@ -11,7 +21,7 @@ import { IModule } from '../ModuleTypes';
|
|||||||
|
|
||||||
dayjs.extend(duration);
|
dayjs.extend(duration);
|
||||||
|
|
||||||
export const NzbComponent: FunctionComponent = () => {
|
export const UsenetComponent: FunctionComponent = () => {
|
||||||
const [nzbs, setNzbs] = useState<DownloadItem[]>([]);
|
const [nzbs, setNzbs] = useState<DownloadItem[]>([]);
|
||||||
const [isLoading, setIsLoading] = useState(true);
|
const [isLoading, setIsLoading] = useState(true);
|
||||||
|
|
||||||
@@ -20,7 +30,7 @@ export const NzbComponent: FunctionComponent = () => {
|
|||||||
|
|
||||||
const getData = async () => {
|
const getData = async () => {
|
||||||
try {
|
try {
|
||||||
const response = await axios.get('/api/modules/nzbs');
|
const response = await axios.get('/api/modules/usenet');
|
||||||
setNzbs(response.data);
|
setNzbs(response.data);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setNzbs([]);
|
setNzbs([]);
|
||||||
@@ -38,7 +48,7 @@ export const NzbComponent: FunctionComponent = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const interval = setInterval(getData, 10000);
|
const interval = setInterval(getData, 5000);
|
||||||
getData();
|
getData();
|
||||||
|
|
||||||
() => {
|
() => {
|
||||||
@@ -112,6 +122,12 @@ export const NzbComponent: FunctionComponent = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<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%' }}>
|
<ScrollArea sx={{ maxHeight: 300, width: '100%' }}>
|
||||||
{rows.length > 0 ? (
|
{rows.length > 0 ? (
|
||||||
<Table highlightOnHover>
|
<Table highlightOnHover>
|
||||||
@@ -124,14 +140,16 @@ export const NzbComponent: FunctionComponent = () => {
|
|||||||
</Center>
|
</Center>
|
||||||
)}
|
)}
|
||||||
</ScrollArea>
|
</ScrollArea>
|
||||||
|
</Tabs.Panel>
|
||||||
|
</Tabs>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const NzbModule: IModule = {
|
export const UsenetModule: IModule = {
|
||||||
id: 'usenet',
|
id: 'usenet',
|
||||||
title: 'Usenet',
|
title: 'Usenet',
|
||||||
icon: IconDownload,
|
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 duration from 'dayjs/plugin/duration';
|
||||||
import { NextApiRequest, NextApiResponse } from 'next';
|
import { NextApiRequest, NextApiResponse } from 'next';
|
||||||
import { Client } from 'sabnzbd-api';
|
import { Client } from 'sabnzbd-api';
|
||||||
import { getConfig } from '../../../tools/getConfig';
|
import { UsenetQueueItem } from '../../../../modules';
|
||||||
import { Config, DownloadItem } from '../../../tools/types';
|
import { getConfig } from '../../../../tools/getConfig';
|
||||||
|
import { Config } from '../../../../tools/types';
|
||||||
|
|
||||||
dayjs.extend(duration);
|
dayjs.extend(duration);
|
||||||
|
|
||||||
@@ -14,7 +15,7 @@ async function Get(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
const { config }: { config: Config } = getConfig(configName?.toString() ?? 'default').props;
|
const { config }: { config: Config } = getConfig(configName?.toString() ?? 'default').props;
|
||||||
const nzbServices = config.services.filter((service) => service.type === 'Sabnzbd');
|
const nzbServices = config.services.filter((service) => service.type === 'Sabnzbd');
|
||||||
|
|
||||||
const downloads: DownloadItem[] = [];
|
const downloads: UsenetQueueItem[] = [];
|
||||||
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
nzbServices.map(async (service) => {
|
nzbServices.map(async (service) => {
|
||||||
@@ -188,12 +188,3 @@ export interface serviceItem {
|
|||||||
newTab?: boolean;
|
newTab?: boolean;
|
||||||
status?: string[];
|
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