mirror of
https://gitee.com/czh-dev/upload-hub
synced 2026-09-08 08:57:16 +08:00
fix:修改共享地址端口
This commit is contained in:
@@ -164,18 +164,14 @@ public class FileController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/shareAddress")
|
@GetMapping("/shareAddress")
|
||||||
public Result<?> getShareAddress() {
|
public Result<?> getShareAddress(Integer clientPort) {
|
||||||
String ip;
|
String ip = getLocalIpAddress();
|
||||||
try {
|
String port = clientPort != null ? clientPort.toString() : serverPort;
|
||||||
ip = getLocalIpAddress();
|
return Result.success("http://" + ip + ":" + port);
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("获取本地IP地址失败:{}", e.getMessage(), e);
|
|
||||||
ip = "localhost";
|
|
||||||
}
|
|
||||||
return Result.success("http://" + ip + ":" + serverPort);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getLocalIpAddress() throws Exception {
|
private String getLocalIpAddress() {
|
||||||
|
try {
|
||||||
Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
|
Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
|
||||||
while (interfaces.hasMoreElements()) {
|
while (interfaces.hasMoreElements()) {
|
||||||
NetworkInterface networkInterface = interfaces.nextElement();
|
NetworkInterface networkInterface = interfaces.nextElement();
|
||||||
@@ -195,6 +191,9 @@ public class FileController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
} catch (Exception e) {
|
||||||
|
log.error("获取本地IP地址失败:{}", e.getMessage(), e);
|
||||||
|
}
|
||||||
|
return "127.0.0.1";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -215,7 +215,8 @@ const getShareStatus = () => {
|
|||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
const shareAddress = () => {
|
const shareAddress = () => {
|
||||||
return http.get("/file/shareAddress");
|
const clientPort = window.location.port;
|
||||||
|
return http.get("/file/shareAddress?clientPort=" + clientPort);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user