From 2edba455dc4a80e13327f86c300567fa5904e9bc Mon Sep 17 00:00:00 2001 From: Gloridust Date: Sun, 14 Jun 2026 15:37:53 +0800 Subject: [PATCH] =?UTF-8?q?feat(v1.2.0):=20=E5=AE=9E=E4=BE=8B=20appType=20?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E6=A8=A1=E5=9E=8B=E5=9C=B0=E5=9F=BA=EF=BC=88?= =?UTF-8?q?=E5=90=91=E5=90=8E=E5=85=BC=E5=AE=B9=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 引入 AppType(wechat/telegram/chromium/custom)+ APP_LABELS + instanceAppType() 兜底。 Instance 增 appType?(可选) 与 customLaunch?;createInstance 接受 appType(默认 wechat)、 按应用取默认名;publicInstance 下发 appType(老实例无字段→回退 wechat)。 纯增量、不改现有运行行为;为后续 autostart 分发 / 各应用安装 / 前端选择器铺底。 Co-Authored-By: Claude Opus 4.8 --- panel/server/src/store.ts | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/panel/server/src/store.ts b/panel/server/src/store.ts index 1a660f7..9d78238 100644 --- a/panel/server/src/store.ts +++ b/panel/server/src/store.ts @@ -25,15 +25,32 @@ export interface User { // 初始默认管理员密码;管理员仍在用它时强烈提示改密。 const DEFAULT_ADMIN_PASSWORD = 'wechat'; +// v1.2.0:实例可承载多种应用(不止微信)。同一镜像运行时按 appType 安装/启动对应应用。 +export type AppType = 'wechat' | 'telegram' | 'chromium' | 'custom'; +export const APP_TYPES: AppType[] = ['wechat', 'telegram', 'chromium', 'custom']; +export const APP_LABELS: Record = { + wechat: '微信', + telegram: 'Telegram', + chromium: '浏览器', + custom: '自定义应用', +}; +// 向后兼容:v1.2.0 之前创建的实例没有 appType 字段,一律视为微信。 +export function instanceAppType(i: Instance): AppType { + return i.appType && APP_TYPES.includes(i.appType) ? i.appType : 'wechat'; +} + export interface Instance { id: string; // 短 id,用于容器/卷命名 name: string; // 显示名 + appType?: AppType; // 承载的应用类型;缺省(老实例)= wechat(见 instanceAppType) containerName: string; // woc-wx- volumeName: string; // woc-data- kasmUser: string; // 随机生成,服务端注入反代,永不下发前端 kasmPassword: string; createdAt: string; createdBy: string; // userId + // 自定义应用(appType=custom):用户上传的安装包信息,autostart 据此启动。 + customLaunch?: string; // 启动命令(容器内绝对路径或命令) // 自愈 watchdog 的"安全阀",per-instance 覆盖全局默认;缺省时使用 env / 内置默认。 // soft:内存超此值时,仅在"当前没有用户在远程会话"才主动重启(柔和自愈); // hard:内存超此值时,无论是否有人在会话都重启(防止 OOM 拖垮宿主)。 @@ -198,6 +215,7 @@ export function publicInstance(i: Instance) { return { id: i.id, name: i.name, + appType: instanceAppType(i), // 老实例无字段时回退 wechat createdAt: i.createdAt, createdBy: i.createdBy, memSoftLimitMB: i.memSoftLimitMB, @@ -263,7 +281,9 @@ export function createInstance( createdBy: string, allowedUserIds: string[] = [], reuseVolumeName?: string, + appType: AppType = 'wechat', ) { + const type: AppType = APP_TYPES.includes(appType) ? appType : 'wechat'; let id = randomBytes(5).toString('hex'); // 10 hex chars let volumeName = `woc-data-${id}`; if (reuseVolumeName) { @@ -275,7 +295,8 @@ export function createInstance( } const inst: Instance = { id, - name: name.trim() || `微信-${id.slice(0, 4)}`, + name: name.trim() || `${APP_LABELS[type]}-${id.slice(0, 4)}`, + appType: type, containerName: `woc-wx-${id}`, volumeName, kasmUser: 'woc',