@nger/fk-upload 1.0.73 → 1.0.76

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.
@@ -13,5 +13,8 @@ export declare class CheckUploadController {
13
13
  msg: string;
14
14
  list: TaskEntity<object>[];
15
15
  }>;
16
- checkSpace(): Promise<void>;
16
+ checkSpace(): Promise<{
17
+ msg: string;
18
+ removes: string[];
19
+ }>;
17
20
  }
@@ -33,16 +33,23 @@ let CheckUploadController = class CheckUploadController {
33
33
  const task = this.db.manager.getRepository(rabbitmq_1.TaskEntity);
34
34
  const list = await task.find({ where: { topic: '@nger/fk-upload/download-task', status: 0 } });
35
35
  await Promise.all(list.map(item => this.manager.send(item)));
36
- return { msg: 'recheck success', list };
36
+ return { msg: 'redownload success', list };
37
37
  }
38
38
  async checkSpace() {
39
39
  const download = this.db.manager.getRepository(fk_download_task_entity_1.FkDownloadTaskEntity);
40
+ // remove to large
41
+ const largs = await download.find({ where: { totalSize: (0, typeorm_2.MoreThan)(1024 * 1024 * 1024) } });
42
+ // remove not use
43
+ // remove finish
40
44
  const list = await download.find({ where: { status: (0, typeorm_2.In)([2, 3]) } });
41
- list.map(item => {
45
+ const removes = [];
46
+ Promise.all([...list, ...largs].map(async (item) => {
42
47
  if ((0, fs_1.existsSync)(item.path)) {
43
- (0, fs_extra_1.unlink)(item.path);
48
+ await (0, fs_extra_1.unlink)(item.path);
49
+ removes.push(item.path);
44
50
  }
45
- });
51
+ }));
52
+ return { msg: 'succes', removes };
46
53
  }
47
54
  };
48
55
  tslib_1.__decorate([
@@ -31,6 +31,11 @@ class DownloadTask extends rabbitmq_1.Task {
31
31
  const task = injector.get(rabbitmq_1.DATA);
32
32
  const complete = injector.get(rabbitmq_1.COMPLETE);
33
33
  const fail = injector.get(rabbitmq_1.FAIL);
34
+ const download = await db.manager.findOne(entities_1.FkDownloadTaskEntity, { where: { filename: task.filename } });
35
+ if (download.status !== 0) {
36
+ complete();
37
+ return next && next();
38
+ }
34
39
  (0, fs_extra_1.ensureDir)((0, path_1.dirname)(task.path));
35
40
  const writeStream = (0, fs_1.createWriteStream)(task.path);
36
41
  const manager = injector.get(rabbitmq_1.TaskManager);
@@ -162,7 +162,7 @@ let FkService = class FkService {
162
162
  task.uploadUrl = fullUrl;
163
163
  }
164
164
  }
165
- console.log(`uploading ${task.filename} ${Math.floor((index + 1 / task.totalChunks) * 100)}%`);
165
+ console.log(`uploading ${task.filename} ${Math.floor((index + 1 / task.totalChunks))}%`);
166
166
  index = index + 1;
167
167
  } while (!complete);
168
168
  // upload complete
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nger/fk-upload",
3
- "version": "1.0.73",
3
+ "version": "1.0.76",
4
4
  "description": "",
5
5
  "main": "dist/core.js",
6
6
  "types": "dist/core.d.ts",