refactor(品牌工具页): 历史轮询抽为 useHistoryPolling
QueryAsin / Withdraw / PatrolDelete 三页逐字相同的 startHistoryPolling / stopHistoryPolling 收敛为 shared/composables/useHistoryPolling:定时器走各页 categorized-timers(category 固定 history-poll),间隔默认主轮询的 2 倍。 categorized-timers 补 CategorizedTimers 类型导出;补注入式假定时器单测 5 例。 净减约 40 行;vue-tsc 构建与 695 个前端单测通过。
This commit is contained in:
+72
-7
@@ -40,6 +40,8 @@ public class OssStorageService {
|
||||
private static final String SHOP_DATA_CRAWL_PREFIX = "result/shop_data_crawl/";
|
||||
private static final String DIGITAL_HUMAN_PREFIX = "digital-human/versions/";
|
||||
private static final String SOFTWARE_VERSION_PREFIX = "nanri-image/versions/";
|
||||
/** 教程安装包对象键前缀(公开 client 桶,工具台「立即下载教程」直链来源)。 */
|
||||
private static final String TUTORIAL_PREFIX = "tutorial/";
|
||||
private static final String LEGACY_MINIO_ENDPOINT = "http://47.110.241.161:9000";
|
||||
/** readObjectBytes 兜底读取上限(20MB):防止大对象一次性读入内存导致 OOM。 */
|
||||
private static final long DEFAULT_READ_MAX_BYTES = 20L * 1024 * 1024;
|
||||
@@ -118,12 +120,13 @@ public class OssStorageService {
|
||||
if (objectKey == null || !objectKey.startsWith(SOFTWARE_VERSION_PREFIX)) {
|
||||
throw new IllegalArgumentException("software version objectKey must start with " + SOFTWARE_VERSION_PREFIX);
|
||||
}
|
||||
String bucket = softwareVersionBucket();
|
||||
String bucket = publicClientBucket();
|
||||
uploadFile(file, bucket, objectKey);
|
||||
return getPublicUrl(objectKey, bucket);
|
||||
}
|
||||
|
||||
private String softwareVersionBucket() {
|
||||
/** 公开 client 桶(软件版本包与教程包共用):默认 client,可用 aiimage.oss.software-version-bucket 覆盖。 */
|
||||
private String publicClientBucket() {
|
||||
String configured = ossProperties.getSoftwareVersionBucket();
|
||||
return (configured == null || configured.isBlank()) ? "client" : configured;
|
||||
}
|
||||
@@ -139,7 +142,7 @@ public class OssStorageService {
|
||||
try {
|
||||
return buildClient().getPresignedObjectUrl(GetPresignedObjectUrlArgs.builder()
|
||||
.method(Method.PUT)
|
||||
.bucket(softwareVersionBucket())
|
||||
.bucket(publicClientBucket())
|
||||
.object(objectKey)
|
||||
.expiry(Math.max(60, expirySeconds), TimeUnit.SECONDS)
|
||||
.build());
|
||||
@@ -155,7 +158,7 @@ public class OssStorageService {
|
||||
}
|
||||
try {
|
||||
var stat = buildClient().statObject(StatObjectArgs.builder()
|
||||
.bucket(softwareVersionBucket())
|
||||
.bucket(publicClientBucket())
|
||||
.object(objectKey)
|
||||
.build());
|
||||
return stat.size();
|
||||
@@ -174,7 +177,7 @@ public class OssStorageService {
|
||||
if (objectKey == null || !objectKey.startsWith(SOFTWARE_VERSION_PREFIX)) {
|
||||
throw new IllegalArgumentException("software version objectKey must start with " + SOFTWARE_VERSION_PREFIX);
|
||||
}
|
||||
return getPublicUrl(objectKey, softwareVersionBucket());
|
||||
return getPublicUrl(objectKey, publicClientBucket());
|
||||
}
|
||||
|
||||
/** 删除软件版本对象(client 桶);确认环节发现超限等异常时清理残留,避免公共桶悬挂大对象。 */
|
||||
@@ -184,7 +187,7 @@ public class OssStorageService {
|
||||
}
|
||||
try {
|
||||
buildClient().removeObject(RemoveObjectArgs.builder()
|
||||
.bucket(softwareVersionBucket())
|
||||
.bucket(publicClientBucket())
|
||||
.object(objectKey)
|
||||
.build());
|
||||
} catch (Exception ex) {
|
||||
@@ -192,6 +195,68 @@ public class OssStorageService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 为教程安装包签发浏览器直传用的预签名 PUT URL(公开 client 桶 tutorial/ 前缀)。
|
||||
* 签名 host 与反代入口一致,浏览器对返回的 URL 直接 PUT 即可落对象。
|
||||
*/
|
||||
public String presignTutorialUpload(String objectKey, int expirySeconds) {
|
||||
requireTutorialKey(objectKey);
|
||||
try {
|
||||
return buildClient().getPresignedObjectUrl(GetPresignedObjectUrlArgs.builder()
|
||||
.method(Method.PUT)
|
||||
.bucket(publicClientBucket())
|
||||
.object(objectKey)
|
||||
.expiry(Math.max(60, expirySeconds), TimeUnit.SECONDS)
|
||||
.build());
|
||||
} catch (Exception ex) {
|
||||
throw storageFailure("presign", objectKey, ex);
|
||||
}
|
||||
}
|
||||
|
||||
/** 返回教程对象的字节数;对象不存在返回 -1(直传完成后由服务端核对大小是否超限)。 */
|
||||
public long tutorialObjectSize(String objectKey) {
|
||||
requireTutorialKey(objectKey);
|
||||
try {
|
||||
var stat = buildClient().statObject(StatObjectArgs.builder()
|
||||
.bucket(publicClientBucket())
|
||||
.object(objectKey)
|
||||
.build());
|
||||
return stat.size();
|
||||
} catch (ErrorResponseException ex) {
|
||||
if (isNotFound(ex)) {
|
||||
return -1L;
|
||||
}
|
||||
throw storageFailure("stat", objectKey, ex);
|
||||
} catch (Exception ex) {
|
||||
throw storageFailure("stat", objectKey, ex);
|
||||
}
|
||||
}
|
||||
|
||||
/** 生成教程对象的公开下载 URL(与历史直链同构:https://oss.aishufu.top/client/tutorial/...)。 */
|
||||
public String getTutorialDownloadUrl(String objectKey) {
|
||||
requireTutorialKey(objectKey);
|
||||
return getPublicUrl(objectKey, publicClientBucket());
|
||||
}
|
||||
|
||||
/** 删除教程对象(client 桶);后台删除记录时清理无引用对象。 */
|
||||
public void removeTutorialObject(String objectKey) {
|
||||
requireTutorialKey(objectKey);
|
||||
try {
|
||||
buildClient().removeObject(RemoveObjectArgs.builder()
|
||||
.bucket(publicClientBucket())
|
||||
.object(objectKey)
|
||||
.build());
|
||||
} catch (Exception ex) {
|
||||
throw storageFailure("delete", objectKey, ex);
|
||||
}
|
||||
}
|
||||
|
||||
private void requireTutorialKey(String objectKey) {
|
||||
if (objectKey == null || !objectKey.startsWith(TUTORIAL_PREFIX)) {
|
||||
throw new IllegalArgumentException("tutorial objectKey must start with " + TUTORIAL_PREFIX);
|
||||
}
|
||||
}
|
||||
|
||||
public String uploadText(String objectKey, String content) {
|
||||
if (objectKey == null || objectKey.isBlank()) {
|
||||
throw new IllegalArgumentException("objectKey must not be blank");
|
||||
@@ -590,7 +655,7 @@ public class OssStorageService {
|
||||
|
||||
private List<String> configuredBuckets() {
|
||||
return Stream.of(ossProperties.getBucket(), imageVideoBucket(), digitalHumanBucket(), templateBucket(),
|
||||
softwareVersionBucket(), shopDataBucket())
|
||||
publicClientBucket(), shopDataBucket())
|
||||
.filter(Objects::nonNull)
|
||||
.map(String::trim)
|
||||
.filter(bucket -> !bucket.isBlank())
|
||||
|
||||
Reference in New Issue
Block a user