mirror of
https://github.com/LamGC/ContentGrabbingJi.git
synced 2025-04-30 06:37:36 +00:00
[Fix] PixivDownload 修复因排行榜总量的不确定导致排行榜获取异常的问题;
[Change] BotEventHandler 调整事件处理完成后的日志输出形式;
This commit is contained in:
parent
a28cb142b4
commit
15af939c3f
@ -188,7 +188,7 @@ public class BotEventHandler implements EventHandler {
|
|||||||
log.error("执行命令时发生异常", e);
|
log.error("执行命令时发生异常", e);
|
||||||
result = "命令执行时发生错误,无法完成!";
|
result = "命令执行时发生错误,无法完成!";
|
||||||
}
|
}
|
||||||
log.info("命令处理完成.(耗时: {}ms)", System.currentTimeMillis() - time);
|
long processTime = System.currentTimeMillis() - time;
|
||||||
if(Objects.requireNonNull(result) instanceof String) {
|
if(Objects.requireNonNull(result) instanceof String) {
|
||||||
try {
|
try {
|
||||||
event.sendMessage((String) result);
|
event.sendMessage((String) result);
|
||||||
@ -196,7 +196,10 @@ public class BotEventHandler implements EventHandler {
|
|||||||
log.error("发送消息时发生异常", e);
|
log.error("发送消息时发生异常", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.info("命令反馈完成.(耗时: {}ms)", System.currentTimeMillis() - time);
|
long totalTime = System.currentTimeMillis() - time;
|
||||||
|
log.info("命令反馈完成.(事件耗时: {}ms, P: {}%({}ms), R: {}%({}ms))", totalTime,
|
||||||
|
String.format("%.3f", ((double) processTime / (double)totalTime) * 100F), processTime,
|
||||||
|
String.format("%.3f", ((double) (totalTime - processTime) / (double)totalTime) * 100F), totalTime - processTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -285,7 +285,8 @@ public class PixivDownload {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取排行榜
|
* 获取排行榜.
|
||||||
|
* <p>注意: 如果范围实际上没超出, 但返回排行榜不足, 会导致与实际请求的数量不符, 需要检查</p>
|
||||||
* @param contentType 排行榜类型
|
* @param contentType 排行榜类型
|
||||||
* @param mode 排行榜模式
|
* @param mode 排行榜模式
|
||||||
* @param time 查询时间
|
* @param time 查询时间
|
||||||
@ -316,7 +317,8 @@ public class PixivDownload {
|
|||||||
int count = 0;
|
int count = 0;
|
||||||
Gson gson = new Gson();
|
Gson gson = new Gson();
|
||||||
ArrayList<JsonObject> results = new ArrayList<>(range);
|
ArrayList<JsonObject> results = new ArrayList<>(range);
|
||||||
for (int pageIndex = startPages; pageIndex <= endPages && count < range; pageIndex++) {
|
boolean canNext = true;
|
||||||
|
for (int pageIndex = startPages; canNext && pageIndex <= endPages && count < range; pageIndex++) {
|
||||||
HttpGet request = createHttpGetRequest(PixivURL.getRankingLink(contentType, mode, time, pageIndex, true));
|
HttpGet request = createHttpGetRequest(PixivURL.getRankingLink(contentType, mode, time, pageIndex, true));
|
||||||
log.debug("RequestUri: {}", request.getURI());
|
log.debug("RequestUri: {}", request.getURI());
|
||||||
HttpResponse response = httpClient.execute(request);
|
HttpResponse response = httpClient.execute(request);
|
||||||
@ -326,10 +328,13 @@ public class PixivDownload {
|
|||||||
throw new IOException("Http Response Error: '" + response.getStatusLine() + "', ResponseBody: '" + responseBody + '\'');
|
throw new IOException("Http Response Error: '" + response.getStatusLine() + "', ResponseBody: '" + responseBody + '\'');
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonArray resultArray = gson.fromJson(responseBody, JsonObject.class).getAsJsonArray("contents");
|
JsonObject resultObject = gson.fromJson(responseBody, JsonObject.class);
|
||||||
|
canNext = resultObject.get("next").getAsJsonPrimitive().isNumber();
|
||||||
|
JsonArray resultArray = resultObject.getAsJsonArray("contents");
|
||||||
for (int resultIndex = startIndex; resultIndex < resultArray.size() && count < range; resultIndex++, count++) {
|
for (int resultIndex = startIndex; resultIndex < resultArray.size() && count < range; resultIndex++, count++) {
|
||||||
results.add(resultArray.get(resultIndex).getAsJsonObject());
|
results.add(resultArray.get(resultIndex).getAsJsonObject());
|
||||||
}
|
}
|
||||||
|
|
||||||
// 重置索引
|
// 重置索引
|
||||||
startIndex = 0;
|
startIndex = 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user