@nger/fk-upload 1.0.64 → 1.0.67
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.
@@ -12,6 +12,7 @@ class UploadTask extends rabbitmq_1.Task {
|
|
12
12
|
constructor() {
|
13
13
|
super(actions_1.UPLOAD_ACTION);
|
14
14
|
}
|
15
|
+
runingCount = 0;
|
15
16
|
async handle(injector, next) {
|
16
17
|
const task = injector.get(rabbitmq_1.DATA);
|
17
18
|
const complete = injector.get(rabbitmq_1.COMPLETE);
|
@@ -19,20 +20,36 @@ class UploadTask extends rabbitmq_1.Task {
|
|
19
20
|
const taskService = injector.get(task_service_1.TaskService);
|
20
21
|
const manager = injector.get(rabbitmq_1.TaskManager);
|
21
22
|
const db = injector.get(typeorm_1.Db);
|
23
|
+
const old = await db.manager.findOne(entities_1.FkDownloadTaskEntity, { where: { filename: task.filename } });
|
24
|
+
// not exist
|
25
|
+
if (!old) {
|
26
|
+
complete();
|
27
|
+
}
|
22
28
|
// > 1G give up
|
23
29
|
if (task.total >= 1024 * 1024 * 1024) {
|
24
30
|
complete();
|
25
31
|
}
|
26
|
-
if (!(0, fs_1.existsSync)(task.path)) {
|
32
|
+
if (!(0, fs_1.existsSync)(task.path) || (old.fileMd5 && old.fileMd5.length > 0)) {
|
33
|
+
await db.manager.update(entities_1.FkDownloadTaskEntity, task.filename, { status: 0 });
|
34
|
+
complete();
|
35
|
+
}
|
36
|
+
if (old.status === 1) {
|
37
|
+
if (this.runingCount > 3) {
|
38
|
+
throw new Error(`system is busy`);
|
39
|
+
}
|
40
|
+
this.runingCount += 1;
|
41
|
+
// upload
|
42
|
+
await fk.startUploadFile(task).then(async (res) => {
|
43
|
+
// create effect task
|
44
|
+
console.log(`upload success`, res.filename);
|
45
|
+
await db.manager.update(entities_1.FkDownloadTaskEntity, task.filename, { status: 2, uploadUrl: task.uploadUrl, uploadSize: task.total, uploadStatus: 1 });
|
46
|
+
const effectTask = await taskService.createEffectTask(res.filename, res.uploadUrl, task.topicId, task.path);
|
47
|
+
return manager.send(effectTask).then(() => complete());
|
48
|
+
});
|
49
|
+
}
|
50
|
+
else {
|
27
51
|
complete();
|
28
52
|
}
|
29
|
-
await fk.startUploadFile(task).then(async (res) => {
|
30
|
-
// create effect task
|
31
|
-
console.log(`upload success`, res.filename);
|
32
|
-
await db.manager.update(entities_1.FkDownloadTaskEntity, task.filename, { status: 2, uploadUrl: task.uploadUrl, uploadSize: task.total, uploadStatus: 1 });
|
33
|
-
const effectTask = await taskService.createEffectTask(res.filename, res.uploadUrl, task.topicId, task.path);
|
34
|
-
return manager.send(effectTask).then(() => complete());
|
35
|
-
});
|
36
53
|
if (next)
|
37
54
|
await next();
|
38
55
|
}
|