fix(socket): 添加 MicroPython 请求端口有效性检查,无效端口不报错

This commit is contained in:
yczpf2019
2026-01-24 20:44:03 +08:00
parent 9bcc49059e
commit 5456419bb3

View File

@@ -173,6 +173,12 @@ export default class Socket {
}); });
socket.on('micropython.burn', async (config, callback) => { 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 shell = this.#shellMicroPython_.getItem(socket.id);
const [error, result] = await to(shell.burn(config)); const [error, result] = await to(shell.burn(config));
error && Debug.error(error); error && Debug.error(error);
@@ -180,6 +186,12 @@ export default class Socket {
}); });
socket.on('micropython.upload', async (config, callback) => { 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); const shell = this.#shellMicroPython_.getItem(socket.id);
let { filePath = '', libraries = {} } = config; let { filePath = '', libraries = {} } = config;
filePath = MString.tpl(filePath, { filePath = MString.tpl(filePath, {