Merge pull request #171 from C9Glax/refresh-libraries

Refresh libraries setting
This commit is contained in:
2025-09-21 17:49:40 +02:00
committed by GitHub
4 changed files with 97 additions and 3 deletions

View File

@@ -0,0 +1,49 @@
import {ChangeEventHandler, ReactNode, useContext, useState} from 'react';
import {SettingsContext, SettingsItem} from './Settings.tsx';
import {ApiContext} from '../../contexts/ApiContext.tsx';
import TButton from "../Inputs/TButton.tsx";
import {LibraryRefreshSetting, PatchLibraryRefreshRecord} from "../../api/data-contracts.ts";
import {Input, Radio, RadioGroup, Typography} from "@mui/joy";
export default function LibraryRefresh(): ReactNode {
const settings = useContext(SettingsContext);
const [value, setValue] = useState<PatchLibraryRefreshRecord>({
setting: settings?.libraryRefreshSetting ?? LibraryRefreshSetting.AfterAllFinished,
refreshLibraryWhileDownloadingEveryMinutes: settings?.refreshLibraryWhileDownloadingEveryMinutes
});
const Api = useContext(ApiContext);
const updateSetting = async () => {
try {
const response = await Api.settingsLibraryRefreshPartialUpdate(value);
if (response.ok) return Promise.resolve();
else return Promise.reject();
} catch {
return await Promise.reject();
}
};
const onSettingChanged : ChangeEventHandler<HTMLInputElement> = (e) => {
setValue({...value, setting: LibraryRefreshSetting[e.target.value as keyof typeof LibraryRefreshSetting] });
}
const onMinutesChanged : ChangeEventHandler<HTMLInputElement> = (e) => {
setValue({...value, refreshLibraryWhileDownloadingEveryMinutes: e.target.valueAsNumber})
}
return (
<SettingsItem title={'Library Refresh'}>
<Typography level={"body-md"}>Refresh after</Typography>
<RadioGroup value={value.setting} onChange={onSettingChanged}>
{Object.keys(LibraryRefreshSetting).map(e => (
<Radio key={e} value={e} label={e} />
))}
</RadioGroup>
<Typography level={"body-md"}>When {LibraryRefreshSetting.WhileDownloading} refresh every x-minutes:</Typography>
<Input value={value.refreshLibraryWhileDownloadingEveryMinutes??undefined} onChange={onMinutesChanged} type={"number"} />
<TButton onClick={updateSetting}>Update</TButton>
</SettingsItem>
);
}

View File

@@ -8,7 +8,7 @@ import {
DialogContent,
DialogTitle,
Modal,
ModalDialog,
ModalDialog, Stack,
} from '@mui/joy';
import './Settings.css';
import * as React from 'react';
@@ -22,6 +22,7 @@ import Maintenance from './Maintenance.tsx';
import { ApiContext } from '../../contexts/ApiContext.tsx';
import { TrangaSettings } from '../../api/data-contracts.ts';
import TInput from '../Inputs/TInput.tsx';
import LibraryRefresh from "./LibraryRefresh.tsx";
export const SettingsContext = createContext<TrangaSettings | undefined>(undefined);
@@ -68,6 +69,7 @@ export default function Settings({ setApiUri }: { setApiUri: (uri: string) => vo
<DownloadLanguage />
<ChapterNamingScheme />
<Maintenance />
<LibraryRefresh />
</AccordionGroup>
</DialogContent>
</ModalDialog>
@@ -80,7 +82,11 @@ export function SettingsItem({ title, children }: { title: string; children: Rea
return (
<Accordion>
<AccordionSummary>{title}</AccordionSummary>
<AccordionDetails>{children}</AccordionDetails>
<AccordionDetails>
<Stack gap={1} direction="column">
{children}
</Stack>
</AccordionDetails>
</Accordion>
);
}

View File

@@ -29,6 +29,7 @@ import {
MetadataSearchResult,
MinimalManga,
NotificationConnector,
PatchLibraryRefreshRecord,
ProblemDetails,
RequestType,
TrangaSettings,
@@ -1201,6 +1202,25 @@ export class V2<SecurityDataType = unknown> extends HttpClient<SecurityDataType>
method: 'PATCH',
...params,
});
/**
* No description
*
* @tags Settings
* @name SettingsLibraryRefreshPartialUpdate
* @summary Sets the time when Libraries are refreshed
* @request PATCH:/v2/Settings/LibraryRefresh
*/
settingsLibraryRefreshPartialUpdate = (
data: PatchLibraryRefreshRecord,
params: RequestParams = {}
) =>
this.request<void, any>({
path: `/v2/Settings/LibraryRefresh`,
method: 'PATCH',
body: data,
type: ContentType.Json,
...params,
});
/**
* No description
*

View File

@@ -41,6 +41,13 @@ export enum LibraryType {
Kavita = 'Kavita',
}
export enum LibraryRefreshSetting {
AfterAllFinished = 'AfterAllFinished',
AfterMangaFinished = 'AfterMangaFinished',
AfterEveryChapter = 'AfterEveryChapter',
WhileDownloading = 'WhileDownloading',
}
export enum CoverSize {
Original = 'Original',
Large = 'Large',
@@ -463,6 +470,15 @@ export interface NotificationConnector {
key: string;
}
export interface PatchLibraryRefreshRecord {
setting: LibraryRefreshSetting;
/**
* When API.Workers.LibraryRefreshSetting.WhileDownloading is selected, update the time between refreshes
* @format int32
*/
refreshLibraryWhileDownloadingEveryMinutes?: number | null;
}
export interface ProblemDetails {
type?: string | null;
title?: string | null;
@@ -474,7 +490,7 @@ export interface ProblemDetails {
}
export interface TrangaSettings {
downloadLocation?: string | null;
defaultDownloadLocation?: string | null;
userAgent?: string | null;
/** @format int32 */
imageCompression?: number;
@@ -516,6 +532,9 @@ export interface TrangaSettings {
maxConcurrentDownloads?: number;
/** @format int32 */
maxConcurrentWorkers?: number;
libraryRefreshSetting?: LibraryRefreshSetting;
/** @format int32 */
refreshLibraryWhileDownloadingEveryMinutes?: number;
}
/** API.Workers.BaseWorker DTO */