* Trigger download ahead while reading client side * Trigger download ahead while reading earlier Download ahead was only triggered once the chapter got marked as read * Optionally ignore dupe chapters for download ahead * Consider current chapters scanlator for dupe check * Update download ahead related settings - add new metadata setting for download ahead limit - previous setting - rename - update usage (auto download new chapters limit) * Select chapter to auto delete while reading depending on ignore dupe setting Currently, the n-th to last chapter always got deleted ignoring if "ignore dupes" setting was enabled or not. * Only auto delete chapter while reading if it is read In case not the last read but the n-th to last read chapter should get auto deleted while reading, it currently just got deleted ignoring if it has been read or not.
52 lines
1.8 KiB
TypeScript
52 lines
1.8 KiB
TypeScript
/*
|
|
* Copyright (C) Contributors to the Suwayomi project
|
|
*
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
*/
|
|
|
|
import { Metadata, MetadataServerSettings } from '@/typings';
|
|
import { requestManager } from '@/lib/requests/RequestManager.ts';
|
|
import { convertFromGqlMeta, getMetadataFrom } from '@/util/metadata';
|
|
|
|
export const getDefaultSettings = (): MetadataServerSettings => ({
|
|
// downloads
|
|
deleteChaptersManuallyMarkedRead: false,
|
|
deleteChaptersWhileReading: 0,
|
|
deleteChaptersWithBookmark: false,
|
|
downloadAheadLimit: 0,
|
|
|
|
// library
|
|
showAddToLibraryCategorySelectDialog: true,
|
|
ignoreFilters: false,
|
|
});
|
|
|
|
const getMetadataServerSettingsWithDefaultFallback = (
|
|
meta?: Metadata,
|
|
defaultSettings: MetadataServerSettings = getDefaultSettings(),
|
|
applyMetadataMigration: boolean = true,
|
|
): MetadataServerSettings => getMetadataFrom({ meta }, defaultSettings, applyMetadataMigration);
|
|
export const useMetadataServerSettings = (): {
|
|
metadata?: Metadata;
|
|
settings: MetadataServerSettings;
|
|
loading: boolean;
|
|
} => {
|
|
const { data, loading } = requestManager.useGetGlobalMeta();
|
|
const metadata = convertFromGqlMeta(data?.metas.nodes);
|
|
const settings = getMetadataServerSettingsWithDefaultFallback(metadata);
|
|
|
|
return { metadata, settings, loading };
|
|
};
|
|
|
|
export const getMetadataServerSettings = async (): Promise<MetadataServerSettings> => {
|
|
const { data, error } = await requestManager.getGlobalMeta().response;
|
|
|
|
if (error) {
|
|
throw error;
|
|
}
|
|
|
|
const metadata = convertFromGqlMeta(data?.metas.nodes);
|
|
return getMetadataServerSettingsWithDefaultFallback(metadata);
|
|
};
|