fix(socket): 添加 MicroPython 请求端口有效性检查,无效端口不报错
This commit is contained in:
@@ -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, {
|
||||
|
||||
Reference in New Issue
Block a user