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 14:13:56 +02:00
|
|
|
public static isAbortable(entry: TMigrationEntry): boolean {
|
|
|
|
|
return (
|
|
|
|
|
MigrationEntries.isSearching(entry) ||
|
|
|
|
|
MigrationEntries.hasStatus(entry, MigrationEntryStatus.MIGRATION_PENDING)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-22 12:12:00 +02:00
|
|
|
public static isSearching(entry: TMigrationEntry): boolean {
|
2026-05-22 14:13:56 +02:00
|
|
|
return MigrationEntries.hasStatus(entry, MigrationEntryStatus.SEARCH_PENDING, MigrationEntryStatus.SEARCHING);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static isMigrating(entry: TMigrationEntry): boolean {
|
|
|
|
|
return MigrationEntries.hasStatus(
|
|
|
|
|
entry,
|
|
|
|
|
MigrationEntryStatus.MIGRATION_PENDING,
|
|
|
|
|
MigrationEntryStatus.MIGRATING,
|
|
|
|
|
);
|
2026-05-22 12:12:00 +02:00
|
|
|
}
|
|
|
|
|
|
2026-05-16 02:23:36 +02:00
|
|
|
public static getExcluded(entries: TMigrationEntry[]): TMigrationEntry[] {
|
|
|
|
|
return entries.filter((entry) => entry.isExcluded);
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-22 14:13:56 +02:00
|
|
|
public static hasStatus(entry: TMigrationEntry, ...statuses: MigrationEntryStatus[]): boolean {
|
|
|
|
|
return statuses.includes(entry.status);
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-16 02:23:36 +02:00
|
|
|
public static getHaveStatus(entries: TMigrationEntry[], ...statuses: MigrationEntryStatus[]): TMigrationEntry[] {
|
2026-05-22 14:13:56 +02:00
|
|
|
return entries.filter((entry) => MigrationEntries.hasStatus(entry, ...statuses));
|
2026-05-16 02:23:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 =>
|
2026-05-22 14:22:01 +02:00
|
|
|
MigrationEntries.hasStatus(
|
|
|
|
|
entry,
|
|
|
|
|
MigrationEntryStatus.SEARCH_COMPLETE,
|
2026-05-22 14:13:56 +02:00
|
|
|
MigrationEntryStatus.MIGRATION_PENDING,
|
2026-05-22 14:22:01 +02:00
|
|
|
MigrationEntryStatus.MIGRATING,
|
|
|
|
|
) &&
|
2026-05-16 02:35:25 +02:00
|
|
|
!entry.isExcluded &&
|
|
|
|
|
entry.selectedMatchMangaId != null &&
|
|
|
|
|
entry.selectedMatchSourceId != null,
|
|
|
|
|
);
|
|
|
|
|
}
|
2026-05-16 02:23:36 +02:00
|
|
|
}
|