From 47ec0a77daad81c22259b68dcd9b5c43759e53f3 Mon Sep 17 00:00:00 2001 From: "song.tianyang" Date: Tue, 23 Mar 2021 21:27:19 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20API=E6=96=87=E6=A1=A3=E5=88=86=E4=BA=AB?= =?UTF-8?q?=E9=93=BE=E6=8E=A5=E5=A4=B1=E6=95=88=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit API文档分享链接失效的问题 --- .../api/dto/definition/parse/HarParser.java | 28 +++++++++++++------ .../api/service/ApiDocumentService.java | 2 +- frontend/src/business/components/xpack | 2 +- frontend/src/document/Document.vue | 15 +++++++--- 4 files changed, 33 insertions(+), 14 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/parse/HarParser.java b/backend/src/main/java/io/metersphere/api/dto/definition/parse/HarParser.java index ade15abc36..5d84a6ec2a 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/parse/HarParser.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/parse/HarParser.java @@ -68,24 +68,36 @@ public class HarParser extends HarAbstractParser { harEntryList = har.log.entries; } + List savedUrl = new ArrayList<>(); + for (HarEntry entry : harEntryList) { HarRequest harRequest = entry.request; + String url = harRequest.url; + if(url == null){ + continue; + } + + try { + url = URLDecoder.decode(url,"UTF-8"); + }catch (Exception e){ + } + + if(savedUrl.contains(harRequest.url)){ + continue; + }else { + savedUrl.add(harRequest.url); + } //默认取路径的最后一块 String reqName = ""; if (harRequest.url != null) { - String[] nameArr = harRequest.url.split("/"); + String[] nameArr = url.split("/"); reqName = nameArr[nameArr.length - 1]; - //然后进行转码解码 - try { - reqName = URLDecoder.decode(reqName,"UTF-8"); - }catch (Exception e){ - } } if (harRequest != null) { - MsHTTPSamplerProxy request = super.buildRequest(reqName, harRequest.url, harRequest.method); - ApiDefinitionWithBLOBs apiDefinition = super.buildApiDefinition(request.getId(), reqName, harRequest.url, harRequest.method, importRequest); + MsHTTPSamplerProxy request = super.buildRequest(reqName, url, harRequest.method); + ApiDefinitionWithBLOBs apiDefinition = super.buildApiDefinition(request.getId(), reqName, url, harRequest.method, importRequest); parseParameters(harRequest, request); parseRequestBody(harRequest, request.getBody()); addBodyHeader(request); diff --git a/backend/src/main/java/io/metersphere/api/service/ApiDocumentService.java b/backend/src/main/java/io/metersphere/api/service/ApiDocumentService.java index 55a4c9d9a0..6f76d24cc3 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiDocumentService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiDocumentService.java @@ -372,7 +372,7 @@ public class ApiDocumentService { ApiDocumentShareDTO returnDTO = new ApiDocumentShareDTO(); if (!StringUtils.isEmpty(apiShare.getShareApiId())) { BaseSystemConfigDTO baseSystemConfigDTO = systemParameterService.getBaseInfo(); - String url = "/#/apiDocumentInfo?documentId=" + apiShare.getId(); + String url = "?" + apiShare.getId(); returnDTO.setId(apiShare.getId()); returnDTO.setShareUrl(url); } diff --git a/frontend/src/business/components/xpack b/frontend/src/business/components/xpack index bc5735a2eb..93adcdc32a 160000 --- a/frontend/src/business/components/xpack +++ b/frontend/src/business/components/xpack @@ -1 +1 @@ -Subproject commit bc5735a2eb796640bde400ae6cafca6229672905 +Subproject commit 93adcdc32a98967ddff208bf5f8868c5e3c063da diff --git a/frontend/src/document/Document.vue b/frontend/src/document/Document.vue index 3cca730ffd..1b778a21df 100644 --- a/frontend/src/document/Document.vue +++ b/frontend/src/document/Document.vue @@ -40,10 +40,17 @@ export default { }, methods: { getUrlParam(){ - let queryParams =this.$route.query; - let documentIdParam = queryParams['documentId']; - this.documentId = queryParams['documentId']; - return documentIdParam; + let herfUrl = window.location.href; + if(herfUrl.indexOf("?") > 0){ + let paramArr = herfUrl.split("?"); + if(paramArr.length > 1){ + let documentId = paramArr[1]; + if(documentId.indexOf("#") > 0){ + documentId = documentId.split("#")[0]; + } + this.documentId = documentId; + } + } }, selectDocumentInfo(){ this.getUrlParam();