@tachybase/module-backup 1.5.0 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -65,7 +65,7 @@ var backup_files_default = {
65
65
  const count = backupFiles.length;
66
66
  const rows = await Promise.all(
67
67
  backupFiles.slice((page - 1) * pageSize, page * pageSize).map(async (file) => {
68
- return await import_dumper.Dumper.getFileStatus(file.endsWith(".lock") ? file.replace(".lock", "") : file);
68
+ return await import_dumper.Dumper.getFileStatus(file.endsWith(".lock") ? file.replace(".lock", "") : file, ctx.app.name);
69
69
  })
70
70
  );
71
71
  ctx.body = {
@@ -112,14 +112,15 @@ var backup_files_default = {
112
112
  * @param next
113
113
  */
114
114
  async create(ctx, next) {
115
- var _a, _b;
115
+ var _a, _b, _c;
116
116
  const data = ctx.request.body;
117
117
  const app = ctx.app;
118
- if (data.method === "worker" && !((_a = app.worker) == null ? void 0 : _a.available)) {
118
+ const userId = (_a = ctx.state.currentUser) == null ? void 0 : _a.id;
119
+ if (data.method === "worker" && !((_b = app.worker) == null ? void 0 : _b.available)) {
119
120
  ctx.throw(500, ctx.t("No worker thread", { ns: "worker-thread" }));
120
121
  return next();
121
122
  }
122
- let useWorker = data.method === "worker" || data.method === "priority" && ((_b = app.worker) == null ? void 0 : _b.available);
123
+ let useWorker = data.method === "worker" || data.method === "priority" && ((_c = app.worker) == null ? void 0 : _c.available);
123
124
  const dumper = new import_dumper.Dumper(ctx.app);
124
125
  const taskId = await dumper.getLockFile(ctx.app.name);
125
126
  if (useWorker) {
@@ -129,7 +130,8 @@ var backup_files_default = {
129
130
  params: {
130
131
  dataTypes: data.dataTypes,
131
132
  appName: ctx.app.name,
132
- filename: taskId
133
+ filename: taskId,
134
+ userId
133
135
  },
134
136
  // 目前限制方法并发为1
135
137
  concurrency: 1
@@ -145,7 +147,8 @@ var backup_files_default = {
145
147
  plugin.workerCreateBackUp({
146
148
  dataTypes: data.dataTypes,
147
149
  appName: ctx.app.name,
148
- filename: taskId
150
+ filename: taskId,
151
+ userId
149
152
  }).then((res) => {
150
153
  app.noticeManager.notify("backup", { level: "info", msg: ctx.t("Done", { ns: "backup" }) });
151
154
  }).catch((error) => {
@@ -15,5 +15,6 @@ export default class PluginBackupRestoreServer extends Plugin {
15
15
  dataTypes: string[];
16
16
  appName: string;
17
17
  filename: string;
18
+ userId?: number;
18
19
  }): Promise<void>;
19
20
  }
@@ -57,6 +57,53 @@ const _PluginBackupRestoreServer = class _PluginBackupRestoreServer extends impo
57
57
  }
58
58
  async load() {
59
59
  this.app.resourcer.define(import_backup_files.default);
60
+ const gateway = import_server.Gateway.getInstance();
61
+ const ws = gateway["wsServer"];
62
+ if (ws == null ? void 0 : ws.wss) {
63
+ const appName = this.app.name;
64
+ ws.wss.on(
65
+ "connection",
66
+ async (websocket) => {
67
+ websocket.on("message", async (data) => {
68
+ var _a, _b, _c;
69
+ if (data.toString() !== "ping") {
70
+ try {
71
+ const userMeg = JSON.parse(data.toString());
72
+ if (userMeg.type === "signIn") {
73
+ if (!((_a = userMeg.payload) == null ? void 0 : _a.token)) {
74
+ return;
75
+ }
76
+ try {
77
+ const analysis = await ((_c = (_b = this.app.authManager) == null ? void 0 : _b.jwt) == null ? void 0 : _c.verifyToken(userMeg.payload.token));
78
+ const userId = analysis.userId;
79
+ const client = ws.webSocketClients.get(websocket.id);
80
+ if (client) {
81
+ client.tags.forEach((tag2) => {
82
+ if (tag2.startsWith("app:")) {
83
+ client.tags.delete(tag2);
84
+ }
85
+ });
86
+ const tag = `app:${appName}#${userId}`;
87
+ client.tags.add(tag);
88
+ this.app.logger.debug(`[Backup] WebSocket signIn: set tag ${tag} for connection ${websocket.id}`);
89
+ } else {
90
+ this.app.logger.warn(
91
+ `[Backup] WebSocket signIn: client not found for connection ${websocket.id}`
92
+ );
93
+ }
94
+ } catch (error) {
95
+ this.app.logger.warn("[Backup] WebSocket signIn message connection error:", error);
96
+ }
97
+ }
98
+ } catch (error) {
99
+ }
100
+ }
101
+ });
102
+ }
103
+ );
104
+ } else {
105
+ this.app.logger.warn("[Backup] WebSocket server not available, backup progress will not be pushed via WebSocket");
106
+ }
60
107
  this.app.on("afterStart", async (app) => {
61
108
  const cronJobs = await app.db.getRepository(import_constants.COLLECTION_AUTOBACKUP).find({
62
109
  filter: { enabled: true }
@@ -228,7 +275,8 @@ const _PluginBackupRestoreServer = class _PluginBackupRestoreServer extends impo
228
275
  await new import_dumper.Dumper(this.app).runDumpTask({
229
276
  groups: new Set(data.dataTypes),
230
277
  appName: data.appName,
231
- fileName: data.filename
278
+ fileName: data.filename,
279
+ userId: data.userId
232
280
  });
233
281
  }
234
282
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tachybase/module-backup",
3
3
  "displayName": "App backup & restore",
4
- "version": "1.5.0",
4
+ "version": "1.6.0",
5
5
  "description": "Backup and restore applications for scenarios such as application replication, migration, and upgrades.",
6
6
  "keywords": [
7
7
  "System management"
@@ -11,10 +11,10 @@
11
11
  "devDependencies": {
12
12
  "@ant-design/icons": "^5.6.1",
13
13
  "@hapi/topo": "^6.0.2",
14
- "@tachybase/schema": "*",
15
- "@tachybase/test": "*",
16
- "@tego/client": "*",
17
- "@tego/server": "*",
14
+ "@tachybase/schema": "1.3.52",
15
+ "@tachybase/test": "1.3.52",
16
+ "@tego/client": "1.3.52",
17
+ "@tego/server": "1.3.52",
18
18
  "@types/archiver": "^5.3.4",
19
19
  "@types/file-saver": "^2.0.7",
20
20
  "@types/lodash": "^4.17.20",
@@ -34,8 +34,8 @@
34
34
  "semver": "7.7.2",
35
35
  "tar": "^7.4.3",
36
36
  "yauzl": "^3.2.0",
37
- "@tachybase/module-worker-thread": "1.5.0",
38
- "@tachybase/client": "1.5.0"
37
+ "@tachybase/module-worker-thread": "1.6.0",
38
+ "@tachybase/client": "1.6.0"
39
39
  },
40
40
  "description.zh-CN": "备份和还原应用,可用于应用的复制、迁移、升级等场景。",
41
41
  "displayName.zh-CN": "应用的备份与还原",