@nger/fk-upload 1.0.71 → 1.0.74
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.
@@ -2,10 +2,14 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.CheckUploadController = void 0;
|
4
4
|
const tslib_1 = require("tslib");
|
5
|
+
const fs_1 = require("fs");
|
6
|
+
const fk_download_task_entity_1 = require("./../entities/fk-download-task.entity");
|
5
7
|
const rabbitmq_1 = require("@nger/rabbitmq");
|
6
8
|
const typeorm_1 = require("@nger/typeorm");
|
7
9
|
const core_1 = require("@nger/core");
|
8
10
|
const http_1 = require("@nger/http");
|
11
|
+
const typeorm_2 = require("typeorm");
|
12
|
+
const fs_extra_1 = require("fs-extra");
|
9
13
|
let CheckUploadController = class CheckUploadController {
|
10
14
|
db;
|
11
15
|
manager;
|
@@ -29,7 +33,18 @@ let CheckUploadController = class CheckUploadController {
|
|
29
33
|
const task = this.db.manager.getRepository(rabbitmq_1.TaskEntity);
|
30
34
|
const list = await task.find({ where: { topic: '@nger/fk-upload/download-task', status: 0 } });
|
31
35
|
await Promise.all(list.map(item => this.manager.send(item)));
|
32
|
-
return { msg: '
|
36
|
+
return { msg: 'redownload success', list };
|
37
|
+
}
|
38
|
+
async checkSpace() {
|
39
|
+
const download = this.db.manager.getRepository(fk_download_task_entity_1.FkDownloadTaskEntity);
|
40
|
+
const list = await download.find({ where: { status: (0, typeorm_2.In)([2, 3]) } });
|
41
|
+
const removes = [];
|
42
|
+
list.map(item => {
|
43
|
+
if ((0, fs_1.existsSync)(item.path)) {
|
44
|
+
(0, fs_extra_1.unlink)(item.path);
|
45
|
+
}
|
46
|
+
});
|
47
|
+
return { msg: 'succes', removes };
|
33
48
|
}
|
34
49
|
};
|
35
50
|
tslib_1.__decorate([
|
@@ -50,6 +65,12 @@ tslib_1.__decorate([
|
|
50
65
|
tslib_1.__metadata("design:paramtypes", []),
|
51
66
|
tslib_1.__metadata("design:returntype", Promise)
|
52
67
|
], CheckUploadController.prototype, "redownload", null);
|
68
|
+
tslib_1.__decorate([
|
69
|
+
(0, http_1.Get)('checkspace'),
|
70
|
+
tslib_1.__metadata("design:type", Function),
|
71
|
+
tslib_1.__metadata("design:paramtypes", []),
|
72
|
+
tslib_1.__metadata("design:returntype", Promise)
|
73
|
+
], CheckUploadController.prototype, "checkSpace", null);
|
53
74
|
CheckUploadController = tslib_1.__decorate([
|
54
75
|
(0, core_1.Controller)(`@nger/fk-upload`),
|
55
76
|
tslib_1.__metadata("design:paramtypes", [typeorm_1.Db, rabbitmq_1.TaskManager])
|
@@ -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);
|
@@ -67,6 +72,7 @@ class DownloadTask extends rabbitmq_1.Task {
|
|
67
72
|
const uploadTask = await this.createUploadTask(task, total, fileMd5, injector);
|
68
73
|
await manager.send(uploadTask);
|
69
74
|
complete();
|
75
|
+
this.downloadingCount -= 1;
|
70
76
|
});
|
71
77
|
req.on('response', async (resp) => {
|
72
78
|
const headers = resp.headers;
|
@@ -75,6 +81,7 @@ class DownloadTask extends rabbitmq_1.Task {
|
|
75
81
|
console.log(`file is to large`);
|
76
82
|
req.destroy();
|
77
83
|
complete();
|
84
|
+
this.downloadingCount -= 1;
|
78
85
|
}
|
79
86
|
});
|
80
87
|
if (next)
|
@@ -14,16 +14,16 @@ class EffectTask extends rabbitmq_1.Task {
|
|
14
14
|
async handle(injector, next) {
|
15
15
|
const task = injector.get(rabbitmq_1.DATA);
|
16
16
|
const complete = injector.get(rabbitmq_1.COMPLETE);
|
17
|
+
if (task.uploadUrl.startsWith('https://site')) {
|
18
|
+
complete();
|
19
|
+
return next && next();
|
20
|
+
}
|
17
21
|
const fail = injector.get(rabbitmq_1.FAIL);
|
18
22
|
const w7 = injector.get(w7_1.W7DataSource);
|
19
23
|
const db = injector.get(typeorm_1.Db);
|
20
24
|
await db.manager.update(entities_1.FkDownloadTaskEntity, task.filename, { status: 3 });
|
21
25
|
if (task.topicId) {
|
22
26
|
await (0, fs_extra_1.unlink)(task.path);
|
23
|
-
if (task.uploadUrl.startsWith('https://site')) {
|
24
|
-
complete();
|
25
|
-
return;
|
26
|
-
}
|
27
27
|
await w7.manager.update(w7_1.W7ChatTopicEntity, task.topicId, { thirdUrl: task.uploadUrl }).then(() => complete()).catch(() => fail());
|
28
28
|
complete();
|
29
29
|
}
|
@@ -44,7 +44,8 @@ class UploadTask extends rabbitmq_1.Task {
|
|
44
44
|
console.log(`upload success`, res.filename);
|
45
45
|
await db.manager.update(entities_1.FkDownloadTaskEntity, task.filename, { status: 2, uploadUrl: task.uploadUrl, uploadSize: task.total, uploadStatus: 1 });
|
46
46
|
const effectTask = await taskService.createEffectTask(res.filename, res.uploadUrl, task.topicId, task.path);
|
47
|
-
|
47
|
+
await manager.send(effectTask).then(() => complete());
|
48
|
+
this.runingCount -= 1;
|
48
49
|
});
|
49
50
|
}
|
50
51
|
else {
|