feat: 增强 RemoteApp 支持用户名;更新 light-code 路由处理逻辑;优化 SyncBase 文件路径检查
This commit is contained in:
@@ -130,10 +130,11 @@ export class AssistantApp extends Manager {
|
|||||||
}
|
}
|
||||||
const url = new URL(shareUrl);
|
const url = new URL(shareUrl);
|
||||||
const id = config?.app?.id;
|
const id = config?.app?.id;
|
||||||
if (token && url && id) {
|
if (url && id) {
|
||||||
const remoteApp = new RemoteApp({
|
const remoteApp = new RemoteApp({
|
||||||
url: url.toString(),
|
url: url.toString(),
|
||||||
token,
|
token,
|
||||||
|
username: config?.auth?.username || '',
|
||||||
id,
|
id,
|
||||||
app: this.mainApp,
|
app: this.mainApp,
|
||||||
// 使用 RemoteApp 内置的自动重连机制
|
// 使用 RemoteApp 内置的自动重连机制
|
||||||
|
|||||||
@@ -162,8 +162,8 @@ export const initLightCode = async (opts: Opts) => {
|
|||||||
metadata.source = 'light-code';
|
metadata.source = 'light-code';
|
||||||
metadata['light-code'] = {
|
metadata['light-code'] = {
|
||||||
id: file.id
|
id: file.id
|
||||||
}
|
};
|
||||||
app.route({
|
(app as App).route({
|
||||||
id: routerItem.id,
|
id: routerItem.id,
|
||||||
path: `${routerItem.id}__${routerItem.path}`,
|
path: `${routerItem.id}__${routerItem.path}`,
|
||||||
key: routerItem.key,
|
key: routerItem.key,
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ type RemoteAppOptions = {
|
|||||||
app?: App;
|
app?: App;
|
||||||
url?: string;
|
url?: string;
|
||||||
token?: string;
|
token?: string;
|
||||||
|
username?: string;
|
||||||
emitter?: EventEmitter;
|
emitter?: EventEmitter;
|
||||||
id?: string;
|
id?: string;
|
||||||
/** 是否启用自动重连,默认 true */
|
/** 是否启用自动重连,默认 true */
|
||||||
@@ -24,6 +25,7 @@ export class RemoteApp {
|
|||||||
mainApp: App;
|
mainApp: App;
|
||||||
url: string;
|
url: string;
|
||||||
id: string;
|
id: string;
|
||||||
|
username: string;
|
||||||
emitter: EventEmitter;
|
emitter: EventEmitter;
|
||||||
isConnected: boolean;
|
isConnected: boolean;
|
||||||
ws: WebSocket;
|
ws: WebSocket;
|
||||||
@@ -43,12 +45,17 @@ export class RemoteApp {
|
|||||||
const token = opts.token;
|
const token = opts.token;
|
||||||
const url = opts.url;
|
const url = opts.url;
|
||||||
const id = opts.id;
|
const id = opts.id;
|
||||||
|
const username = opts.username;
|
||||||
|
this.username = username;
|
||||||
this.emitter = opts?.emitter || new EventEmitter();
|
this.emitter = opts?.emitter || new EventEmitter();
|
||||||
const _url = new URL(url);
|
const _url = new URL(url);
|
||||||
if (token) {
|
if (token) {
|
||||||
_url.searchParams.set('token', token);
|
_url.searchParams.set('token', token);
|
||||||
}
|
}
|
||||||
_url.searchParams.set('id', id);
|
_url.searchParams.set('id', id);
|
||||||
|
if (!token && !username) {
|
||||||
|
console.error(`[remote-app] 不存在用户名和token ${id}. 权限认证会失败。`);
|
||||||
|
}
|
||||||
this.url = _url.toString();
|
this.url = _url.toString();
|
||||||
this.id = id;
|
this.id = id;
|
||||||
// 初始化重连相关配置
|
// 初始化重连相关配置
|
||||||
@@ -223,6 +230,7 @@ export class RemoteApp {
|
|||||||
listenProxy() {
|
listenProxy() {
|
||||||
const remoteApp = this;
|
const remoteApp = this;
|
||||||
const app = this.mainApp;
|
const app = this.mainApp;
|
||||||
|
const username = this.username;
|
||||||
const listenFn = async (event: any) => {
|
const listenFn = async (event: any) => {
|
||||||
try {
|
try {
|
||||||
const data = event.toString();
|
const data = event.toString();
|
||||||
@@ -262,8 +270,10 @@ export class RemoteApp {
|
|||||||
};
|
};
|
||||||
remoteApp.json({
|
remoteApp.json({
|
||||||
id: this.id,
|
id: this.id,
|
||||||
type: 'registryClient'
|
type: 'registryClient',
|
||||||
|
username: username,
|
||||||
});
|
});
|
||||||
|
console.log(`远程应用 ${this.id} (${username}) 已注册到主应用,等待消息...`);
|
||||||
remoteApp.emitter.on('message', listenFn);
|
remoteApp.emitter.on('message', listenFn);
|
||||||
const closeMessage = () => {
|
const closeMessage = () => {
|
||||||
remoteApp.emitter.off('message', listenFn);
|
remoteApp.emitter.off('message', listenFn);
|
||||||
|
|||||||
@@ -116,7 +116,10 @@ export class SyncBase {
|
|||||||
const syncList = syncKeys.map((key) => {
|
const syncList = syncKeys.map((key) => {
|
||||||
const value = sync[key];
|
const value = sync[key];
|
||||||
const filepath = path.join(this.#dir, 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;
|
return null;
|
||||||
}
|
}
|
||||||
if (typeof value === 'string') {
|
if (typeof value === 'string') {
|
||||||
|
|||||||
Reference in New Issue
Block a user