@nger/fk-upload 1.0.167 → 1.0.171

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.
package/dist/electon.js CHANGED
@@ -53,13 +53,8 @@ async function createWindow() {
53
53
  provide: electron_1.BrowserWindow,
54
54
  useValue: win
55
55
  }], 'root');
56
- win.webContents.closeDevTools();
57
- electron_1.Menu.setApplicationMenu(null);
58
- setTimeout(() => {
59
- win.loadURL('http://localhost:8081/@nger/fk-upload/help');
60
- }, 400);
56
+ win.loadURL('http://localhost:8081/@nger/fk-upload/help');
61
57
  }
62
- //
63
58
  electron_1.app.whenReady().then(() => {
64
59
  createWindow();
65
60
  electron_1.app.on('activate', () => {
@@ -68,3 +63,18 @@ electron_1.app.whenReady().then(() => {
68
63
  }
69
64
  });
70
65
  });
66
+ electron_1.app.on('certificate-error', (e) => {
67
+ console.log(e);
68
+ });
69
+ electron_1.app.on('continue-activity-error', (e) => {
70
+ console.log(e);
71
+ });
72
+ process.on('uncaughtException', (e) => {
73
+ console.log(e);
74
+ });
75
+ process.on('unhandledRejection', (e) => {
76
+ console.log(e);
77
+ });
78
+ process.on('uncaughtExceptionMonitor', (e) => {
79
+ console.log(e);
80
+ });
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DownloadTask = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const rabbitmq_1 = require("@nger/rabbitmq");
6
+ const core_1 = require("@nger/core");
6
7
  const actions_1 = require("./actions");
7
8
  const request_1 = require("request");
8
9
  const fs_1 = require("fs");
@@ -14,6 +15,7 @@ const typeorm_1 = require("@nger/typeorm");
14
15
  const entities_1 = require("../../entities");
15
16
  const rxjs_1 = require("rxjs");
16
17
  const operators_1 = require("rxjs/operators");
18
+ const path_2 = require("path");
17
19
  /**
18
20
  * upload and task
19
21
  */
@@ -25,14 +27,16 @@ class DownloadTask extends rabbitmq_1.Task {
25
27
  const db = injector.get(typeorm_1.Db);
26
28
  const task = injector.get(rabbitmq_1.DATA);
27
29
  const complete = injector.get(rabbitmq_1.COMPLETE);
30
+ const root = injector.get(core_1.APP_ROOT);
28
31
  const fail = injector.get(rabbitmq_1.FAIL);
29
32
  const download = await db.manager.findOne(entities_1.FkDownloadTaskEntity, { where: { filename: task.filename } });
30
33
  if (!download || (download && download.status !== 0)) {
31
34
  await complete();
32
35
  return next && next();
33
36
  }
34
- (0, fs_extra_1.ensureDir)((0, path_1.dirname)(task.path));
35
- const writeStream = (0, fs_1.createWriteStream)(task.path);
37
+ const filePath = (0, path_2.join)(root, task.path);
38
+ (0, fs_extra_1.ensureDir)((0, path_1.dirname)(filePath));
39
+ const writeStream = (0, fs_1.createWriteStream)(filePath);
36
40
  const manager = injector.get(rabbitmq_1.TaskManager);
37
41
  const url = task.url.startsWith('http') ? task.url : `https://${task.url}`;
38
42
  const req = (0, request_1.get)(url, {
@@ -62,12 +66,12 @@ class DownloadTask extends rabbitmq_1.Task {
62
66
  req.on('end', async () => {
63
67
  writeStream.end();
64
68
  sub.complete();
65
- const fileMd5 = await (0, md5_file_1.default)(task.path);
69
+ const fileMd5 = await (0, md5_file_1.default)(filePath);
66
70
  console.log(`file download success ${task.filename}: ${fileMd5}`);
67
71
  await db.manager.update(entities_1.FkDownloadTaskEntity, task.filename, { totalSize: total, fileMd5: fileMd5, status: 1, size: total });
68
72
  const fk = injector.get(fk_service_1.FkService);
69
73
  const shouldSize = await fk.getSize(task.url);
70
- const localSize = await fk.getLocalSize(task.path);
74
+ const localSize = await fk.getLocalSize(filePath);
71
75
  if (shouldSize != localSize) {
72
76
  // re download
73
77
  await fail();
@@ -2,11 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.EffectTask = void 0;
4
4
  const rabbitmq_1 = require("@nger/rabbitmq");
5
+ const core_1 = require("@nger/core");
5
6
  const actions_1 = require("./actions");
6
7
  const typeorm_1 = require("@nger/typeorm");
7
8
  const w7_1 = require("@nger/w7");
8
9
  const entities_1 = require("../../entities");
9
10
  const fs_extra_1 = require("fs-extra");
11
+ const path_1 = require("path");
10
12
  class EffectTask extends rabbitmq_1.Task {
11
13
  constructor() {
12
14
  super(actions_1.EFFECT_ACTION);
@@ -16,6 +18,7 @@ class EffectTask extends rabbitmq_1.Task {
16
18
  const task = injector.get(rabbitmq_1.DATA);
17
19
  const complete = injector.get(rabbitmq_1.COMPLETE);
18
20
  const manager = injector.get(rabbitmq_1.TaskManager);
21
+ const root = injector.get(core_1.APP_ROOT);
19
22
  console.log(`effect`, task.filename);
20
23
  try {
21
24
  const item = await db.manager.findOne(entities_1.FkDownloadTaskEntity, { where: { filename: task.filename } });
@@ -45,7 +48,8 @@ class EffectTask extends rabbitmq_1.Task {
45
48
  await db.manager.update(entities_1.FkDownloadTaskEntity, task.filename, { status: 3, uploadUrl });
46
49
  if (task.topicId) {
47
50
  try {
48
- await (0, fs_extra_1.unlink)(task.path);
51
+ const filePath = (0, path_1.join)(root, task.path);
52
+ await (0, fs_extra_1.unlink)(filePath);
49
53
  }
50
54
  catch (e) { }
51
55
  await w7.manager.update(w7_1.W7ChatTopicEntity, task.topicId, { topicStyle: 7, thirdUrl: item.url, foreverUrl: task.uploadUrl });
@@ -93,7 +93,7 @@ let TaskService = class TaskService {
93
93
  }
94
94
  const root = this.injector.get(core_1.APP_ROOT);
95
95
  (0, fs_extra_1.ensureDirSync)((0, path_1.join)(root, 'attachments/fk-upload'));
96
- const path = (0, path_1.join)(root, 'attachments/fk-upload', filename);
96
+ const path = (0, path_1.join)('attachments/fk-upload', filename);
97
97
  const download = {
98
98
  filename: filename,
99
99
  path: path,
@@ -2,12 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.UploadTask = void 0;
4
4
  const rabbitmq_1 = require("@nger/rabbitmq");
5
+ const core_1 = require("@nger/core");
5
6
  const actions_1 = require("./actions");
6
7
  const fk_service_1 = require("./fk.service");
7
8
  const task_service_1 = require("./task.service");
8
9
  const typeorm_1 = require("@nger/typeorm");
9
10
  const entities_1 = require("../../entities");
10
11
  const fs_1 = require("fs");
12
+ const path_1 = require("path");
11
13
  class UploadTask extends rabbitmq_1.Task {
12
14
  constructor() {
13
15
  super(actions_1.UPLOAD_ACTION);
@@ -24,6 +26,8 @@ class UploadTask extends rabbitmq_1.Task {
24
26
  errorCount = 0;
25
27
  async handle(injector, next) {
26
28
  const task = injector.get(rabbitmq_1.DATA);
29
+ const root = injector.get(core_1.APP_ROOT);
30
+ const filePath = (0, path_1.join)(root, task.path);
27
31
  const complete = injector.get(rabbitmq_1.COMPLETE);
28
32
  const fk = injector.get(fk_service_1.FkService);
29
33
  const taskService = injector.get(task_service_1.TaskService);
@@ -37,8 +41,11 @@ class UploadTask extends rabbitmq_1.Task {
37
41
  await complete();
38
42
  return next && next();
39
43
  }
40
- if (!(0, fs_1.existsSync)(task.path)) {
41
- throw new Error(`file ${task.path} not found`);
44
+ if (!(0, fs_1.existsSync)(filePath)) {
45
+ setTimeout(() => {
46
+ fail();
47
+ }, 1000);
48
+ return next && next();
42
49
  }
43
50
  // > 1G give up
44
51
  if (task.total >= 1024 * 1024 * 1024) {
@@ -46,15 +53,14 @@ class UploadTask extends rabbitmq_1.Task {
46
53
  return next && next();
47
54
  }
48
55
  const cloudSize = await fk.getSize(old.url);
49
- const localSize = fk.getLocalSize(old.path);
56
+ const localSize = fk.getLocalSize(filePath);
50
57
  if (cloudSize != localSize) {
51
58
  // not my task
52
- throw new Error(`not mine task`);
53
- // await db.manager.update(FkDownloadTaskEntity, task.filename, { status: 0 })
54
- // const download = await taskService.createDownLoadTask(old.url, old.loginId, old.topicId);
55
- // await manager.send(download);
56
- // await complete();
57
- // return next && next();
59
+ await db.manager.update(entities_1.FkDownloadTaskEntity, task.filename, { status: 0 });
60
+ const download = await taskService.createDownLoadTask(old.url, old.loginId, old.topicId);
61
+ await manager.send(download);
62
+ await complete();
63
+ return next && next();
58
64
  }
59
65
  console.log(`receive upload task`, { filename: task.filename, status: old.status });
60
66
  if (old.status == 1) {
@@ -76,7 +82,8 @@ class UploadTask extends rabbitmq_1.Task {
76
82
  this.errorCount = 0;
77
83
  }
78
84
  this.errorCount += 1;
79
- throw e;
85
+ fail();
86
+ return next && next();
80
87
  });
81
88
  }
82
89
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nger/fk-upload",
3
- "version": "1.0.167",
3
+ "version": "1.0.171",
4
4
  "description": "nger fk upload",
5
5
  "main": "dist/electon.js",
6
6
  "types": "dist/core.d.ts",