@whyour/qinglong 2.17.13 → 2.18.1

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.
Files changed (39) hide show
  1. package/package.json +9 -2
  2. package/sample/notify.js +47 -30
  3. package/sample/notify.py +36 -53
  4. package/shell/api.sh +26 -0
  5. package/shell/preload/sitecustomize.js +7 -1
  6. package/shell/preload/sitecustomize.py +9 -1
  7. package/shell/share.sh +3 -7
  8. package/shell/task.sh +1 -1
  9. package/shell/update.sh +2 -6
  10. package/static/build/api/config.js +2 -1
  11. package/static/build/api/script.js +4 -3
  12. package/static/build/api/system.js +16 -1
  13. package/static/build/api/user.js +1 -1
  14. package/static/build/config/util.js +10 -3
  15. package/static/build/data/system.js +1 -0
  16. package/static/build/loaders/express.js +8 -11
  17. package/static/build/loaders/initData.js +41 -5
  18. package/static/build/loaders/initFile.js +74 -76
  19. package/static/build/loaders/sock.js +4 -5
  20. package/static/build/services/cron.js +2 -1
  21. package/static/build/services/dependence.js +16 -7
  22. package/static/build/services/env.js +4 -27
  23. package/static/build/services/open.js +16 -7
  24. package/static/build/services/sshKey.js +5 -6
  25. package/static/build/services/system.js +15 -3
  26. package/static/build/services/user.js +116 -161
  27. package/static/build/shared/store.js +32 -0
  28. package/static/build/shared/utils.js +27 -0
  29. package/static/build/token.js +2 -6
  30. package/static/dist/{4642.260d2a8e.async.js → 4642.9e24d86c.async.js} +1 -1
  31. package/static/dist/4799.d5ca9f30.async.js +1 -0
  32. package/static/dist/index.html +2 -2
  33. package/static/dist/{preload_helper.2e4c8e3f.js → preload_helper.55b35ae0.js} +1 -1
  34. package/static/dist/{src__pages__crontab__index.7163c445.async.js → src__pages__crontab__index.55a8714d.async.js} +1 -1
  35. package/static/dist/{src__pages__script__index.b893a14e.async.js → src__pages__script__index.6a212c2d.async.js} +1 -1
  36. package/static/dist/{src__pages__setting__index.636a04c7.async.js → src__pages__setting__index.ffa1cdd6.async.js} +1 -1
  37. package/static/dist/{umi.916b40e1.js → umi.fb3ed7a0.js} +1 -1
  38. package/version.yaml +7 -8
  39. package/static/dist/4799.2c2c56e5.async.js +0 -1
@@ -35,6 +35,7 @@ const celebrate_1 = require("celebrate");
35
35
  const path_1 = __importStar(require("path"));
36
36
  const script_1 = __importDefault(require("../services/script"));
37
37
  const multer_1 = __importDefault(require("multer"));
38
+ const utils_1 = require("../shared/utils");
38
39
  const route = (0, express_1.Router)();
