Skip to content

Commit

Permalink
Merge pull request #125 from john180/dev
Browse files Browse the repository at this point in the history
修正okhttp的ResponseBody没有close的问题
  • Loading branch information
john180 authored Aug 18, 2023
2 parents b151d5c + 4f2b9f9 commit 3b8c20e
Showing 1 changed file with 20 additions and 25 deletions.
45 changes: 20 additions & 25 deletions src/main/java/plus/maa/backend/service/ArkLevelService.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,32 +173,27 @@ public void onFailure(@NotNull Call call, @NotNull IOException e) {

@Override
public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
if (!response.isSuccessful()) {
task.fail();
log.error("[LEVEL]下载地图数据失败:" + tree.getPath());
return;
try (ResponseBody rspBody = response.body()) {
if (!response.isSuccessful()) {
task.fail();
log.error("[LEVEL]下载地图数据失败:" + tree.getPath());
return;
}
ArkTilePos tilePos = mapper.readValue(rspBody.string(), ArkTilePos.class);
ArkLevel level = parserService.parseLevel(tilePos, tree.getSha());
if (level == null) {
task.fail();
log.info("[LEVEL]地图数据解析失败:" + tree.getPath());
return;
} else if (level == ArkLevel.EMPTY) {
task.pass();
return;
}
arkLevelRepo.save(level);

task.success();
log.info("[LEVEL]下载地图数据 {} 成功, 进度{}/{}, 用时:{}s", tilePos.getName(), task.getCurrent(), task.getTotal(), task.getDuration());
}
ResponseBody body = response.body();
if (body == null) {
task.fail();
log.error("[LEVEL]下载地图数据失败:" + tree.getPath());
return;
}
ArkTilePos tilePos = mapper.readValue(body.string(), ArkTilePos.class);

ArkLevel level = parserService.parseLevel(tilePos, tree.getSha());
if (level == null) {
task.fail();
log.info("[LEVEL]地图数据解析失败:" + tree.getPath());
return;
} else if (level == ArkLevel.EMPTY) {
task.pass();
return;
}
arkLevelRepo.save(level);

task.success();
log.info("[LEVEL]下载地图数据 {} 成功, 进度{}/{}, 用时:{}s", tilePos.getName(), task.getCurrent(), task.getTotal(), task.getDuration());
}
});
}
Expand Down

0 comments on commit 3b8c20e

Please sign in to comment.