feat(software-version): 安装包改浏览器直传 MinIO,支持批量删除
- 后端新增 /api/admin/version/presign、confirm、delete 端点;直传后服务端校验对象并写 web_config - OSS 层新增软件版本对象 presign PUT/大小校验/删除与 client 桶 URL 识别 - 后台前端上传改 presign→PUT→confirm 三段式直传,带进度条;成功提示精简为"发布成功" - 版本列表加勾选/表头全选、批量删除与单行删除;操作按钮样式对齐其他子菜单
This commit is contained in:
+69
-1
@@ -3,8 +3,10 @@ package com.nanri.aiimage.modules.file.service.oss;
|
||||
import com.nanri.aiimage.config.OssProperties;
|
||||
import io.minio.BucketExistsArgs;
|
||||
import io.minio.GetObjectArgs;
|
||||
import io.minio.GetPresignedObjectUrlArgs;
|
||||
import io.minio.MakeBucketArgs;
|
||||
import io.minio.MinioClient;
|
||||
import io.minio.http.Method;
|
||||
import io.minio.PutObjectArgs;
|
||||
import io.minio.RemoveObjectArgs;
|
||||
import io.minio.StatObjectArgs;
|
||||
@@ -23,6 +25,7 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@Service
|
||||
@@ -99,6 +102,70 @@ public class OssStorageService {
|
||||
return (configured == null || configured.isBlank()) ? "client" : configured;
|
||||
}
|
||||
|
||||
/**
|
||||
* 为软件版本安装包签发浏览器直传用的预签名 PUT URL(client 桶公开路径)。
|
||||
* 签名 host 与反代入口一致(endpoint 即 public-endpoint oss.aishufu.top),浏览器对返回的 URL 直接 PUT 即可落对象。
|
||||
*/
|
||||
public String presignSoftwareVersionUpload(String objectKey, int expirySeconds) {
|
||||
if (objectKey == null || !objectKey.startsWith(SOFTWARE_VERSION_PREFIX)) {
|
||||
throw new IllegalArgumentException("software version objectKey must start with " + SOFTWARE_VERSION_PREFIX);
|
||||
}
|
||||
try {
|
||||
return buildClient().getPresignedObjectUrl(GetPresignedObjectUrlArgs.builder()
|
||||
.method(Method.PUT)
|
||||
.bucket(softwareVersionBucket())
|
||||
.object(objectKey)
|
||||
.expiry(Math.max(60, expirySeconds), TimeUnit.SECONDS)
|
||||
.build());
|
||||
} catch (Exception ex) {
|
||||
throw storageFailure("presign", objectKey, ex);
|
||||
}
|
||||
}
|
||||
|
||||
/** 返回软件版本对象的字节数;对象不存在返回 -1(直传完成后由服务端核对大小是否超限)。 */
|
||||
public long softwareVersionObjectSize(String objectKey) {
|
||||
if (objectKey == null || !objectKey.startsWith(SOFTWARE_VERSION_PREFIX)) {
|
||||
throw new IllegalArgumentException("software version objectKey must start with " + SOFTWARE_VERSION_PREFIX);
|
||||
}
|
||||
try {
|
||||
var stat = buildClient().statObject(StatObjectArgs.builder()
|
||||
.bucket(softwareVersionBucket())
|
||||
.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(与历史 file_url 同构:path-style client 桶)。 */
|
||||
public String getSoftwareVersionDownloadUrl(String objectKey) {
|
||||
if (objectKey == null || !objectKey.startsWith(SOFTWARE_VERSION_PREFIX)) {
|
||||
throw new IllegalArgumentException("software version objectKey must start with " + SOFTWARE_VERSION_PREFIX);
|
||||
}
|
||||
return getPublicUrl(objectKey, softwareVersionBucket());
|
||||
}
|
||||
|
||||
/** 删除软件版本对象(client 桶);确认环节发现超限等异常时清理残留,避免公共桶悬挂大对象。 */
|
||||
public void removeSoftwareVersionObject(String objectKey) {
|
||||
if (objectKey == null || !objectKey.startsWith(SOFTWARE_VERSION_PREFIX)) {
|
||||
throw new IllegalArgumentException("software version objectKey must start with " + SOFTWARE_VERSION_PREFIX);
|
||||
}
|
||||
try {
|
||||
buildClient().removeObject(RemoveObjectArgs.builder()
|
||||
.bucket(softwareVersionBucket())
|
||||
.object(objectKey)
|
||||
.build());
|
||||
} catch (Exception ex) {
|
||||
throw storageFailure("delete", objectKey, ex);
|
||||
}
|
||||
}
|
||||
|
||||
public String uploadText(String objectKey, String content) {
|
||||
if (objectKey == null || objectKey.isBlank()) {
|
||||
throw new IllegalArgumentException("objectKey must not be blank");
|
||||
@@ -472,7 +539,8 @@ public class OssStorageService {
|
||||
}
|
||||
|
||||
private List<String> configuredBuckets() {
|
||||
return Stream.of(ossProperties.getBucket(), imageVideoBucket(), digitalHumanBucket(), templateBucket())
|
||||
return Stream.of(ossProperties.getBucket(), imageVideoBucket(), digitalHumanBucket(), templateBucket(),
|
||||
softwareVersionBucket())
|
||||
.filter(Objects::nonNull)
|
||||
.map(String::trim)
|
||||
.filter(bucket -> !bucket.isBlank())
|
||||
|
||||
Reference in New Issue
Block a user