修复用户导入文件时能查询却无法导入的bug;新增获取公网ip的方式;更新依赖
This commit is contained in:
parent
c17dfde4e2
commit
a3927f4d71
4
pom.xml
4
pom.xml
@ -14,7 +14,7 @@
|
||||
<name>scalable-network-storage-site</name>
|
||||
<description>scalable-network-storage-site</description>
|
||||
<properties>
|
||||
<java.version>17</java.version>
|
||||
<java.version>21</java.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
@ -65,7 +65,7 @@
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
<version>5.8.20</version>
|
||||
<version>5.8.26</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
||||
@ -1205,7 +1205,7 @@ public class CommunicateToMainService {
|
||||
if(storagePath.startsWith(file.getParentFile().getPath()))
|
||||
fileNode.setPath("");
|
||||
else
|
||||
fileNode.setPath(file.getParentFile().getPath().replace(storagePath, ""));
|
||||
fileNode.setPath(file.getParentFile().getPath().replace(storagePath, "") + "/");
|
||||
response.success(objectMapper.valueToTree(fileNode));
|
||||
}
|
||||
case ShareFileQueryMessage.QUERY_SHARE_FILES -> {
|
||||
|
||||
@ -19,14 +19,15 @@ import oshi.hardware.HWDiskStore;
|
||||
import oshi.hardware.NetworkIF;
|
||||
import oshi.software.os.OperatingSystem;
|
||||
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.RandomAccessFile;
|
||||
import java.io.*;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@Data
|
||||
@Slf4j
|
||||
@ -50,12 +51,14 @@ public class IoUtil {
|
||||
static long write;
|
||||
static long writeNow;
|
||||
|
||||
static ScheduledExecutorService thread;
|
||||
|
||||
static {
|
||||
init();
|
||||
}
|
||||
|
||||
public static void init(){
|
||||
ScheduledExecutorService thread = Executors.newScheduledThreadPool(1);
|
||||
thread = Executors.newScheduledThreadPool(1);
|
||||
List<NetworkIF> networkIFs = OshiUtil.getNetworkIFs();
|
||||
cpuInfo = OshiUtil.getCpuInfo();
|
||||
globalMemory = OshiUtil.getMemory();
|
||||
@ -106,7 +109,16 @@ public class IoUtil {
|
||||
|
||||
public static PairMessage generatePairMessage(){
|
||||
PairMessage pairMessage = new PairMessage();
|
||||
pairMessage.setIp(networkIF.getIPv4addr()[0].split("/")[0]);
|
||||
String ip = networkIF.getIPv4addr()[0].split("/")[0];
|
||||
String privateIPPattern = "(^10\\.)|(^172\\.1[6-9]\\.)|(^172\\.2[0-9]\\.)|(^172\\.3[0-1]\\.)|(^192\\.168\\.)";
|
||||
if(Pattern.compile(privateIPPattern).matcher(ip).find())
|
||||
try {
|
||||
ip = getPublicIP();
|
||||
}catch (IOException | URISyntaxException e){
|
||||
log.info("当前机器网卡为内网ip且无法获取公网ip,程序退出");
|
||||
Runtime.getRuntime().exit(1);
|
||||
}
|
||||
pairMessage.setIp(ip);
|
||||
pairMessage.setHostname(NetUtil.getLocalHostName());
|
||||
|
||||
OperatingSystem os = OshiUtil.getOs();
|
||||
@ -120,6 +132,25 @@ public class IoUtil {
|
||||
return pairMessage;
|
||||
}
|
||||
|
||||
public static String getPublicIP() throws IOException, URISyntaxException {
|
||||
// 通过访问一个提供公网IP查询的服务,例如 httpbin.org
|
||||
URL url = new URI("https://httpbin.org/ip").toURL();
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
|
||||
|
||||
// 读取返回的 JSON 数据
|
||||
StringBuilder response = new StringBuilder();
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
response.append(line);
|
||||
}
|
||||
|
||||
// 从返回的 JSON 数据中提取公网IP
|
||||
String json = response.toString();
|
||||
int startIndex = json.indexOf("\"origin\":") + 10;
|
||||
int endIndex = json.indexOf("\"", startIndex + 1);
|
||||
return json.substring(startIndex + 1, endIndex);
|
||||
}
|
||||
|
||||
public static StatusMessage generateStatusMessage(int id, String path){
|
||||
StatusMessage statusMessage = new StatusMessage();
|
||||
statusMessage.setId(id);
|
||||
|
||||
Binary file not shown.
Loading…
Reference in New Issue
Block a user