mirror of
https://gitee.com/czh-dev/upload-hub
synced 2026-09-08 00:47:02 +08:00
fix:修改共享地址端口
This commit is contained in:
@@ -164,37 +164,36 @@ 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() {
|
||||||
Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
|
try {
|
||||||
while (interfaces.hasMoreElements()) {
|
Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
|
||||||
NetworkInterface networkInterface = interfaces.nextElement();
|
while (interfaces.hasMoreElements()) {
|
||||||
// 跳过回环接口和未启用的接口
|
NetworkInterface networkInterface = interfaces.nextElement();
|
||||||
if (networkInterface.isLoopback() || !networkInterface.isUp()) {
|
// 跳过回环接口和未启用的接口
|
||||||
continue;
|
if (networkInterface.isLoopback() || !networkInterface.isUp()) {
|
||||||
}
|
continue;
|
||||||
Enumeration<InetAddress> addresses = networkInterface.getInetAddresses();
|
}
|
||||||
while (addresses.hasMoreElements()) {
|
Enumeration<InetAddress> addresses = networkInterface.getInetAddresses();
|
||||||
InetAddress addr = addresses.nextElement();
|
while (addresses.hasMoreElements()) {
|
||||||
if (addr instanceof Inet4Address && !addr.isLoopbackAddress()) {
|
InetAddress addr = addresses.nextElement();
|
||||||
String ip = addr.getHostAddress();
|
if (addr instanceof Inet4Address && !addr.isLoopbackAddress()) {
|
||||||
if (ip.startsWith("192.168.") || ip.startsWith("10.") ||
|
String ip = addr.getHostAddress();
|
||||||
(ip.startsWith("172.") && Integer.parseInt(ip.split("\\.")[1]) >= 16 && Integer.parseInt(ip.split("\\.")[1]) <= 31)) {
|
if (ip.startsWith("192.168.") || ip.startsWith("10.") ||
|
||||||
return ip;
|
(ip.startsWith("172.") && Integer.parseInt(ip.split("\\.")[1]) >= 16 && Integer.parseInt(ip.split("\\.")[1]) <= 31)) {
|
||||||
|
return ip;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("获取本地IP地址失败:{}", e.getMessage(), e);
|
||||||
}
|
}
|
||||||
return null;
|
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