fix: markdown旧数据图片无法显示

--bug=1009605 --user=陈建星 【测试跟踪】缺陷管理,有带图片的缺陷,console就会有报错 https://www.tapd.cn/55049933/s/1091852
This commit is contained in:
chenjianxing 2022-01-14 15:09:39 +08:00 committed by zhangdahai112
parent b47a09f1a4
commit b79c972da6
6 changed files with 32 additions and 16 deletions

View File

@ -68,7 +68,7 @@
<select id="getIssueForSync" resultType="io.metersphere.base.domain.IssuesDao">
select id,platform, platform_id
from issues
where project_id = #{projectId} and platform != 'Local';
where project_id = #{projectId} and platform != 'Local' and (platform_status != 'delete' or platform_status is null);
</select>
<select id="selectForPlanReport" resultType="io.metersphere.track.dto.PlanReportIssueDTO">
select id,status,platform_status,platform from issues where resource_id = #{planId} and ( platform_status != 'delete' or platform_status is null);

View File

@ -15,7 +15,7 @@ public class ShiroUtils {
public static void loadBaseFilterChain(Map<String, String> filterChainDefinitionMap) {
filterChainDefinitionMap.put("/resource/md/get", "anon");
filterChainDefinitionMap.put("/resource/md/get/**", "anon");
filterChainDefinitionMap.put("/*.worker.js", "anon");
filterChainDefinitionMap.put("/login", "anon");
filterChainDefinitionMap.put("/signin", "anon");

View File

@ -25,6 +25,16 @@ public class ResourceController {
return resourceService.getMdImage(fileName);
}
/**
* 兼容旧版本
* @param fileName
* @return
*/
@GetMapping(value = "/md/get/{fileName}")
public ResponseEntity<FileSystemResource> getFileCompatible(@PathVariable("fileName") String fileName) {
return resourceService.getMdImage(fileName);
}
@GetMapping("/md/delete/{fileName}")
public void delete(@PathVariable("fileName") String fileName) {
resourceService.mdDelete(fileName);

View File

@ -37,6 +37,7 @@ import org.springframework.web.client.RestTemplate;
import javax.net.ssl.SSLContext;
import java.io.File;
import java.net.URLDecoder;
import java.security.cert.X509Certificate;
import java.util.*;
import java.util.function.Function;
@ -314,12 +315,18 @@ public abstract class AbstractIssuePlatform implements IssuesPlatform {
String result = input;
while (matcher.find()) {
String url = matcher.group(2);
if (url.contains("/resource/md/get/")) {
if (url.contains("/resource/md/get/")) { // 兼容旧数据
String path = url.substring(url.indexOf("/resource/md/get/"));
String name = path.substring(path.indexOf("/resource/md/get/") + 26);
String mdLink = "![" + name + "](" + path + ")";
result = matcher.replaceFirst(mdLink);
matcher = pattern.matcher(result);
} else if(url.contains("/resource/md/get")) { //新数据走这里
String path = url.substring(url.indexOf("/resource/md/get"));
String name = path.substring(path.indexOf("/resource/md/get") + 35);
String mdLink = "![" + name + "](" + path + ")";
result = matcher.replaceFirst(mdLink);
matcher = pattern.matcher(result);
}
}
return result;
@ -336,9 +343,12 @@ public abstract class AbstractIssuePlatform implements IssuesPlatform {
while (matcher.find()) {
try {
String path = matcher.group(2);
if (path.contains("/resource/md/get/")) {
if (path.contains("/resource/md/get/")) { // 兼容旧数据
String name = path.substring(path.indexOf("/resource/md/get/") + 17);
files.add(new File(FileUtils.MD_IMAGE_DIR + "/" + name));
} else if (path.contains("/resource/md/get")) { // 新数据走这里
String name = path.substring(path.indexOf("/resource/md/get") + 26);
files.add(new File(FileUtils.MD_IMAGE_DIR + "/" + URLDecoder.decode(name, "UTF-8")));
}
} catch (Exception e) {
LogUtil.error(e.getMessage(), e);

View File

@ -183,10 +183,6 @@ public class TapdPlatform extends AbstractIssuePlatform {
@Override
public void syncIssues(Project project, List<IssuesDao> tapdIssues) {
int pageNum = 1;
int limit = 50;
int count = 50;
Map<String, String> idMap = tapdIssues.stream()
.collect(Collectors.toMap(IssuesDao::getPlatformId, IssuesDao::getId));
@ -194,17 +190,17 @@ public class TapdPlatform extends AbstractIssuePlatform {
.map(IssuesDao::getPlatformId)
.collect(Collectors.toList());
if (CollectionUtils.isEmpty(ids)) {
return;
}
if (CollectionUtils.isEmpty(ids)) return;
Map<String, String> statusMap = tapdClient.getStatusMap(project.getTapdId());
while (count == limit) {
TapdGetIssueResponse result = tapdClient.getIssueForPageByIds(project.getTapdId(), pageNum, limit, ids);
int index = 0;
int limit = 50;
while (index < ids.size()) {
List<String> subIds = ids.subList(index, (index + limit) > ids.size() ? ids.size() : (index + limit));
TapdGetIssueResponse result = tapdClient.getIssueForPageByIds(project.getTapdId(), 1, limit, subIds);
List<JSONObject> datas = result.getData();
count = datas.size();
pageNum++;
datas.forEach(issue -> {
JSONObject bug = issue.getJSONObject("Bug");
String platformId = bug.getString("id");
@ -215,6 +211,7 @@ public class TapdPlatform extends AbstractIssuePlatform {
issuesMapper.updateByPrimaryKeySelective(updateIssue);
ids.remove(platformId);
});
index += limit;
}
// 查不到的设置为删除
ids.forEach((id) -> {

View File

@ -134,7 +134,6 @@ public abstract class JiraAbstractClient extends BaseClient {
response = restTemplate.exchange(getBaseUrl() + "/issue/" + issueKey + "/attachments", HttpMethod.POST, requestEntity, String.class);
} catch (Exception e) {
LogUtil.error(e.getMessage(), e);
MSException.throwException(e.getMessage());
}
System.out.println(response);
}