|
|
@@ -1,5 +1,7 @@
|
|
1
|
1
|
package com.ruoyi.web.kb.support;
|
|
2
|
2
|
|
|
|
3
|
+import java.net.URI;
|
|
|
4
|
+import java.net.URISyntaxException;
|
|
3
|
5
|
import com.ruoyi.common.exception.ServiceException;
|
|
4
|
6
|
import com.ruoyi.common.utils.StringUtils;
|
|
5
|
7
|
|
|
|
@@ -8,6 +10,12 @@ import com.ruoyi.common.utils.StringUtils;
|
|
8
|
10
|
*/
|
|
9
|
11
|
public final class KbFileUrlResolver
|
|
10
|
12
|
{
|
|
|
13
|
+ /** 外网域名:同步知识库时若正文 URL 含此串,则改写为内网地址供知识库拉取 */
|
|
|
14
|
+ private static final String EXTRANET_HOST = "bqxm.alafarms.com";
|
|
|
15
|
+
|
|
|
16
|
+ /** 内网文件服务地址(含端口) */
|
|
|
17
|
+ private static final String INTRANET_HOST = "192.168.153.16:443";
|
|
|
18
|
+
|
|
11
|
19
|
private KbFileUrlResolver()
|
|
12
|
20
|
{
|
|
13
|
21
|
}
|
|
|
@@ -25,7 +33,7 @@ public final class KbFileUrlResolver
|
|
25
|
33
|
String p = contentFileUrl.trim();
|
|
26
|
34
|
if (StringUtils.startsWithIgnoreCase(p, "http://") || StringUtils.startsWithIgnoreCase(p, "https://"))
|
|
27
|
35
|
{
|
|
28
|
|
- return p;
|
|
|
36
|
+ return rewriteExtranetToIntranetIfNeeded(contentFileUrl, p);
|
|
29
|
37
|
}
|
|
30
|
38
|
if (StringUtils.isEmpty(fileUrlBase))
|
|
31
|
39
|
{
|
|
|
@@ -37,6 +45,48 @@ public final class KbFileUrlResolver
|
|
37
|
45
|
base = base.substring(0, base.length() - 1);
|
|
38
|
46
|
}
|
|
39
|
47
|
String path = p.startsWith("/") ? p : "/" + p;
|
|
40
|
|
- return base + path;
|
|
|
48
|
+ return rewriteExtranetToIntranetIfNeeded(contentFileUrl, base + path);
|
|
|
49
|
+ }
|
|
|
50
|
+
|
|
|
51
|
+ /**
|
|
|
52
|
+ * 正文 URL 含外网域名时,将解析结果中的域名替换为内网地址,便于知识库节点拉取文件。
|
|
|
53
|
+ */
|
|
|
54
|
+ static String rewriteExtranetToIntranetIfNeeded(String contentFileUrl, String resolvedUrl)
|
|
|
55
|
+ {
|
|
|
56
|
+ if (StringUtils.isEmpty(contentFileUrl) || StringUtils.isEmpty(resolvedUrl))
|
|
|
57
|
+ {
|
|
|
58
|
+ return resolvedUrl;
|
|
|
59
|
+ }
|
|
|
60
|
+ if (!contentFileUrl.contains(EXTRANET_HOST))
|
|
|
61
|
+ {
|
|
|
62
|
+ return resolvedUrl;
|
|
|
63
|
+ }
|
|
|
64
|
+ try
|
|
|
65
|
+ {
|
|
|
66
|
+ URI uri = new URI(resolvedUrl);
|
|
|
67
|
+ if (uri.getHost() == null || !EXTRANET_HOST.equalsIgnoreCase(uri.getHost()))
|
|
|
68
|
+ {
|
|
|
69
|
+ return resolvedUrl;
|
|
|
70
|
+ }
|
|
|
71
|
+ StringBuilder sb = new StringBuilder();
|
|
|
72
|
+ sb.append(uri.getScheme()).append("://").append(INTRANET_HOST);
|
|
|
73
|
+ if (uri.getRawPath() != null)
|
|
|
74
|
+ {
|
|
|
75
|
+ sb.append(uri.getRawPath());
|
|
|
76
|
+ }
|
|
|
77
|
+ if (uri.getRawQuery() != null)
|
|
|
78
|
+ {
|
|
|
79
|
+ sb.append('?').append(uri.getRawQuery());
|
|
|
80
|
+ }
|
|
|
81
|
+ if (uri.getRawFragment() != null)
|
|
|
82
|
+ {
|
|
|
83
|
+ sb.append('#').append(uri.getRawFragment());
|
|
|
84
|
+ }
|
|
|
85
|
+ return sb.toString();
|
|
|
86
|
+ }
|
|
|
87
|
+ catch (URISyntaxException e)
|
|
|
88
|
+ {
|
|
|
89
|
+ return resolvedUrl;
|
|
|
90
|
+ }
|
|
41
|
91
|
}
|
|
42
|
92
|
}
|