fix(接口测试): 接口调试上传请求体文件后,多次点击保存报错

--bug=1037020 --user=陈建星 【接口测试】接口调试,创建post请求,formdata参数为文件类型,创建后再次点击保存会报错 https://www.tapd.cn/55049933/s/1473999
This commit is contained in:
AgAngle 2024-03-13 15:45:00 +08:00 committed by 刘瑞斌
parent 6e725bdb57
commit 97f2b3e1f8
3 changed files with 17 additions and 5 deletions

View File

@ -312,6 +312,8 @@ public class ApiExecuteService {
String fileName = apiFileResourceService.getTempFileNameByFileId(tempFileId);
return getApiExecuteFileInfo(tempFileId, fileName, taskRequest.getProjectId());
})
// uploadFileIds 查不到则已经移动到正式目录
.filter(i -> StringUtils.isNotBlank(i.getFileName()))
.collect(Collectors.toList());
taskRequest.setLocalTempFiles(localTempFiles);
}

View File

@ -121,19 +121,27 @@ public class ApiFileResourceService {
if (CollectionUtils.isNotEmpty(uploadFileIds)) {
// 添加文件与接口的关联关系
Map<String, String> addFileMap = new HashMap<>();
List<ApiFileResource> apiFileResources = uploadFileIds.stream().map(fileId -> {
ApiFileResource apiFileResource = new ApiFileResource();
List<ApiFileResource> apiFileResources = new ArrayList<>(uploadFileIds.size());
for (String fileId : uploadFileIds) {
String fileName = getTempFileNameByFileId(fileId);
if (StringUtils.isBlank(fileName)) {
// 如果 fileName 查不到说明该文件已经从临时目录移到正式目录已经关联过了无需关联
break;
}
ApiFileResource apiFileResource = new ApiFileResource();
apiFileResource.setFileId(fileId);
apiFileResource.setResourceId(resourceId);
apiFileResource.setResourceType(apiResourceType.name());
apiFileResource.setProjectId(projectId);
apiFileResource.setCreateTime(System.currentTimeMillis());
apiFileResource.setFileName(fileName);
apiFileResources.add(apiFileResource);
addFileMap.put(fileId, fileName);
return apiFileResource;
}).toList();
apiFileResourceMapper.batchInsert(apiFileResources);
}
if (CollectionUtils.isNotEmpty(apiFileResources)) {
apiFileResourceMapper.batchInsert(apiFileResources);
}
// 上传文件到对象存储
uploadFileResource(resourceUpdateRequest.getFolder(), addFileMap);

View File

@ -263,6 +263,8 @@ public class ApiDebugControllerTests extends BaseTest {
request.setDeleteFileIds(null);
request.setUnLinkFileIds(null);
this.requestPostWithOk(DEFAULT_UPDATE, request);
// 校验 UploadFileIds 参数重复关联
this.requestPostWithOk(DEFAULT_UPDATE, request);
// 校验请求成功数据
assertUpdateApiDebug(request, msHttpElement, request.getId());
assertUploadFile(addApiDebug.getId(), List.of(fileId));