项目整机拼装与资源文件上传
This commit is contained in:
+2
-1
@@ -195,7 +195,8 @@ public class AdminManagementService {
|
||||
checkKeyword(keyword);
|
||||
LambdaQueryWrapper<Project> query =
|
||||
new LambdaQueryWrapper<Project>().eq(Project::getDeleted, false);
|
||||
query.select(Project.class, field -> !"urdfFiles".equals(field.getProperty()));
|
||||
query.select(Project.class, field -> !Set.of("urdfFiles", "modelPartsFiles", "walkingResourcesFiles")
|
||||
.contains(field.getProperty()));
|
||||
if (ownerCode != null) query.eq(Project::getOwnerUserId, user(ownerCode).getId());
|
||||
query.eq(type != null, Project::getProjectType, type)
|
||||
.eq(publishStatus != null, Project::getPublishStatus, publishStatus)
|
||||
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
package com.linkerbot.vibemake.service.admin;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.linkerbot.vibemake.bean.Contracts.*;
|
||||
import com.linkerbot.vibemake.bean.entity.Project;
|
||||
import com.linkerbot.vibemake.common.BusinessException;
|
||||
import com.linkerbot.vibemake.service.ProjectService;
|
||||
import com.linkerbot.vibemake.service.mapper.ProjectMapper;
|
||||
import com.linkerbot.vibemake.service.oss.ProjectResources;
|
||||
import com.linkerbot.vibemake.service.oss.ProjectResourceType;
|
||||
import com.linkerbot.vibemake.service.support.ProjectActors;
|
||||
import com.linkerbot.vibemake.service.support.ProjectLocks;
|
||||
import com.linkerbot.vibemake.service.support.ProjectSupport;
|
||||
import java.util.List;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class AdminProjectResourceService {
|
||||
private static final Logger log = LoggerFactory.getLogger(AdminProjectResourceService.class);
|
||||
private final ProjectService projects;
|
||||
private final ProjectMapper mapper;
|
||||
private final ProjectResources resources;
|
||||
private final ProjectLocks locks;
|
||||
|
||||
private void requireAdmin() {
|
||||
if (!ProjectActors.isAdmin()) throw new BusinessException(403, "FORBIDDEN", "仅管理员可管理项目资源");
|
||||
}
|
||||
|
||||
public ResourceUploadSignature signature(String projectCode, String resourceType, ResourceUploadInput input) {
|
||||
requireAdmin();
|
||||
ProjectResourceType type = ProjectResourceType.from(resourceType);
|
||||
projects.readyOwner(0, projectCode);
|
||||
return resources.sign(projectCode, type, input.files());
|
||||
}
|
||||
|
||||
public ProjectView confirm(String projectCode, String resourceType, ResourceConfirmInput input) {
|
||||
requireAdmin();
|
||||
ProjectResourceType type = ProjectResourceType.from(resourceType);
|
||||
projects.readyOwner(0, projectCode);
|
||||
resources.verify(projectCode, type, input.batchCode(), input.files());
|
||||
String prefix = resources.prefix(projectCode, type, input.batchCode());
|
||||
String manifest = resources.manifest(input.files());
|
||||
return locks.serial(projectCode, () -> {
|
||||
Project project = projects.readyOwner(0, projectCode);
|
||||
persist(project, type, prefix, input.files(), manifest);
|
||||
log.info("绑定项目资源 projectCode={} resourceType={} batchCode={} fileCount={}",
|
||||
projectCode, type.code(), input.batchCode(), input.files().size());
|
||||
return projects.view(projects.owner(0, projectCode), null);
|
||||
});
|
||||
}
|
||||
|
||||
public void clear(String projectCode, String resourceType) {
|
||||
requireAdmin();
|
||||
ProjectResourceType type = ProjectResourceType.from(resourceType);
|
||||
locks.serial(projectCode, () -> {
|
||||
persist(projects.owner(0, projectCode), type, "", List.of(), "[]");
|
||||
log.info("清除项目资源绑定 projectCode={} resourceType={}", projectCode, type.code());
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
private void persist(Project project, ProjectResourceType type, String prefix,
|
||||
List<ResourceFile> files, String manifest) {
|
||||
LambdaUpdateWrapper<Project> update = new LambdaUpdateWrapper<Project>()
|
||||
.eq(Project::getProjectCode, project.getProjectCode())
|
||||
.eq(Project::getOwnerUserId, project.getOwnerUserId())
|
||||
.eq(Project::getDeleted, false)
|
||||
.set(Project::getUpdatedAt, ProjectSupport.now());
|
||||
String key = prefix.isEmpty() ? "" : prefix + files.getFirst().relativePath();
|
||||
long size = files.isEmpty() ? 0L : files.getFirst().sizeBytes();
|
||||
switch (type) {
|
||||
case MODEL_GLB -> update.set(Project::getModelGlbObjectKey, key)
|
||||
.set(Project::getModelGlbSizeBytes, size);
|
||||
case MODEL_PARTS -> update.set(Project::getModelPartsPrefix, prefix)
|
||||
.set(Project::getModelPartsFiles, manifest);
|
||||
case ASSEMBLY_JSON -> update.set(Project::getAssemblyJsonObjectKey, key)
|
||||
.set(Project::getAssemblyJsonSizeBytes, size);
|
||||
case WALKING_RESOURCES -> update.set(Project::getWalkingResourcesPrefix, prefix)
|
||||
.set(Project::getWalkingResourcesFiles, manifest);
|
||||
}
|
||||
if (mapper.update(null, update) != 1) throw BusinessException.notFound();
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -174,7 +174,8 @@ public class AiProjectSearch {
|
||||
if (codes.isEmpty()) return List.of();
|
||||
return projects.selectList(
|
||||
new LambdaQueryWrapper<Project>()
|
||||
.select(Project.class, field -> !"urdfFiles".equals(field.getProperty()))
|
||||
.select(Project.class, field -> !Set.of("urdfFiles", "modelPartsFiles", "walkingResourcesFiles")
|
||||
.contains(field.getProperty()))
|
||||
.in(Project::getProjectCode, codes)
|
||||
.eq(Project::getDeleted, false)
|
||||
.eq(Project::getRepoStatus, "READY")
|
||||
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package com.linkerbot.vibemake.service.config;
|
||||
|
||||
import jakarta.validation.constraints.AssertTrue;
|
||||
import java.time.Duration;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Validated
|
||||
@Component
|
||||
@ConfigurationProperties(prefix = "vibemake.oss.project-resources")
|
||||
public class ProjectResourceProperties {
|
||||
private Duration signatureValidity = Duration.ofHours(1);
|
||||
|
||||
@AssertTrue(message = "项目资源签名有效期必须大于零且不超过七天")
|
||||
public boolean isSignatureValidityValid() {
|
||||
return signatureValidity != null
|
||||
&& !signatureValidity.isNegative()
|
||||
&& !signatureValidity.isZero()
|
||||
&& signatureValidity.compareTo(Duration.ofDays(7)) <= 0;
|
||||
}
|
||||
}
|
||||
+44
-18
@@ -19,6 +19,8 @@ import com.linkerbot.vibemake.service.fork.GitSnapshotCopier;
|
||||
import com.linkerbot.vibemake.service.gitea.*;
|
||||
import com.linkerbot.vibemake.service.mapper.*;
|
||||
import com.linkerbot.vibemake.service.oss.OssResourcePaths;
|
||||
import com.linkerbot.vibemake.service.oss.ProjectResourceFiles;
|
||||
import com.linkerbot.vibemake.service.oss.ProjectResourceType;
|
||||
import com.linkerbot.vibemake.service.oss.UrdfResources;
|
||||
import com.linkerbot.vibemake.service.state.RateLimits;
|
||||
import com.linkerbot.vibemake.service.support.ProjectActors;
|
||||
@@ -52,6 +54,7 @@ public class ProjectServiceImpl implements ProjectService {
|
||||
private final OssResourcePaths resourcePaths;
|
||||
// 离线导入只需地址转换配置,没有 URDF 时无需初始化 OSS 客户端。
|
||||
private final ObjectProvider<UrdfResources> urdf;
|
||||
private final ObjectProvider<ProjectResourceFiles> resources;
|
||||
private final ObjectProvider<ForkExecutor> forks;
|
||||
private final ObjectProvider<GitSnapshotCopier> snapshots;
|
||||
|
||||
@@ -116,11 +119,15 @@ public class ProjectServiceImpl implements ProjectService {
|
||||
|
||||
@Override
|
||||
public ProjectView view(Project project, Long currentUser) {
|
||||
return views(List.of(project), currentUser).getFirst();
|
||||
return views(List.of(project), currentUser, true).getFirst();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ProjectView> views(List<Project> records, Long currentUser) {
|
||||
return views(records, currentUser, false);
|
||||
}
|
||||
|
||||
private List<ProjectView> views(List<Project> records, Long currentUser, boolean includeFiles) {
|
||||
if (records.isEmpty()) return List.of();
|
||||
Set<Long> ids = new HashSet<>();
|
||||
Set<Long> ownerIds = new HashSet<>();
|
||||
@@ -177,7 +184,8 @@ public class ProjectServiceImpl implements ProjectService {
|
||||
likeCounts.getOrDefault(project.getId(), 0L),
|
||||
commentCounts.getOrDefault(project.getId(), 0L),
|
||||
likedIds.contains(project.getId()),
|
||||
imported.get(project.getProjectCode())));
|
||||
imported.get(project.getProjectCode()),
|
||||
includeFiles));
|
||||
return List.copyOf(result);
|
||||
}
|
||||
|
||||
@@ -188,25 +196,24 @@ public class ProjectServiceImpl implements ProjectService {
|
||||
long likeCount,
|
||||
long commentCount,
|
||||
boolean liked,
|
||||
ProjectImportTask imported) {
|
||||
String coverUrl;
|
||||
String urdfMainUrl;
|
||||
String urdfBaseUrl;
|
||||
ProjectImportTask imported,
|
||||
boolean includeFiles) {
|
||||
try {
|
||||
coverUrl = resourcePaths.coverUrl(project.getCoverUrl());
|
||||
urdfMainUrl = urdfUrl(project.getUrdfMainObjectKey());
|
||||
urdfBaseUrl = urdfUrl(project.getUrdfPrefix());
|
||||
} catch (BusinessException error) {
|
||||
log.warn("项目资源地址生成失败 projectCode={} code={}", project.getProjectCode(), error.code());
|
||||
throw error;
|
||||
}
|
||||
return new ProjectView(
|
||||
return new ProjectView(
|
||||
project.getProjectCode(),
|
||||
project.getName(),
|
||||
project.getDescription(),
|
||||
coverUrl,
|
||||
urdfMainUrl,
|
||||
urdfBaseUrl,
|
||||
resourcePaths.coverUrl(project.getCoverUrl()),
|
||||
urdfUrl(project.getUrdfMainObjectKey()),
|
||||
urdfUrl(project.getUrdfPrefix()),
|
||||
resourcePaths.publicUrl(project.getModelGlbObjectKey()),
|
||||
resourcePaths.publicUrl(project.getModelPartsPrefix()),
|
||||
includeFiles ? resourceFiles(project.getModelPartsPrefix(), project.getModelPartsFiles(),
|
||||
ProjectResourceType.MODEL_PARTS) : null,
|
||||
resourcePaths.publicUrl(project.getAssemblyJsonObjectKey()),
|
||||
resourcePaths.publicUrl(project.getWalkingResourcesPrefix()),
|
||||
includeFiles ? resourceFiles(project.getWalkingResourcesPrefix(), project.getWalkingResourcesFiles(),
|
||||
ProjectResourceType.WALKING_RESOURCES) : null,
|
||||
project.getProjectType(),
|
||||
owner,
|
||||
project.getRepoStatus(),
|
||||
@@ -222,12 +229,21 @@ public class ProjectServiceImpl implements ProjectService {
|
||||
imported == null ? null : imported.getSourceLicense(),
|
||||
project.getCreatedAt(),
|
||||
project.getUpdatedAt());
|
||||
} catch (BusinessException error) {
|
||||
log.warn("项目资源地址生成失败 projectCode={} code={}", project.getProjectCode(), error.code());
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
private String urdfUrl(String objectKey) {
|
||||
return objectKey == null || objectKey.isEmpty() ? null : urdf.getObject().url(objectKey);
|
||||
}
|
||||
|
||||
private List<ResourceFileView> resourceFiles(String prefix, String manifest, ProjectResourceType type) {
|
||||
if (prefix == null || prefix.isEmpty()) return List.of();
|
||||
return resources.getObject().fileViews(prefix, manifest, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResponse<ProjectView> list(
|
||||
Long ownerId, String type, String keyword, long page, long size, Long currentUser) {
|
||||
@@ -241,7 +257,8 @@ public class ProjectServiceImpl implements ProjectService {
|
||||
.lambda()
|
||||
.eq(Project::getDeleted, false);
|
||||
// 列表不需要资源包清单,避免为每个项目读取可能很大的 JSON 字段。
|
||||
query.select(Project.class, field -> !"urdfFiles".equals(field.getProperty()));
|
||||
query.select(Project.class, field -> !Set.of("urdfFiles", "modelPartsFiles", "walkingResourcesFiles")
|
||||
.contains(field.getProperty()));
|
||||
if (ownerId == null)
|
||||
query.eq(Project::getRepoStatus, "READY")
|
||||
.eq(Project::getPublishStatus, "PUBLISHED")
|
||||
@@ -290,6 +307,15 @@ public class ProjectServiceImpl implements ProjectService {
|
||||
if (source != null) {
|
||||
project.setSourceProjectId(source.getId());
|
||||
project.setSourceCommitSha(source.getPublishedCommitSha());
|
||||
// 新增资源只继承数据库引用;不查询或复制 OSS,源项目替换也不会改变副本绑定。
|
||||
project.setModelGlbObjectKey(source.getModelGlbObjectKey());
|
||||
project.setModelGlbSizeBytes(source.getModelGlbSizeBytes());
|
||||
project.setModelPartsPrefix(source.getModelPartsPrefix());
|
||||
project.setModelPartsFiles(source.getModelPartsFiles());
|
||||
project.setAssemblyJsonObjectKey(source.getAssemblyJsonObjectKey());
|
||||
project.setAssemblyJsonSizeBytes(source.getAssemblyJsonSizeBytes());
|
||||
project.setWalkingResourcesPrefix(source.getWalkingResourcesPrefix());
|
||||
project.setWalkingResourcesFiles(source.getWalkingResourcesFiles());
|
||||
}
|
||||
for (int attempt = 1; attempt <= 5; attempt++) {
|
||||
try {
|
||||
|
||||
+2
-2
@@ -113,7 +113,7 @@ public class AliyunOssObjectStore implements OssObjectStore {
|
||||
}
|
||||
|
||||
private BusinessException failure(String operation, String key, OSSException error) {
|
||||
log.warn("URDF OSS 请求失败 operation={} objectKey={} ossCode={} requestId={}",
|
||||
log.warn("OSS 请求失败 operation={} objectKey={} ossCode={} requestId={}",
|
||||
operation, key, error.getErrorCode(), error.getRequestId());
|
||||
if ("NoSuchKey".equals(error.getErrorCode()))
|
||||
return new BusinessException(400, "URDF_FILE_MISSING", "URDF 文件未上传完整,请重新上传");
|
||||
@@ -123,7 +123,7 @@ public class AliyunOssObjectStore implements OssObjectStore {
|
||||
}
|
||||
|
||||
private BusinessException transportFailure(String operation, String key, ClientException error) {
|
||||
log.warn("URDF OSS 连接失败 operation={} objectKey={} errorType={}",
|
||||
log.warn("OSS 连接失败 operation={} objectKey={} errorType={}",
|
||||
operation, key, error.getClass().getSimpleName());
|
||||
return new BusinessException(502, "OSS_ERROR", "OSS 资源访问失败,请稍后重试");
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
package com.linkerbot.vibemake.service.oss;
|
||||
|
||||
/** URDF 所需的 OSS 操作边界,测试使用内存实现。 */
|
||||
/** 项目资源所需的 OSS 操作边界,测试使用内存实现。 */
|
||||
public interface OssObjectStore {
|
||||
record Metadata(long sizeBytes, String etag) {}
|
||||
|
||||
|
||||
+5
-1
@@ -58,7 +58,11 @@ public class OssPostSigner {
|
||||
public record SignedPost(LocalDateTime expiresAt, Map<String, String> formFields) {}
|
||||
|
||||
public SignedPost signObject(String key, String contentType, long sizeBytes) {
|
||||
return post(key, contentType, sizeBytes, sizeBytes, Duration.ofMinutes(15), true);
|
||||
return signObject(key, contentType, sizeBytes, Duration.ofMinutes(15));
|
||||
}
|
||||
|
||||
public SignedPost signObject(String key, String contentType, long sizeBytes, Duration validity) {
|
||||
return post(key, contentType, sizeBytes, sizeBytes, validity, true);
|
||||
}
|
||||
|
||||
private SignedPost post(String key, String contentType, long minBytes, long maxBytes,
|
||||
|
||||
+2
-1
@@ -65,7 +65,8 @@ public class OssResourcePaths {
|
||||
String root = oss.getRootDirectory();
|
||||
if (root != null && !root.isBlank() && path.startsWith(root + "/"))
|
||||
path = path.substring(root.length());
|
||||
if (!path.startsWith("/project-covers/") && !path.startsWith("/urdf/")) throw invalidPath();
|
||||
if (!path.startsWith("/project-covers/") && !path.startsWith("/urdf/")
|
||||
&& !path.startsWith("/project-resources/")) throw invalidPath();
|
||||
String relative = path.substring(1);
|
||||
if (relative.endsWith("/")) relative = relative.substring(0, relative.length() - 1);
|
||||
try {
|
||||
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package com.linkerbot.vibemake.service.oss;
|
||||
|
||||
import com.linkerbot.vibemake.common.BusinessException;
|
||||
|
||||
public enum ProjectResourceType {
|
||||
MODEL_GLB("model-glb", ".glb", true),
|
||||
MODEL_PARTS("model-parts", ".glb", false),
|
||||
ASSEMBLY_JSON("assembly-json", ".json", true),
|
||||
WALKING_RESOURCES("walking-resources", "", false);
|
||||
|
||||
private final String code;
|
||||
private final String extension;
|
||||
private final boolean singleFile;
|
||||
|
||||
ProjectResourceType(String code, String extension, boolean singleFile) {
|
||||
this.code = code;
|
||||
this.extension = extension;
|
||||
this.singleFile = singleFile;
|
||||
}
|
||||
|
||||
public String code() { return code; }
|
||||
public String extension() { return extension; }
|
||||
public boolean singleFile() { return singleFile; }
|
||||
|
||||
public static ProjectResourceType from(String code) {
|
||||
for (ProjectResourceType type : values()) {
|
||||
if (type.code.equals(code)) return type;
|
||||
}
|
||||
throw BusinessException.badRequest("项目资源类型不合法");
|
||||
}
|
||||
}
|
||||
+98
@@ -0,0 +1,98 @@
|
||||
package com.linkerbot.vibemake.service.oss;
|
||||
|
||||
import com.linkerbot.vibemake.bean.Contracts.ResourceFile;
|
||||
import com.linkerbot.vibemake.bean.Contracts.ResourceFileSignature;
|
||||
import com.linkerbot.vibemake.bean.Contracts.ResourceUploadSignature;
|
||||
import com.linkerbot.vibemake.common.BusinessException;
|
||||
import com.linkerbot.vibemake.common.Codes;
|
||||
import com.linkerbot.vibemake.service.config.OssProperties;
|
||||
import com.linkerbot.vibemake.service.config.ProjectResourceProperties;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.http.MediaTypeFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/** 管理端资源签名及上传结果核验。 */
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class ProjectResources {
|
||||
public static final long OSS_MAX_FILE_BYTES = ProjectResourceFiles.OSS_MAX_FILE_BYTES;
|
||||
private static final Logger log = LoggerFactory.getLogger(ProjectResources.class);
|
||||
private final OssProperties oss;
|
||||
private final ProjectResourceProperties properties;
|
||||
private final OssPostSigner signer;
|
||||
private final OssObjectStore store;
|
||||
private final ProjectResourceFiles manifests;
|
||||
private final OssResourcePaths paths;
|
||||
|
||||
private void requireEnabled() {
|
||||
if (!oss.isEnabled())
|
||||
throw new BusinessException(503, "OSS_UNAVAILABLE", "OSS 项目资源上传暂未开启");
|
||||
}
|
||||
|
||||
public String prefix(String projectCode, ProjectResourceType type, String batchCode) {
|
||||
if (projectCode == null || !projectCode.matches("[a-z0-9]{12}|[a-z0-9]{32}")
|
||||
|| batchCode == null || !batchCode.matches("[a-f0-9]{32}"))
|
||||
throw BusinessException.badRequest("项目或上传批次编码不合法");
|
||||
return "/project-resources/" + projectCode + "/" + type.code() + "/" + batchCode + "/";
|
||||
}
|
||||
|
||||
public void validate(String prefix, ProjectResourceType type, List<ResourceFile> files) {
|
||||
manifests.validate(prefix, type, files);
|
||||
}
|
||||
|
||||
public ResourceUploadSignature sign(String projectCode, ProjectResourceType type, List<ResourceFile> files) {
|
||||
requireEnabled();
|
||||
String batchCode = Codes.next();
|
||||
String prefix = prefix(projectCode, type, batchCode);
|
||||
validate(prefix, type, files);
|
||||
List<ResourceFileSignature> signatures = new ArrayList<>();
|
||||
LocalDateTime expiration = null;
|
||||
for (ResourceFile file : files) {
|
||||
String key = paths.objectKey(prefix + file.relativePath());
|
||||
OssPostSigner.SignedPost post = signer.signObject(
|
||||
key, contentType(file.relativePath()), file.sizeBytes(), properties.getSignatureValidity());
|
||||
signatures.add(new ResourceFileSignature(file.relativePath(), key, post.formFields()));
|
||||
if (expiration == null || post.expiresAt().isBefore(expiration)) expiration = post.expiresAt();
|
||||
}
|
||||
log.info("生成项目资源上传签名 projectCode={} resourceType={} batchCode={} fileCount={}",
|
||||
projectCode, type.code(), batchCode, files.size());
|
||||
return new ResourceUploadSignature(batchCode, oss.uploadUrl(), expiration, List.copyOf(signatures));
|
||||
}
|
||||
|
||||
private String contentType(String path) {
|
||||
String lower = path.toLowerCase(Locale.ROOT);
|
||||
if (lower.endsWith(".glb")) return "model/gltf-binary";
|
||||
if (lower.endsWith(".json")) return "application/json";
|
||||
return MediaTypeFactory.getMediaType(lower).map(Object::toString).orElse("application/octet-stream");
|
||||
}
|
||||
|
||||
public void verify(String projectCode, ProjectResourceType type, String batchCode, List<ResourceFile> files) {
|
||||
requireEnabled();
|
||||
String prefix = prefix(projectCode, type, batchCode);
|
||||
validate(prefix, type, files);
|
||||
for (ResourceFile file : files) {
|
||||
try {
|
||||
OssObjectStore.Metadata metadata = store.head(paths.objectKey(prefix + file.relativePath()));
|
||||
if (metadata.sizeBytes() != file.sizeBytes())
|
||||
throw new BusinessException(400, "RESOURCE_FILE_SIZE_MISMATCH", "资源文件大小不符,请重新上传");
|
||||
} catch (BusinessException error) {
|
||||
log.warn("项目资源核验失败 projectCode={} resourceType={} batchCode={} relativePath={} code={}",
|
||||
projectCode, type.code(), batchCode, file.relativePath(), error.code());
|
||||
if ("URDF_FILE_MISSING".equals(error.code()))
|
||||
throw new BusinessException(400, "RESOURCE_FILE_MISSING", "资源文件未上传完整,请重新上传");
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String manifest(List<ResourceFile> files) {
|
||||
return manifests.manifest(files);
|
||||
}
|
||||
|
||||
}
|
||||
+6
-1
@@ -86,7 +86,12 @@ public class HttpSafetyFilter extends OncePerRequestFilter {
|
||||
if (!acquired) throw new RateLimitedException("FILE_BUSY", "文件服务繁忙,请稍后重试", 1);
|
||||
}
|
||||
String contentType = request.getContentType();
|
||||
if (contentType != null && contentType.toLowerCase(Locale.ROOT).contains("json")) {
|
||||
// 仅管理端的新资源清单不设正文配额;安全链鉴权通过后,控制器才会解析正文。
|
||||
boolean resourceManifest = ("POST".equals(method) || "PUT".equals(method))
|
||||
&& path.matches("/admin-api/projects/[^/]+/resources/"
|
||||
+ "(model-glb|model-parts|assembly-json|walking-resources)(/signature)?");
|
||||
if (contentType != null && contentType.toLowerCase(Locale.ROOT).contains("json")
|
||||
&& !resourceManifest) {
|
||||
long maximum =
|
||||
path.endsWith("/commits") && "POST".equals(method)
|
||||
? properties.getCommitJsonBytes()
|
||||
|
||||
Reference in New Issue
Block a user