CompletableFuture 改 Future
This commit is contained in:
@@ -2,8 +2,8 @@ package me.qwq.doghouse.controller.api.v1;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.jdom2.DocType;
|
||||
@@ -71,7 +71,7 @@ public class ApiControllerV1 {
|
||||
@RequestParam(required=false) String nocache) {
|
||||
|
||||
if (size == null || size <= 0) size = 36;
|
||||
CompletableFuture<byte[]> future =
|
||||
Future<byte[]> future =
|
||||
gravatarUtils.getReversedProxyGravatarAsync(hash, size, StringUtils.isBlank(nocache));
|
||||
|
||||
byte[] avatar;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package me.qwq.doghouse.controller.api.v2;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -49,7 +49,7 @@ public class GravatarApiControllerV2 extends BaseController {
|
||||
@RequestParam(required=false) String nocache) {
|
||||
|
||||
if (size == null || size <= 0) size = 36;
|
||||
CompletableFuture<byte[]> future =
|
||||
Future<byte[]> future =
|
||||
gravatarUtils.getReversedProxyGravatarAsync(hash, size, StringUtils.isBlank(nocache));
|
||||
|
||||
byte[] avatar;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package me.qwq.doghouse.util;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Map;
|
||||
@@ -34,4 +35,24 @@ public final class DateUtils {
|
||||
|
||||
return dateTime.format(formatter);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将给定字符串转换成 LocalDate
|
||||
* @param value 如 "20260101"
|
||||
* @param pattern 日期格式,如 yyyyMMdd
|
||||
* @return
|
||||
*/
|
||||
public static LocalDate parse(String value, String pattern) {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
if (pattern == null || pattern.isEmpty()) {
|
||||
throw new IllegalArgumentException("pattern must not be null or empty");
|
||||
}
|
||||
DateTimeFormatter formatter =
|
||||
FORMATTER_CACHE.computeIfAbsent(pattern, DateTimeFormatter::ofPattern);
|
||||
|
||||
LocalDate date = LocalDate.parse(value, formatter);
|
||||
return date;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import java.net.Proxy;
|
||||
import java.time.Duration;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
@@ -63,7 +64,7 @@ public class GravatarUtils {
|
||||
}
|
||||
|
||||
@Async
|
||||
public CompletableFuture<byte[]> getReversedProxyGravatarAsync(String privateHash, int size, boolean fromCache) {
|
||||
public Future<byte[]> getReversedProxyGravatarAsync(String privateHash, int size, boolean fromCache) {
|
||||
return CompletableFuture.completedFuture(getProxyGravatar(privateHash, size, fromCache));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user