Skip to content

Commit

Permalink
修复图像为空时程序挂起问题
Browse files Browse the repository at this point in the history
  • Loading branch information
jiayaoO3O committed Oct 5, 2022
1 parent 7237237 commit c246f0b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private Consumer<List<PhotoEntity>> photoEntitiesConsumer(ChapterEntity chapterE
private Consumer<Boolean> 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()
Expand All @@ -86,16 +86,18 @@ private Consumer<Boolean> photoExistsConsumer(ChapterEntity chapterEntity, Photo
}

private Consumer<Buffer> 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<String> 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));
}
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -158,8 +156,8 @@ public Uni<String> processChapterDir(String title, ChapterEntity chapterEntity)
.item(dirPath));
}

public Uni<Boolean> processPhotoExists(String photoPath){
return vertx.fileSystem()
public Uni<Boolean> processPhotoExists(String photoPath) {
return vertx.fileSystem()
.exists(photoPath);
}

Expand All @@ -170,16 +168,18 @@ public Uni<Buffer> processPhotoBuffer(PhotoEntity photoEntity) {
.item(response.bodyAsBuffer()));
}

public Uni<String> processPhotoTempFile(Buffer buffer) {
public Uni<String> 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;
Expand Down Expand Up @@ -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 漫画的标题.
Expand Down

0 comments on commit c246f0b

Please sign in to comment.