feat: 增强 RemoteApp 支持用户名;更新 light-code 路由处理逻辑;优化 SyncBase 文件路径检查

This commit is contained in:
2026-03-05 02:45:51 +08:00
parent c2c6d4a7d3
commit 3b383639d6
4 changed files with 19 additions and 5 deletions

View File

@@ -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 内置的自动重连机制

View File

@@ -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,

View File

@@ -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);