@nger/fk-upload 1.0.40 → 1.0.41
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,8 @@ const fs_extra_1 = require("fs-extra");
|
|
12
12
|
const path_1 = require("path");
|
13
13
|
const typeorm_1 = require("@nger/typeorm");
|
14
14
|
const entities_1 = require("../../entities");
|
15
|
+
const rxjs_1 = require("rxjs");
|
16
|
+
const operators_1 = require("rxjs/operators");
|
15
17
|
/**
|
16
18
|
* upload and task
|
17
19
|
*/
|
@@ -20,6 +22,7 @@ class DownloadTask extends rabbitmq_1.Task {
|
|
20
22
|
super(actions_1.DOWNLOAD_ACTION);
|
21
23
|
}
|
22
24
|
async handle(injector, next) {
|
25
|
+
const db = injector.get(typeorm_1.Db);
|
23
26
|
const task = injector.get(rabbitmq_1.DATA);
|
24
27
|
const complete = injector.get(rabbitmq_1.COMPLETE);
|
25
28
|
const fail = injector.get(rabbitmq_1.FAIL);
|
@@ -33,10 +36,18 @@ class DownloadTask extends rabbitmq_1.Task {
|
|
33
36
|
}
|
34
37
|
});
|
35
38
|
let total = 0;
|
39
|
+
let length = 0;
|
36
40
|
let md5 = ``;
|
41
|
+
console.log(`download ${url}`);
|
42
|
+
const sub = new rxjs_1.Subject();
|
43
|
+
sub.pipe((0, operators_1.throttleTime)(1000), (0, operators_1.switchMap)((size) => {
|
44
|
+
console.log(`download ${task.filename}: ${length}`);
|
45
|
+
return db.manager.update(entities_1.FkDownloadTaskEntity, task.filename, { size });
|
46
|
+
})).subscribe();
|
37
47
|
// get split size
|
38
48
|
req.on('data', (buf) => {
|
39
49
|
length += buf.length;
|
50
|
+
sub.next(length);
|
40
51
|
writeStream.write(buf, (err) => {
|
41
52
|
if (err)
|
42
53
|
fail();
|
@@ -44,6 +55,7 @@ class DownloadTask extends rabbitmq_1.Task {
|
|
44
55
|
});
|
45
56
|
req.on('end', async () => {
|
46
57
|
writeStream.end();
|
58
|
+
sub.complete();
|
47
59
|
const fileMd5 = await (0, md5_file_1.default)(task.path);
|
48
60
|
const isEqual = md5 === fileMd5;
|
49
61
|
console.log(`file download success ${task.filename}, check result is ${isEqual}`);
|