@nger/fk-upload 1.0.83 → 1.0.84
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.
@@ -83,7 +83,7 @@ let CheckUploadController = class CheckUploadController {
|
|
83
83
|
async checkWaitUploadTask() {
|
84
84
|
const download = this.db.manager.getRepository(fk_download_task_entity_1.FkDownloadTaskEntity);
|
85
85
|
const errors = await download.find({ where: { uploadUrl: (0, typeorm_2.Like)('https://site%') } });
|
86
|
-
await download.update(errors.map(err => err.filename), { status:
|
86
|
+
await download.update(errors.map(err => err.filename), { status: 1 });
|
87
87
|
const list = await download.find({ where: { status: 1 } });
|
88
88
|
const task = this.injector.get(task_service_1.TaskService);
|
89
89
|
await Promise.all(list.map(async (item) => {
|
@@ -21,12 +21,7 @@ class DownloadTask extends rabbitmq_1.Task {
|
|
21
21
|
constructor() {
|
22
22
|
super(actions_1.DOWNLOAD_ACTION);
|
23
23
|
}
|
24
|
-
downloadingCount = 0;
|
25
24
|
async handle(injector, next) {
|
26
|
-
if (this.downloadingCount > 3) {
|
27
|
-
throw new Error(`system is busy`);
|
28
|
-
}
|
29
|
-
this.downloadingCount += 1;
|
30
25
|
const db = injector.get(typeorm_1.Db);
|
31
26
|
const task = injector.get(rabbitmq_1.DATA);
|
32
27
|
const complete = injector.get(rabbitmq_1.COMPLETE);
|
@@ -34,7 +29,6 @@ class DownloadTask extends rabbitmq_1.Task {
|
|
34
29
|
const download = await db.manager.findOne(entities_1.FkDownloadTaskEntity, { where: { filename: task.filename } });
|
35
30
|
if (download.status !== 0) {
|
36
31
|
await complete();
|
37
|
-
this.downloadingCount -= 1;
|
38
32
|
return next && next();
|
39
33
|
}
|
40
34
|
(0, fs_extra_1.ensureDir)((0, path_1.dirname)(task.path));
|
@@ -73,7 +67,6 @@ class DownloadTask extends rabbitmq_1.Task {
|
|
73
67
|
const uploadTask = await this.createUploadTask(task, total, fileMd5, injector);
|
74
68
|
await manager.send(uploadTask);
|
75
69
|
await complete();
|
76
|
-
this.downloadingCount -= 1;
|
77
70
|
});
|
78
71
|
req.on('response', async (resp) => {
|
79
72
|
const headers = resp.headers;
|
@@ -83,7 +76,6 @@ class DownloadTask extends rabbitmq_1.Task {
|
|
83
76
|
console.log(`file is to large`);
|
84
77
|
req.destroy();
|
85
78
|
await complete();
|
86
|
-
this.downloadingCount -= 1;
|
87
79
|
}
|
88
80
|
});
|
89
81
|
if (next)
|
@@ -12,7 +12,6 @@ class UploadTask extends rabbitmq_1.Task {
|
|
12
12
|
constructor() {
|
13
13
|
super(actions_1.UPLOAD_ACTION);
|
14
14
|
}
|
15
|
-
runingCount = 0;
|
16
15
|
async handle(injector, next) {
|
17
16
|
const task = injector.get(rabbitmq_1.DATA);
|
18
17
|
const complete = injector.get(rabbitmq_1.COMPLETE);
|
@@ -24,26 +23,19 @@ class UploadTask extends rabbitmq_1.Task {
|
|
24
23
|
// not exist
|
25
24
|
if (!old) {
|
26
25
|
await complete();
|
27
|
-
this.runingCount -= 1;
|
28
26
|
return next && next();
|
29
27
|
}
|
30
28
|
// > 1G give up
|
31
29
|
if (task.total >= 1024 * 1024 * 1024) {
|
32
30
|
await complete();
|
33
|
-
this.runingCount -= 1;
|
34
31
|
return next && next();
|
35
32
|
}
|
36
33
|
if (!(0, fs_1.existsSync)(task.path) || (old.fileMd5 && old.fileMd5.length > 0)) {
|
37
34
|
await db.manager.update(entities_1.FkDownloadTaskEntity, task.filename, { status: 0 });
|
38
35
|
await complete();
|
39
|
-
this.runingCount -= 1;
|
40
36
|
return next && next();
|
41
37
|
}
|
42
38
|
if (old.status === 1) {
|
43
|
-
if (this.runingCount > 5) {
|
44
|
-
throw new Error(`system is busy`);
|
45
|
-
}
|
46
|
-
this.runingCount += 1;
|
47
39
|
// upload
|
48
40
|
await fk.startUploadFile(task).then(async (res) => {
|
49
41
|
// create effect task
|
@@ -51,7 +43,6 @@ class UploadTask extends rabbitmq_1.Task {
|
|
51
43
|
await db.manager.update(entities_1.FkDownloadTaskEntity, task.filename, { status: 2, uploadUrl: task.uploadUrl, uploadSize: task.total, uploadStatus: 1 });
|
52
44
|
const effectTask = await taskService.createEffectTask(res.filename, res.uploadUrl, task.topicId, task.path);
|
53
45
|
await manager.send(effectTask).then(() => complete());
|
54
|
-
this.runingCount -= 1;
|
55
46
|
});
|
56
47
|
}
|
57
48
|
else {
|