Allow batch export. Close #179

This commit is contained in:
2025-02-08 18:23:49 +08:00
parent 35429c132c
commit f0b1135eb7
6 changed files with 189 additions and 135 deletions

View File

@@ -175,7 +175,7 @@ abstract class CBZ {
return comic;
}
static Future<File> export(LocalComic comic) async {
static Future<File> export(LocalComic comic, String outFilePath) async {
var cache = Directory(FilePath.join(App.cachePath, 'cbz_export'));
if (cache.existsSync()) cache.deleteSync(recursive: true);
cache.createSync();
@@ -234,7 +234,7 @@ abstract class CBZ {
).toJson(),
),
);
var cbz = File(FilePath.join(App.cachePath, sanitizeFileName('${comic.title}.cbz')));
var cbz = File(outFilePath);
if (cbz.existsSync()) cbz.deleteSync();
await _compress(cache.path, cbz.path);
cache.deleteSync(recursive: true);

View File

@@ -24,7 +24,8 @@ class EpubData {
});
}
Future<File> createEpubComic(EpubData data, String cacheDir) async {
Future<File> createEpubComic(
EpubData data, String cacheDir, String outFilePath) async {
final workingDir = Directory(FilePath.join(cacheDir, 'epub'));
if (workingDir.existsSync()) {
workingDir.deleteSync(recursive: true);
@@ -109,8 +110,7 @@ ${images.map((e) => ' <img src="$e" alt="$e"/>').join('\n')}
}
// content.opf
final contentOpf =
File(FilePath.join(workingDir.path, 'content.opf'));
final contentOpf = File(FilePath.join(workingDir.path, 'content.opf'));
final uuid = const Uuid().v4();
var spineStrBuilder = StringBuffer();
for (var i = 0; i < chapterIndex; i++) {
@@ -171,16 +171,15 @@ ${navMapStrBuilder.toString()}
</ncx>
''');
// zip
final zipPath = FilePath.join(cacheDir, '${data.title}.epub');
ZipFile.compressFolder(workingDir.path, zipPath);
ZipFile.compressFolder(workingDir.path, outFilePath);
workingDir.deleteSync(recursive: true);
return File(zipPath);
return File(outFilePath);
}
Future<File> createEpubWithLocalComic(LocalComic comic) async {
Future<File> createEpubWithLocalComic(
LocalComic comic, String outFilePath) async {
var chapters = <String, List<File>>{};
if (comic.chapters == null) {
chapters[comic.title] =
@@ -188,11 +187,11 @@ Future<File> createEpubWithLocalComic(LocalComic comic) async {
.map((e) => File(e))
.toList();
} else {
for (var chapter in comic.chapters!.keys) {
chapters[comic.chapters![chapter]!] = (await LocalManager()
.getImages(comic.id, comic.comicType, chapter))
.map((e) => File(e))
.toList();
for (var chapter in comic.downloadedChapters) {
chapters[comic.chapters![chapter]!] =
(await LocalManager().getImages(comic.id, comic.comicType, chapter))
.map((e) => File(e))
.toList();
}
}
var data = EpubData(
@@ -205,6 +204,6 @@ Future<File> createEpubWithLocalComic(LocalComic comic) async {
final cacheDir = App.cachePath;
return Isolate.run(() => overrideIO(() async {
return createEpubComic(data, cacheDir);
return createEpubComic(data, cacheDir, outFilePath);
}));
}

View File

@@ -49,7 +49,7 @@ Future<void> _createPdfFromComic({
images.add(file.path);
}
} else {
for (var chapter in comic.chapters!.keys) {
for (var chapter in comic.downloadedChapters) {
var files = Directory(FilePath.join(baseDir, chapter)).listSync();
reorderFiles(files);
for (var file in files) {
@@ -112,10 +112,7 @@ Future<Isolate> _runIsolate(
);
}
Future<void> createPdfFromComicIsolate({
required LocalComic comic,
required String savePath,
}) async {
Future<File> createPdfFromComicIsolate(LocalComic comic, String savePath) async {
var receivePort = ReceivePort();
SendPort? sendPort;
Isolate? isolate;
@@ -134,7 +131,8 @@ Future<void> createPdfFromComicIsolate({
}
});
isolate = await _runIsolate(comic, savePath, receivePort.sendPort);
return completer.future;
await completer.future;
return File(savePath);
}
class PdfGenerator {