39
40
  const storage = multer_1.default.diskStorage({
40
41
  destination: function (req, file, cb) {
@@ -142,7 +143,7 @@ exports.default = (app) => {
142
143
  await (0, util_1.rmPath)(originFilePath);
143
144
  }
144
145
  }
145
- await fs.writeFile(filePath, content);
146
+ await (0, utils_1.writeFileWithLock)(filePath, content);
146
147
  return res.send({ code: 200 });
147
148
  }
148
149
  catch (e) {
@@ -160,7 +161,7 @@ exports.default = (app) => {
160
161
  try {
161
162
  let { filename, content, path } = req.body;
162
163
  const filePath = (0, path_1.join)(config_1.default.scriptPath, path, filename);
163
- await fs.writeFile(filePath, content);
164
+ await (0, utils_1.writeFileWithLock)(filePath, content);
164
165
  return res.send({ code: 200 });
165
166
  }
166
167
  catch (e) {
@@ -221,7 +222,7 @@ exports.default = (app) => {
221
222
  let { filename, content, path } = req.body;
222
223
  const { name, ext } = (0, path_1.parse)(filename);
223
224
  const filePath = (0, path_1.join)(config_1.default.scriptPath, path, `${name}.swap${ext}`);
224
- await fs.writeFile(filePath, content || '', { encoding: 'utf8' });
225
+ await (0, utils_1.writeFileWithLock)(filePath, content || '');
225
226
  const scriptService = typedi_1.Container.get(script_1.default);
226
227
  const result = await scriptService.runScript(filePath);
227
228
  res.send(result);
@@ -52,7 +52,7 @@ exports.default = (app) => {
52
52
  const logger = typedi_1.Container.get('logger');
53
53
  try {
54
54
  const userService = typedi_1.Container.get(user_1.default);
55
- const authInfo = await userService.getUserInfo();
55
+ const authInfo = await userService.getAuthInfo();
56
56
  const { version, changeLog, changeLogLink, publishTime } = await (0, util_1.parseVersion)(config_1.default.versionFile);
57
57
  let isInitialized = true;
58
58
  if (Object.keys(authInfo).length === 2 &&
@@ -321,5 +321,20 @@ exports.default = (app) => {
321
321
  return next(e);
322
322
  }
323
323
  });
324
+ route.put('/auth/reset', (0, celebrate_1.celebrate)({
325
+ body: celebrate_1.Joi.object({
326
+ retries: celebrate_1.Joi.number().optional(),
327
+ twoFactorActivated: celebrate_1.Joi.boolean().optional(),
328
+ }),
329
+ }), async (req, res, next) => {
330
+ try {
331
+ const userService = typedi_1.Container.get(user_1.default);
332
+ await userService.resetAuthInfo(req.body);
333
+ res.send({ code: 200, message: '更新成功' });
334
+ }
335
+ catch (e) {
336
+ return next(e);
337
+ }
338
+ });
324
339
  };
325
340
  //# sourceMappingURL=system.js.map
@@ -79,7 +79,7 @@ exports.default = (app) => {
79
79
  const logger = typedi_1.Container.get('logger');
80
80
  try {
81
81
  const userService = typedi_1.Container.get(user_1.default);
82
- const authInfo = await userService.getUserInfo();
82
+ const authInfo = await userService.getAuthInfo();
83
83
  res.send({
84
84
  code: 200,
85
85
  data: {
@@ -42,6 +42,7 @@ const js_yaml_1 = require("js-yaml");
42
42
  const index_1 = __importDefault(require("./index"));
43
43
  const const_1 = require("./const");
44
44
  const logger_1 = __importDefault(require("../loaders/logger"));
45
+ const utils_1 = require("../shared/utils");
45
46
  const os_1 = __importDefault(require("os"));
46
47
  __exportStar(require("./share"), exports);
47
48
  let osType;
@@ -180,7 +181,10 @@ function getPlatform(userAgent) {
180
181
  if (system === 'windows' || system === 'macos' || system === 'linux') {
181
182
  platform = 'desktop';
182
183
  }
183
- else if (system === 'android' || system === 'ios' || system === 'openharmony' || testUa(/mobile/g)) {
184
+ else if (system === 'android' ||
185
+ system === 'ios' ||
186
+ system === 'openharmony' ||
187
+ testUa(/mobile/g)) {
184
188
  platform = 'mobile';
185
189
  }
186
190
  return platform;
@@ -198,7 +202,7 @@ async function fileExist(file) {
198
202
  exports.fileExist = fileExist;
199
203
  async function createFile(file, data = '') {
200
204
  await fs.mkdir(path.dirname(file), { recursive: true });
201
- await fs.writeFile(file, data);
205
+ await (0, utils_1.writeFileWithLock)(file, data);
202
206
  }
203
207
  exports.createFile = createFile;
204
208
  async function handleLogPath(logPath, data = '') {
@@ -530,6 +534,9 @@ async function detectOS() {
530
534
  console.error(`Unknown Linux Distribution: ${osReleaseInfo}`);
531
535
  }
532
536
  }
537
+ else if (platform === 'darwin') {
538
+ osType = undefined;
539
+ }
533
540
  else {
534
541
  logger_1.default.error(`Unsupported platform: ${platform}`);
535
542
  console.error(`Unsupported platform: ${platform}`);
@@ -557,7 +564,7 @@ async function replaceDomainInFile(filePath, oldDomainWithScheme, newDomainWithS
557
564
  if (!newDomainWithScheme.endsWith('/')) {
558
565
  newDomainWithScheme += '/';
559
566
  }
560
- await fs.writeFile(filePath, updatedContent, 'utf8');
567
+ await (0, utils_1.writeFileWithLock)(filePath, updatedContent);
561
568
  }
562
569
  async function _updateLinuxMirror(osType, mirrorDomainWithScheme) {
563
570
  let filePath, currentDomainWithScheme;
@@ -24,6 +24,7 @@ var AuthDataType;
24
24
  AuthDataType["notification"] = "notification";
25
25
  AuthDataType["removeLogFrequency"] = "removeLogFrequency";
26
26
  AuthDataType["systemConfig"] = "systemConfig";
27
+ AuthDataType["authConfig"] = "authConfig";
27
28
  })(AuthDataType || (exports.AuthDataType = AuthDataType = {}));
28
29
  exports.SystemModel = _1.sequelize.define('Auth', {
29
30
  ip: sequelize_1.DataTypes.STRING,
@@ -32,17 +32,14 @@ const cors_1 = __importDefault(require("cors"));
32
32
  const api_1 = __importDefault(require("../api"));
33
33
  const config_1 = __importDefault(require("../config"));
34
34
  const express_jwt_1 = require("express-jwt");
35
- const promises_1 = __importDefault(require("fs/promises"));
36
35
  const util_1 = require("../config/util");
37
- const typedi_1 = __importDefault(require("typedi"));
38
- const open_1 = __importDefault(require("../services/open"));
39
36
  const express_urlrewrite_1 = __importDefault(require("express-urlrewrite"));
40
- const user_1 = __importDefault(require("../services/user"));
41
37
  const Sentry = __importStar(require("@sentry/node"));
42
38
  const celebrate_1 = require("celebrate");
43
39
  const http_proxy_middleware_1 = require("http-proxy-middleware");
44
40
  const serverEnv_1 = require("../config/serverEnv");
45
41
  const logger_1 = __importDefault(require("./logger"));
42
+ const store_1 = require("../shared/store");
46
43
  exports.default = ({ app }) => {
47
44
  app.set('trust proxy', 'loopback');
48
45
  app.use((0, cors_1.default)());
@@ -73,10 +70,11 @@ exports.default = ({ app }) => {
73
70
  return next();
74
71
  });
75
72
  app.use(async (req, res, next) => {
73
+ var _a;
76
74
  const headerToken = (0, util_1.getToken)(req);
77
75
  if (req.path.startsWith('/open/')) {
78
- const openService = typedi_1.default.get(open_1.default);
79
- const doc = await openService.findTokenByValue(headerToken);
76
+ const apps = await store_1.shareStore.getApps();
77
+ const doc = (_a = apps === null || apps === void 0 ? void 0 : apps.filter((x) => { var _a; return (_a = x.tokens) === null || _a === void 0 ? void 0 : _a.find((y) => y.value === headerToken); })) === null || _a === void 0 ? void 0 : _a[0];
80
78
  if (doc && doc.tokens && doc.tokens.length > 0) {
81
79
  const currentToken = doc.tokens.find((x) => x.value === headerToken);
82
80
  const keyMatch = req.path.match(/\/open\/([a-z]+)\/*/);
@@ -94,9 +92,9 @@ exports.default = ({ app }) => {
94
92
  config_1.default.apiWhiteList.includes(originPath)) {
95
93
  return next();
96
94
  }
97
- const data = await promises_1.default.readFile(config_1.default.authConfigFile, 'utf8');
98
- if (data && headerToken) {
99
- const { token = '', tokens = {} } = (0, util_1.safeJSONParse)(data);
95
+ const authInfo = await store_1.shareStore.getAuthInfo();
96
+ if (authInfo && headerToken) {
97
+ const { token = '', tokens = {} } = authInfo;
100
98
  if (headerToken === token || tokens[req.platform] === headerToken) {
101
99
  return next();
102
100
  }
@@ -112,8 +110,7 @@ exports.default = ({ app }) => {
112
110
  if (!['/api/user/init', '/api/user/notification/init'].includes(req.path)) {
113
111
  return next();
114
112
  }
115
- const userService = typedi_1.default.get(user_1.default);
116
- const authInfo = await userService.getUserInfo();
113
+ const authInfo = (await store_1.shareStore.getAuthInfo()) || {};
117
114
  let isInitialized = true;
118
115
  if (Object.keys(authInfo).length === 2 &&
119
116
  authInfo.username === 'admin' &&
@@ -18,6 +18,10 @@ const system_1 = require("../data/system");
18
18
  const system_2 = __importDefault(require("../services/system"));
19
19
  const user_1 = __importDefault(require("../services/user"));
20
20
  const promises_1 = require("fs/promises");
21
+ const util_1 = require("../config/util");
22
+ const open_1 = __importDefault(require("../services/open"));
23
+ const store_1 = require("../shared/store");
24
+ const logger_1 = __importDefault(require("./logger"));
21
25
  exports.default = async () => {
22
26
  var _a, _b, _c, _d, _e, _f;
23
27
  const cronService = typedi_1.Container.get(cron_2.default);
@@ -25,12 +29,39 @@ exports.default = async () => {
25
29
  const dependenceService = typedi_1.Container.get(dependence_1.default);
26
30
  const systemService = typedi_1.Container.get(system_2.default);
27
31
  const userService = typedi_1.Container.get(user_1.default);
32
+ const openService = typedi_1.Container.get(open_1.default);
28
33
  // 初始化增加系统配置
29
- await system_1.SystemModel.upsert({ type: system_1.AuthDataType.systemConfig });
30
- await system_1.SystemModel.upsert({ type: system_1.AuthDataType.notification });
34
+ const [systemConfig] = await system_1.SystemModel.findOrCreate({
35
+ where: { type: system_1.AuthDataType.systemConfig },
36
+ });
37
+ const [notifyConfig] = await system_1.SystemModel.findOrCreate({
38
+ where: { type: system_1.AuthDataType.notification },
39
+ });
40
+ const [authConfig] = await system_1.SystemModel.findOrCreate({
41
+ where: { type: system_1.AuthDataType.authConfig },
42
+ });
43
+ if (!(authConfig === null || authConfig === void 0 ? void 0 : authConfig.info)) {
44
+ let authInfo = {
45
+ username: 'admin',
46
+ password: 'admin',
47
+ };
48
+ try {
49
+ const content = await (0, promises_1.readFile)(config_1.default.authConfigFile, 'utf8');
50
+ authInfo = (0, util_1.safeJSONParse)(content);
51
+ }
52
+ catch (error) {
53
+ logger_1.default.warn('Failed to read auth config file, using default credentials');
54
+ }
55
+ await system_1.SystemModel.upsert({
56
+ id: authConfig === null || authConfig === void 0 ? void 0 : authConfig.id,
57
+ info: authInfo,
58
+ type: system_1.AuthDataType.authConfig,
59
+ });
60
+ }
31
61
  // 初始化通知配置
32
- const notifyConfig = await userService.getNotificationMode();
33
- await (0, promises_1.writeFile)(config_1.default.systemNotifyFile, JSON.stringify(notifyConfig));
62
+ if (notifyConfig.info) {
63
+ await (0, promises_1.writeFile)(config_1.default.systemNotifyFile, JSON.stringify(notifyConfig.info));
64
+ }
34
65
  const installDependencies = () => {
35
66
  // 初始化时安装所有处于安装中,安装成功,安装失败的依赖
36
67
  dependence_2.DependenceModel.findAll({
@@ -48,7 +79,6 @@ exports.default = async () => {
48
79
  });
49
80
  };
50
81
  // 初始化更新 linux/python/nodejs 镜像源配置
51
- const systemConfig = await systemService.getSystemConfig();
52
82
  if ((_a = systemConfig.info) === null || _a === void 0 ? void 0 : _a.pythonMirror) {
53
83
  systemService.updatePythonMirror({
54
84
  pythonMirror: (_b = systemConfig.info) === null || _b === void 0 ? void 0 : _b.pythonMirror,
@@ -138,5 +168,11 @@ exports.default = async () => {
138
168
  // 初始化保存一次ck和定时任务数据
139
169
  await cronService.autosave_crontab();
140
170
  await envService.set_envs();
171
+ const authInfo = await userService.getAuthInfo();
172
+ const apps = await openService.findApps();
173
+ await store_1.shareStore.updateAuthInfo(authInfo);
174
+ if (apps === null || apps === void 0 ? void 0 : apps.length) {
175
+ await store_1.shareStore.updateApps(apps);
176
+ }
141
177
  };
142
178
  //# sourceMappingURL=initData.js.map
@@ -8,6 +8,7 @@ const path_1 = __importDefault(require("path"));
8
8
  const os_1 = __importDefault(require("os"));
9
9
  const logger_1 = __importDefault(require("./logger"));
10
10
  const util_1 = require("../config/util");
11
+ const utils_1 = require("../shared/utils");
11
12
  const rootPath = process.env.QL_DIR;
12
13
  let dataPath = path_1.default.join(rootPath, 'data/');
13
14
  if (process.env.QL_DATA_DIR) {
@@ -22,9 +23,7 @@ const bakPath = path_1.default.join(dataPath, 'bak/');
22
23
  const samplePath = path_1.default.join(rootPath, 'sample/');
23
24
  const tmpPath = path_1.default.join(logPath, '.tmp/');
24
25
  const confFile = path_1.default.join(configPath, 'config.sh');
25
- const authConfigFile = path_1.default.join(configPath, 'auth.json');
26
26
  const sampleConfigFile = path_1.default.join(samplePath, 'config.sample.sh');
27
- const sampleAuthFile = path_1.default.join(samplePath, 'auth.sample.json');
28
27
  const sampleTaskShellFile = path_1.default.join(samplePath, 'task.sample.sh');
29
28
  const sampleNotifyJsFile = path_1.default.join(samplePath, 'notify.js');
30
29
  const sampleNotifyPyFile = path_1.default.join(samplePath, 'notify.py');
@@ -40,81 +39,80 @@ const homedir = os_1.default.homedir();
40
39
  const sshPath = path_1.default.resolve(homedir, '.ssh');
41
40
  const sshdPath = path_1.default.join(dataPath, 'ssh.d');
42
41
  const systemLogPath = path_1.default.join(dataPath, 'syslog');
42
+ const directories = [
43
+ configPath,
44
+ scriptPath,
45
+ preloadPath,
46
+ logPath,
47
+ tmpPath,
48
+ uploadPath,
49
+ sshPath,
50
+ bakPath,
51
+ sshdPath,
52
+ systemLogPath,
53
+ ];
54
+ const files = [
55
+ {
56
+ target: confFile,
57
+ source: sampleConfigFile,
58
+ checkExistence: true,
59
+ },
60
+ {
61
+ target: jsNotifyFile,
62
+ source: sampleNotifyJsFile,
63
+ checkExistence: false,
64
+ },
65
+ {
66
+ target: pyNotifyFile,
67
+ source: sampleNotifyPyFile,
68
+ checkExistence: false,
69
+ },
70
+ {
71
+ target: scriptNotifyJsFile,
72
+ source: sampleNotifyJsFile,
73
+ checkExistence: true,
74
+ },
75
+ {
76
+ target: scriptNotifyPyFile,
77
+ source: sampleNotifyPyFile,
78
+ checkExistence: true,
79
+ },
80
+ {
81
+ target: TaskBeforeFile,
82
+ source: sampleTaskShellFile,
83
+ checkExistence: true,
84
+ },
85
+ {
86
+ target: TaskBeforeJsFile,
87
+ content: '// The JavaScript code that executes before the JavaScript task execution will execute.',
88
+ checkExistence: true,
89
+ },
90
+ {
91
+ target: TaskBeforePyFile,
92
+ content: '# The Python code that executes before the Python task execution will execute.',
93
+ checkExistence: true,
94
+ },
95
+ {
96
+ target: TaskAfterFile,
97
+ source: sampleTaskShellFile,
98
+ checkExistence: true,
99
+ },
100
+ ];
43
101
  exports.default = async () => {
44
- const authFileExist = await (0, util_1.fileExist)(authConfigFile);
45
- const confFileExist = await (0, util_1.fileExist)(confFile);
46
- const scriptDirExist = await (0, util_1.fileExist)(scriptPath);
47
- const preloadDirExist = await (0, util_1.fileExist)(preloadPath);
48
- const logDirExist = await (0, util_1.fileExist)(logPath);
49
- const configDirExist = await (0, util_1.fileExist)(configPath);
50
- const uploadDirExist = await (0, util_1.fileExist)(uploadPath);
51
- const sshDirExist = await (0, util_1.fileExist)(sshPath);
52
- const bakDirExist = await (0, util_1.fileExist)(bakPath);
53
- const sshdDirExist = await (0, util_1.fileExist)(sshdPath);
54
- const systemLogDirExist = await (0, util_1.fileExist)(systemLogPath);
55
- const tmpDirExist = await (0, util_1.fileExist)(tmpPath);
56
- const scriptNotifyJsFileExist = await (0, util_1.fileExist)(scriptNotifyJsFile);
57
- const scriptNotifyPyFileExist = await (0, util_1.fileExist)(scriptNotifyPyFile);
58
- const TaskBeforeFileExist = await (0, util_1.fileExist)(TaskBeforeFile);
59
- const TaskBeforeJsFileExist = await (0, util_1.fileExist)(TaskBeforeJsFile);
60
- const TaskBeforePyFileExist = await (0, util_1.fileExist)(TaskBeforePyFile);
61
- const TaskAfterFileExist = await (0, util_1.fileExist)(TaskAfterFile);
62
- if (!configDirExist) {
63
- await promises_1.default.mkdir(configPath);
64
- }
65
- if (!scriptDirExist) {
66
- await promises_1.default.mkdir(scriptPath);
67
- }
68
- if (!preloadDirExist) {
69
- await promises_1.default.mkdir(preloadPath);
70
- }
71
- if (!logDirExist) {
72
- await promises_1.default.mkdir(logPath);
73
- }
74
- if (!tmpDirExist) {
75
- await promises_1.default.mkdir(tmpPath);
76
- }
77
- if (!uploadDirExist) {
78
- await promises_1.default.mkdir(uploadPath);
79
- }
80
- if (!sshDirExist) {
81
- await promises_1.default.mkdir(sshPath);
82
- }
83
- if (!bakDirExist) {
84
- await promises_1.default.mkdir(bakPath);
85
- }
86
- if (!sshdDirExist) {
87
- await promises_1.default.mkdir(sshdPath);
88
- }
89
- if (!systemLogDirExist) {
90
- await promises_1.default.mkdir(systemLogPath);
91
- }
92
- // 初始化文件
93
- if (!authFileExist) {
94
- await promises_1.default.writeFile(authConfigFile, await promises_1.default.readFile(sampleAuthFile));
95
- }
96
- if (!confFileExist) {
97
- await promises_1.default.writeFile(confFile, await promises_1.default.readFile(sampleConfigFile));
98
- }
99
- await promises_1.default.writeFile(jsNotifyFile, await promises_1.default.readFile(sampleNotifyJsFile));
100
- await promises_1.default.writeFile(pyNotifyFile, await promises_1.default.readFile(sampleNotifyPyFile));
101
- if (!scriptNotifyJsFileExist) {
102
- await promises_1.default.writeFile(scriptNotifyJsFile, await promises_1.default.readFile(sampleNotifyJsFile));
103
- }
104
- if (!scriptNotifyPyFileExist) {
105
- await promises_1.default.writeFile(scriptNotifyPyFile, await promises_1.default.readFile(sampleNotifyPyFile));
106
- }
107
- if (!TaskBeforeFileExist) {
108
- await promises_1.default.writeFile(TaskBeforeFile, await promises_1.default.readFile(sampleTaskShellFile));
109
- }
110
- if (!TaskBeforeJsFileExist) {
111
- await promises_1.default.writeFile(TaskBeforeJsFile, '// The JavaScript code that executes before the JavaScript task execution will execute.');
112
- }
113
- if (!TaskBeforePyFileExist) {
114
- await promises_1.default.writeFile(TaskBeforePyFile, '# The Python code that executes before the Python task execution will execute.');
115
- }
116
- if (!TaskAfterFileExist) {
117
- await promises_1.default.writeFile(TaskAfterFile, await promises_1.default.readFile(sampleTaskShellFile));
102
+ for (const dirPath of directories) {
103
+ if (!(await (0, util_1.fileExist)(dirPath))) {
104
+ await promises_1.default.mkdir(dirPath);
105
+ }
106
+ }
107
+ for (const item of files) {
108
+ const exists = await (0, util_1.fileExist)(item.target);
109
+ if (!item.checkExistence || !exists) {
110
+ if (!item.content && !item.source) {
111
+ throw new Error(`Neither content nor source specified for ${item.target}`);
112
+ }
113
+ const content = item.content || (await promises_1.default.readFile(item.source));
114
+ await (0, utils_1.writeFileWithLock)(item.target, content);
115
+ }
118
116
  }
119
117
  logger_1.default.info('✌️ Init file down');
120
118
  console.log('✌️ Init file down');
@@ -6,9 +6,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const sockjs_1 = __importDefault(require("sockjs"));
7
7
  const typedi_1 = require("typedi");
8
8
  const sock_1 = __importDefault(require("../services/sock"));
9
- const index_1 = __importDefault(require("../config/index"));
10
- const promises_1 = __importDefault(require("fs/promises"));
11
9
  const util_1 = require("../config/util");
10
+ const store_1 = require("../shared/store");
12
11
  exports.default = async ({ server }) => {
13
12
  const echo = sockjs_1.default.createServer({ prefix: '/api/ws', log: () => { } });
14
13
  const sockService = typedi_1.Container.get(sock_1.default);
@@ -16,11 +15,11 @@ exports.default = async ({ server }) => {
16
15
  if (!conn.headers || !conn.url || !conn.pathname) {
17
16
  conn.close('404');
18
17
  }
19
- const data = await promises_1.default.readFile(index_1.default.authConfigFile, 'utf8');
18
+ const authInfo = await store_1.shareStore.getAuthInfo();
20
19
  const platform = (0, util_1.getPlatform)(conn.headers['user-agent'] || '') || 'desktop';
21
20
  const headerToken = conn.url.replace(`${conn.pathname}?token=`, '');
22
- if (data) {
23
- const { token = '', tokens = {} } = (0, util_1.safeJSONParse)(data);
21
+ if (authInfo) {
22
+ const { token = '', tokens = {} } = authInfo;
24
23
  if (headerToken === token || tokens[platform] === headerToken) {
25
24
  sockService.addClient(conn);
26
25
  conn.on('data', (message) => {
@@ -32,6 +32,7 @@ const cross_spawn_1 = require("cross-spawn");
32
32
  const dayjs_1 = __importDefault(require("dayjs"));
33
33
  const pickBy_1 = __importDefault(require("lodash/pickBy"));
34
34
  const omit_1 = __importDefault(require("lodash/omit"));
35
+ const utils_1 = require("../shared/utils");
35
36
  let CronService = class CronService {
36
37
  constructor(logger) {
37
38
  this.logger = logger;
@@ -496,7 +497,7 @@ let CronService = class CronService {
496
497
  crontab_string += '\n';
497
498
  }
498
499
  });
499
- await promises_1.default.writeFile(config_1.default.crontabFile, crontab_string);
500
+ await (0, utils_1.writeFileWithLock)(config_1.default.crontabFile, crontab_string);
500
501
  await cron_1.CrontabModel.update({ saved: true }, { where: {} });
501
502
  }
502
503
  import_crontab() {
@@ -175,6 +175,12 @@ let DependenceService = class DependenceService {
175
175
  if (pLimit_1.default.firstDependencyId !== dependency.id) {
176
176
  return resolve(null);
177
177
  }
178
+ const depIds = [dependency.id];
179
+ let depName = dependency.name.trim();
180
+ const actionText = isInstall ? '安装' : '删除';
181
+ const socketMessageType = isInstall
182
+ ? 'installDependence'
183
+ : 'uninstallDependence';
178
184
  const isNodeDependence = dependency.type === dependence_1.DependenceTypes.nodejs;
179
185
  const isLinuxDependence = dependency.type === dependence_1.DependenceTypes.linux;
180
186
  const isPythonDependence = dependency.type === dependence_1.DependenceTypes.python3;
@@ -183,19 +189,23 @@ let DependenceService = class DependenceService {
183
189
  pLimit_1.default.removeQueuedDependency(dependency);
184
190
  if (isLinuxDependence) {
185
191
  if (!osType) {
192
+ await dependence_1.DependenceModel.update({ status: dependence_1.DependenceStatus.installFailed }, { where: { id: depIds } });
193
+ const startTime = (0, dayjs_1.default)();
194
+ const message = `开始${actionText}依赖 ${depName},开始时间 ${startTime.format('YYYY-MM-DD HH:mm:ss')}\n\n当前系统不支持\n\n依赖${actionText}失败,结束时间 ${startTime.format('YYYY-MM-DD HH:mm:ss')},耗时 ${startTime.diff(startTime, 'second')} 秒`;
195
+ this.sockService.sendMessage({
196
+ type: socketMessageType,
197
+ message,
198
+ references: depIds,
199
+ });
200
+ this.updateLog(depIds, message);
186
201
  return resolve(null);
187
202
  }
188
203
  linuxCommand = const_1.LINUX_DEPENDENCE_COMMAND[osType];
189
204
  }
190
- const depIds = [dependency.id];
191
205
  const status = isInstall
192
206
  ? dependence_1.DependenceStatus.installing
193
207
  : dependence_1.DependenceStatus.removing;
194
208
  await dependence_1.DependenceModel.update({ status }, { where: { id: depIds } });
195
- const socketMessageType = isInstall
196
- ? 'installDependence'
197
- : 'uninstallDependence';
198
- let depName = dependency.name.trim();
199
209
  let depRunCommand = (isInstall
200
210
  ? dependence_1.InstallDependenceCommandTypes
201
211
  : dependence_1.unInstallDependenceCommandTypes)[dependency.type];
@@ -204,7 +214,6 @@ let DependenceService = class DependenceService {
204
214
  ? linuxCommand.install
205
215
  : linuxCommand.uninstall;
206
216
  }
207
- const actionText = isInstall ? '安装' : '删除';
208
217
  const startTime = (0, dayjs_1.default)();
209
218
  const message = `开始${actionText}依赖 ${depName},开始时间 ${startTime.format('YYYY-MM-DD HH:mm:ss')}\n\n`;
210
219
  this.sockService.sendMessage({
@@ -294,7 +303,7 @@ let DependenceService = class DependenceService {
294
303
  references: depIds,
295
304
  });
296
305
  this.updateLog(depIds, message);
297
- let status = null;
306
+ let status;
298
307
  if (isSucceed) {
299
308
  status = isInstall
300
309
  ? dependence_1.DependenceStatus.installed
@@ -1,33 +1,10 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
2
  var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
19
3
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
20
4
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
21
5
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
22
6
  return c > 3 && r && Object.defineProperty(target, key, r), r;
23
7
  };
24
- var __importStar = (this && this.__importStar) || function (mod) {
25
- if (mod && mod.__esModule) return mod;
26
- var result = {};
27
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
28
- __setModuleDefault(result, mod);
29
- return result;
30
- };
31
8
  var __metadata = (this && this.__metadata) || function (k, v) {
32
9
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
33
10
  };
@@ -41,10 +18,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
41
18
  const typedi_1 = require("typedi");
42
19
  const winston_1 = __importDefault(require("winston"));
43
20
  const config_1 = __importDefault(require("../config"));
44
- const fs = __importStar(require("fs/promises"));
45
21
  const env_1 = require("../data/env");
46
22
  const groupBy_1 = __importDefault(require("lodash/groupBy"));
47
23
  const sequelize_1 = require("sequelize");
24
+ const utils_1 = require("../shared/utils");
48
25
  let EnvService = class EnvService {
49
26
  constructor(logger) {
50
27
  this.logger = logger;
@@ -215,9 +192,9 @@ let EnvService = class EnvService {
215
192
  }
216
193
  }
217
194
  }
218
- await fs.writeFile(config_1.default.envFile, env_string);
219
- await fs.writeFile(config_1.default.jsEnvFile, js_env_string);
220
- await fs.writeFile(config_1.default.pyEnvFile, py_env_string);
195
+ await (0, utils_1.writeFileWithLock)(config_1.default.envFile, env_string);
196
+ await (0, utils_1.writeFileWithLock)(config_1.default.jsEnvFile, js_env_string);
197
+ await (0, utils_1.writeFileWithLock)(config_1.default.pyEnvFile, py_env_string);
221
198
  }
222
199
  };
223
200
  EnvService = __decorate([