diff --git a/assistant/src/module/assistant/local-app-manager/assistant-app.ts b/assistant/src/module/assistant/local-app-manager/assistant-app.ts index d4400f0..4182971 100644 --- a/assistant/src/module/assistant/local-app-manager/assistant-app.ts +++ b/assistant/src/module/assistant/local-app-manager/assistant-app.ts @@ -130,10 +130,11 @@ export class AssistantApp extends Manager { } const url = new URL(shareUrl); const id = config?.app?.id; - if (token && url && id) { + if (url && id) { const remoteApp = new RemoteApp({ url: url.toString(), token, + username: config?.auth?.username || '', id, app: this.mainApp, // 使用 RemoteApp 内置的自动重连机制 diff --git a/assistant/src/module/light-code/index.ts b/assistant/src/module/light-code/index.ts index b73176d..463d2b1 100644 --- a/assistant/src/module/light-code/index.ts +++ b/assistant/src/module/light-code/index.ts @@ -162,8 +162,8 @@ export const initLightCode = async (opts: Opts) => { metadata.source = 'light-code'; metadata['light-code'] = { id: file.id - } - app.route({ + }; + (app as App).route({ id: routerItem.id, path: `${routerItem.id}__${routerItem.path}`, key: routerItem.key, diff --git a/assistant/src/module/remote-app/remote-app.ts b/assistant/src/module/remote-app/remote-app.ts index af60dc0..b86293f 100644 --- a/assistant/src/module/remote-app/remote-app.ts +++ b/assistant/src/module/remote-app/remote-app.ts @@ -4,6 +4,7 @@ type RemoteAppOptions = { app?: App; url?: string; token?: string; + username?: string; emitter?: EventEmitter; id?: string; /** 是否启用自动重连,默认 true */ @@ -24,6 +25,7 @@ export class RemoteApp { mainApp: App; url: string; id: string; + username: string; emitter: EventEmitter; isConnected: boolean; ws: WebSocket; @@ -43,12 +45,17 @@ export class RemoteApp { const token = opts.token; const url = opts.url; const id = opts.id; + const username = opts.username; + this.username = username; this.emitter = opts?.emitter || new EventEmitter(); const _url = new URL(url); if (token) { _url.searchParams.set('token', token); } _url.searchParams.set('id', id); + if (!token && !username) { + console.error(`[remote-app] 不存在用户名和token ${id}. 权限认证会失败。`); + } this.url = _url.toString(); this.id = id; // 初始化重连相关配置 @@ -223,6 +230,7 @@ export class RemoteApp { listenProxy() { const remoteApp = this; const app = this.mainApp; + const username = this.username; const listenFn = async (event: any) => { try { const data = event.toString(); @@ -262,8 +270,10 @@ export class RemoteApp { }; remoteApp.json({ id: this.id, - type: 'registryClient' + type: 'registryClient', + username: username, }); + console.log(`远程应用 ${this.id} (${username}) 已注册到主应用,等待消息...`); remoteApp.emitter.on('message', listenFn); const closeMessage = () => { remoteApp.emitter.off('message', listenFn); diff --git a/src/command/sync/modules/base.ts b/src/command/sync/modules/base.ts index 23f71d4..9fac86f 100644 --- a/src/command/sync/modules/base.ts +++ b/src/command/sync/modules/base.ts @@ -116,7 +116,10 @@ export class SyncBase { const syncList = syncKeys.map((key) => { const value = sync[key]; const filepath = path.join(this.#dir, key); // 文件的路径 - if (filepath.includes('node_modules') || filepath.includes('.git')) { + const dirs = path.dirname(filepath).split(path.sep); + const hasGit = dirs.includes('.git'); + const hasNodeModules = dirs.includes('node_modules'); + if (hasGit || hasNodeModules) { return null; } if (typeof value === 'string') {