From c246f0bc509b0ac08a839709d51d7c009c364009 Mon Sep 17 00:00:00 2001 From: jiayao Date: Thu, 6 Oct 2022 02:37:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=9B=BE=E5=83=8F=E4=B8=BA?= =?UTF-8?q?=E7=A9=BA=E6=97=B6=E7=A8=8B=E5=BA=8F=E6=8C=82=E8=B5=B7=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jiayaoO3O/finder/service/ComicService.java | 12 +++++++----- .../jiayaoO3O/finder/service/TaskService.java | 15 ++++++++------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/main/java/io/github/jiayaoO3O/finder/service/ComicService.java b/src/main/java/io/github/jiayaoO3O/finder/service/ComicService.java index 437f2121c..131786d50 100644 --- a/src/main/java/io/github/jiayaoO3O/finder/service/ComicService.java +++ b/src/main/java/io/github/jiayaoO3O/finder/service/ComicService.java @@ -76,7 +76,7 @@ private Consumer> photoEntitiesConsumer(ChapterEntity chapterE private Consumer photoExistsConsumer(ChapterEntity chapterEntity, PhotoEntity photoEntity, String photoPath) { return exists -> { if(exists) { - log.info("{}[{}]已存在, 跳过处理",taskService.clickPhotoCounter(false), photoPath); + log.info("{}[{}]已存在, 跳过处理", taskService.clickPhotoCounter(false), photoPath); } else { var bufferUni = taskService.processPhotoBuffer(photoEntity); bufferUni.subscribe() @@ -86,16 +86,18 @@ private Consumer photoExistsConsumer(ChapterEntity chapterEntity, Photo } private Consumer photoBufferConsumer(ChapterEntity chapterEntity, PhotoEntity photoEntity, String photoPath) { - return buffer -> taskService.processPhotoTempFile(buffer) + return buffer -> taskService.processPhotoTempFile(buffer, photoEntity) .subscribe() .with(this.tempFileConsumer(chapterEntity, photoEntity, photoPath)); } private Consumer tempFileConsumer(ChapterEntity chapterEntity, PhotoEntity photoEntity, String photoPath) { return path -> { - var bufferedImageUni = taskService.processPhotoReverse(path, chapterEntity, photoEntity); - bufferedImageUni.subscribe() - .with(this.finalImageConsumer(photoPath)); + if(StrUtil.isNotEmpty(path)) { + var bufferedImageUni = taskService.processPhotoReverse(path, chapterEntity, photoEntity); + bufferedImageUni.subscribe() + .with(this.finalImageConsumer(photoPath)); + } }; } diff --git a/src/main/java/io/github/jiayaoO3O/finder/service/TaskService.java b/src/main/java/io/github/jiayaoO3O/finder/service/TaskService.java index 8f2b1915e..fb577df16 100644 --- a/src/main/java/io/github/jiayaoO3O/finder/service/TaskService.java +++ b/src/main/java/io/github/jiayaoO3O/finder/service/TaskService.java @@ -8,9 +8,7 @@ import io.github.jiayaoO3O.finder.entity.PhotoEntity; import io.quarkus.runtime.Quarkus; import io.smallrye.common.constraint.NotNull; -import io.smallrye.mutiny.Multi; import io.smallrye.mutiny.Uni; -import io.smallrye.mutiny.tuples.Tuple2; import io.vertx.mutiny.core.Vertx; import io.vertx.mutiny.core.buffer.Buffer; import io.vertx.mutiny.ext.web.client.HttpResponse; @@ -158,8 +156,8 @@ public Uni processChapterDir(String title, ChapterEntity chapterEntity) .item(dirPath)); } - public Uni processPhotoExists(String photoPath){ - return vertx.fileSystem() + public Uni processPhotoExists(String photoPath) { + return vertx.fileSystem() .exists(photoPath); } @@ -170,16 +168,18 @@ public Uni processPhotoBuffer(PhotoEntity photoEntity) { .item(response.bodyAsBuffer())); } - public Uni processPhotoTempFile(Buffer buffer) { + public Uni processPhotoTempFile(Buffer buffer, PhotoEntity photoEntity) { if(buffer == null) { - log.info("buffer为null"); + log.info("{}[{}]对应buffer为null, 跳过处理", this.clickPhotoCounter(false), photoEntity.url()); + return Uni.createFrom() + .item(""); } var tempFile = vertx.fileSystem() .createTempFile(String.valueOf(System.nanoTime()), ".tmp"); var voidUni = tempFile.chain(path -> vertx.fileSystem() .writeFile(path, buffer) .onFailure() - .invoke(e -> log.error(StrUtil.format("保存文件:[{}]失败:[{}]", path, e.getLocalizedMessage()), e)) + .invoke(e -> log.error(StrUtil.format("保存文件:[{}]失败:[{}]", photoEntity.url(), e.getLocalizedMessage()), e)) .onItem() .transform(v -> path)); return voidUni; @@ -362,6 +362,7 @@ public void write(String path, BufferedImage bufferedImage) { log.error(StrUtil.format("{}保存文件失败:[{}][{}]", this.clickPhotoCounter(false), path, e.getLocalizedMessage()), e); } } + /** * @param body 网页的html内容. * @return 漫画的标题.