@lppx/lanshare 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/routers/files.js +3 -1
- package/package.json +1 -1
- package/public/js/api.js +9 -0
- package/public/js/file-list.js +2 -2
- package/public/js/main.js +4 -2
|
@@ -109,10 +109,12 @@ function createFilesRouter(uploadDir) {
|
|
|
109
109
|
// #endregion
|
|
110
110
|
// #region 获取服务器信息
|
|
111
111
|
router.get('/info', (_req, res) => {
|
|
112
|
+
const clientIP = _req.ip || _req.socket.remoteAddress || 'unknown';
|
|
112
113
|
res.json({
|
|
113
114
|
ip: getLocalIP(),
|
|
114
115
|
hostname: os_1.default.hostname(),
|
|
115
|
-
platform: os_1.default.platform()
|
|
116
|
+
platform: os_1.default.platform(),
|
|
117
|
+
clientIP: clientIP
|
|
116
118
|
});
|
|
117
119
|
});
|
|
118
120
|
// #endregion
|
package/package.json
CHANGED
package/public/js/api.js
CHANGED
|
@@ -19,6 +19,8 @@ async function loadDevices() {
|
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
let isLocalClient = false;
|
|
23
|
+
|
|
22
24
|
async function loadServerInfo() {
|
|
23
25
|
try {
|
|
24
26
|
const response = await fetch('/info');
|
|
@@ -27,6 +29,13 @@ async function loadServerInfo() {
|
|
|
27
29
|
const ipText = document.getElementById('ipText');
|
|
28
30
|
ipText.textContent = info.ip;
|
|
29
31
|
}
|
|
32
|
+
// 判断客户端是否是本地(服务器所在机器)
|
|
33
|
+
if (info.clientIP && info.ip) {
|
|
34
|
+
// 处理 IPv6 映射的 IPv4 地址 (::ffff:192.168.1.1 -> 192.168.1.1)
|
|
35
|
+
const clientIP = info.clientIP.replace('::ffff:', '');
|
|
36
|
+
isLocalClient = (clientIP === info.ip || clientIP === '127.0.0.1' || clientIP === '::1');
|
|
37
|
+
console.log('客户端IP:', clientIP, '服务器IP:', info.ip, '是否本地:', isLocalClient);
|
|
38
|
+
}
|
|
30
39
|
} catch (error) {
|
|
31
40
|
console.error('加载服务器信息失败:', error);
|
|
32
41
|
}
|
package/public/js/file-list.js
CHANGED
|
@@ -49,11 +49,11 @@ function renderFileList(files) {
|
|
|
49
49
|
<path d="M3 17V19C3 20.1046 3.89543 21 5 21H19C20.1046 21 21 20.1046 21 19V17" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
|
|
50
50
|
</svg>
|
|
51
51
|
</button>
|
|
52
|
-
|
|
52
|
+
${isLocalClient ? `<button class="action-btn delete" onclick="deleteFile('${file.name}')" title="删除">
|
|
53
53
|
<svg width="20" height="20" viewBox="0 0 24 24" fill="none">
|
|
54
54
|
<path d="M6 6L18 18M6 18L18 6" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
|
|
55
55
|
</svg>
|
|
56
|
-
</button
|
|
56
|
+
</button>` : ''}
|
|
57
57
|
</div>
|
|
58
58
|
</div>
|
|
59
59
|
`;
|
package/public/js/main.js
CHANGED