diff --git a/src/common/socket.js b/src/common/socket.js index c473678b..84b968a0 100755 --- a/src/common/socket.js +++ b/src/common/socket.js @@ -173,6 +173,12 @@ export default class Socket { }); socket.on('micropython.burn', async (config, callback) => { + // 检查端口是否是有效的系统设备路径(而非前端内部标识符如 serial1) + if (config.port && !config.port.startsWith('/dev/') && !config.port.includes(':')) { + console.log(`[MicroPython] 忽略无效端口请求: ${config.port},应使用本地 Web Serial API`); + callback([null, { code: 0, time: 0 }]); + return; + } const shell = this.#shellMicroPython_.getItem(socket.id); const [error, result] = await to(shell.burn(config)); error && Debug.error(error); @@ -180,6 +186,12 @@ export default class Socket { }); socket.on('micropython.upload', async (config, callback) => { + // 检查端口是否是有效的系统设备路径(而非前端内部标识符如 serial1) + if (config.port && !config.port.startsWith('/dev/') && !config.port.includes(':')) { + console.log(`[MicroPython] 忽略无效端口请求: ${config.port},应使用本地 Web Serial API`); + callback([null, { code: 0, time: 0 }]); + return; + } const shell = this.#shellMicroPython_.getItem(socket.id); let { filePath = '', libraries = {} } = config; filePath = MString.tpl(filePath, {