@lppx/lanshare 1.0.3 → 1.0.5

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.
@@ -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
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.0.3",
6
+ "version": "1.0.5",
7
7
  "description": "这是一个局域网分享工具",
8
8
  "bin": {
9
9
  "lanshare": "dist/src/cli.js",
@@ -28,7 +28,7 @@
28
28
  "@types/socket.io": "^3.0.1",
29
29
  "commander": "^12.0.0",
30
30
  "express": "^4.18.2",
31
- "multer": "^1.4.5-lts.1",
31
+ "multer": "2.0.2",
32
32
  "open": "^11.0.0",
33
33
  "prompts": "^2.4.2",
34
34
  "socket.io": "^4.8.3",
@@ -36,7 +36,7 @@
36
36
  },
37
37
  "devDependencies": {
38
38
  "@types/express": "^4.17.21",
39
- "@types/multer": "^1.4.11",
39
+ "@types/multer": "^2.0.0",
40
40
  "@types/node": "^20.11.0",
41
41
  "@types/prompts": "^2.4.9",
42
42
  "@types/winston": "^2.4.4",
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
  }
@@ -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
- <button class="action-btn delete" onclick="deleteFile('${file.name}')" title="删除">
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
@@ -1,9 +1,11 @@
1
1
  // #region 初始化
2
- function init() {
2
+ async function init() {
3
3
  initSocket();
4
4
  initUpload();
5
+
6
+ // 先加载服务器信息(判断是否本地客户端),再加载文件列表
7
+ await loadServerInfo();
5
8
  loadFiles();
6
- loadServerInfo();
7
9
 
8
10
  // 定期刷新文件列表
9
11
  setInterval(loadFiles, 5000);