2026-05-16 02:23:36 +02:00
|
|
|
/*
|
|
|
|
|
* 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/.
|
|
|
|
|
*/
|
|
|
|
|
|
2026-05-16 02:35:25 +02:00
|
|
|
import type { MigratableEntry, TMigrationEntry } from '@/features/migration/Migration.types.ts';
|
|
|
|
|
import { MigrationEntryStatus } from '@/features/migration/Migration.types.ts';
|
2026-05-16 02:23:36 +02:00
|
|
|
|
|
|
|
|
export class MigrationEntries {
|
2026-05-22 12:12:00 +02:00
|
|
|
public static isSearching(entry: TMigrationEntry): boolean {
|
|
|
|
|
return [MigrationEntryStatus.PENDING, MigrationEntryStatus.SEARCHING].includes(entry.status);
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-16 02:23:36 +02:00
|
|
|
public static getExcluded(entries: TMigrationEntry[]): TMigrationEntry[] {
|
|
|
|
|
return entries.filter((entry) => entry.isExcluded);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static getHaveStatus(entries: TMigrationEntry[], ...statuses: MigrationEntryStatus[]): TMigrationEntry[] {
|
|
|
|
|
return entries.filter((entry) => statuses.includes(entry.status));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static getHaveStatusSorted(
|
|
|
|
|
entries: TMigrationEntry[],
|
|
|
|
|
...statuses: MigrationEntryStatus[]
|
|
|
|
|
): TMigrationEntry[] {
|
|
|
|
|
return MigrationEntries.getHaveStatus(entries, ...statuses).toSorted((a, b) =>
|
|
|
|
|
a.mangaTitle.localeCompare(b.mangaTitle),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static getActiveEntriesSorted(
|
|
|
|
|
entries: TMigrationEntry[],
|
|
|
|
|
activeStatus: MigrationEntryStatus,
|
|
|
|
|
...statuses: MigrationEntryStatus[]
|
|
|
|
|
): TMigrationEntry[] {
|
|
|
|
|
return MigrationEntries.getHaveStatus(entries, ...statuses).toSorted((a, b) => {
|
|
|
|
|
if (a.status === activeStatus && b.status !== activeStatus) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (a.status !== activeStatus && b.status === activeStatus) {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return a.mangaTitle.localeCompare(b.mangaTitle);
|
|
|
|
|
});
|
|
|
|
|
}
|
2026-05-16 02:35:25 +02:00
|
|
|
|
|
|
|
|
public static getMigratable(entries: TMigrationEntry[]): MigratableEntry[] {
|
|
|
|
|
return Object.values(entries).filter(
|
|
|
|
|
(entry): entry is MigratableEntry =>
|
|
|
|
|
[MigrationEntryStatus.SEARCH_COMPLETE, MigrationEntryStatus.MIGRATING].includes(entry.status) &&
|
|
|
|
|
!entry.isExcluded &&
|
|
|
|
|
entry.selectedMatchMangaId != null &&
|
|
|
|
|
entry.selectedMatchSourceId != null,
|
|
|
|
|
);
|
|
|
|
|
}
|
2026-05-16 02:23:36 +02:00
|
|
|
}
|