@nger/fk-upload 1.0.106 → 1.0.109
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.
- package/dist/templates/check-upload.js +1 -1
- package/dist/templates/tasks/check-task.js +3 -0
- package/dist/templates/tasks/download-task.js +8 -0
- package/dist/templates/tasks/fk.service.d.ts +2 -0
- package/dist/templates/tasks/fk.service.js +24 -0
- package/dist/templates/tasks/upload-task.d.ts +1 -0
- package/dist/templates/tasks/upload-task.js +10 -0
- package/package.json +1 -1
@@ -107,7 +107,7 @@ let CheckUploadController = class CheckUploadController {
|
|
107
107
|
const item = new rabbitmq_1.TaskEntity();
|
108
108
|
item.topic = actions_1.CHECK_ACTION;
|
109
109
|
item.data = { filename: finish.filename };
|
110
|
-
this.manager.send(item);
|
110
|
+
return this.manager.send(item);
|
111
111
|
}));
|
112
112
|
return { list: finishs.map(it => it.filename) };
|
113
113
|
}
|
@@ -66,6 +66,14 @@ class DownloadTask extends rabbitmq_1.Task {
|
|
66
66
|
console.log(`file download success ${task.filename}: ${fileMd5}`);
|
67
67
|
const db = injector.get(typeorm_1.Db);
|
68
68
|
await db.manager.update(entities_1.FkDownloadTaskEntity, task.filename, { totalSize: total, fileMd5: fileMd5, status: 1, size: total });
|
69
|
+
const fk = injector.get(fk_service_1.FkService);
|
70
|
+
const shouldSize = await fk.getSize(task.url);
|
71
|
+
const localSize = await fk.getLocalSize(task.path);
|
72
|
+
if (shouldSize != localSize) {
|
73
|
+
// download
|
74
|
+
await fail();
|
75
|
+
return next && next();
|
76
|
+
}
|
69
77
|
const uploadTask = await this.createUploadTask(task, total, fileMd5, injector);
|
70
78
|
await manager.send(uploadTask);
|
71
79
|
await complete();
|
@@ -4,6 +4,7 @@ import { IUploadTask } from "./actions";
|
|
4
4
|
export declare class FkService {
|
5
5
|
private db;
|
6
6
|
constructor(db: Db);
|
7
|
+
getLocalSize(path: string): number;
|
7
8
|
getFkLogin(loginId: number): Promise<FkLoginEntity>;
|
8
9
|
getFkLoginCookie(loginId: number): Promise<FkLoginCookieEntity[]>;
|
9
10
|
createCookieStr(cookies: FkLoginCookieEntity[]): string;
|
@@ -14,6 +15,7 @@ export declare class FkService {
|
|
14
15
|
getUploadUrl(token: any, forceDirect?: boolean): string;
|
15
16
|
getUploadInfo(loginId: number, filename: string, fileMd5: string, totalSize: number): Promise<any>;
|
16
17
|
startUploadFile(task: IUploadTask): Promise<IUploadTask>;
|
18
|
+
getSize(url: string): Promise<number>;
|
17
19
|
uploadFile(task: IUploadTask): Promise<IUploadTask>;
|
18
20
|
getBssInfo(): {
|
19
21
|
fromSite: boolean;
|
@@ -8,11 +8,21 @@ const axios_1 = tslib_1.__importDefault(require("axios"));
|
|
8
8
|
const core_1 = require("@nger/core");
|
9
9
|
const fs_extra_1 = require("fs-extra");
|
10
10
|
const form_data_1 = tslib_1.__importDefault(require("form-data"));
|
11
|
+
const request_1 = require("request");
|
11
12
|
let FkService = class FkService {
|
12
13
|
db;
|
13
14
|
constructor(db) {
|
14
15
|
this.db = db;
|
15
16
|
}
|
17
|
+
getLocalSize(path) {
|
18
|
+
try {
|
19
|
+
const stat = (0, fs_extra_1.statSync)(path);
|
20
|
+
return stat.size;
|
21
|
+
}
|
22
|
+
catch (e) {
|
23
|
+
return 0;
|
24
|
+
}
|
25
|
+
}
|
16
26
|
async getFkLogin(loginId) {
|
17
27
|
return await this.db.manager.findOneOrFail(entities_1.FkLoginEntity, { where: { fkLoginId: loginId } });
|
18
28
|
}
|
@@ -100,6 +110,20 @@ let FkService = class FkService {
|
|
100
110
|
task.index = Math.ceil(info.uploadedSize / info.splitSize);
|
101
111
|
return await this.uploadFile(task);
|
102
112
|
}
|
113
|
+
async getSize(url) {
|
114
|
+
const size = (0, core_1.defer)();
|
115
|
+
const req = (0, request_1.get)(url, {
|
116
|
+
headers: {
|
117
|
+
'Content-Type': 'application/octet-stream'
|
118
|
+
}
|
119
|
+
});
|
120
|
+
req.on('response', async (resp) => {
|
121
|
+
const headers = resp.headers;
|
122
|
+
size.resolve(Number(headers["content-length"]));
|
123
|
+
req.destroy();
|
124
|
+
});
|
125
|
+
return size;
|
126
|
+
}
|
103
127
|
async uploadFile(task) {
|
104
128
|
let complete = false;
|
105
129
|
const max = task.total - 1;
|
@@ -13,6 +13,15 @@ class UploadTask extends rabbitmq_1.Task {
|
|
13
13
|
constructor() {
|
14
14
|
super(actions_1.UPLOAD_ACTION);
|
15
15
|
}
|
16
|
+
getLocalSize(path) {
|
17
|
+
try {
|
18
|
+
const stat = (0, fs_1.statSync)(path);
|
19
|
+
return stat.size;
|
20
|
+
}
|
21
|
+
catch (e) {
|
22
|
+
return 0;
|
23
|
+
}
|
24
|
+
}
|
16
25
|
async handle(injector, next) {
|
17
26
|
const task = injector.get(rabbitmq_1.DATA);
|
18
27
|
const complete = injector.get(rabbitmq_1.COMPLETE);
|
@@ -20,6 +29,7 @@ class UploadTask extends rabbitmq_1.Task {
|
|
20
29
|
const taskService = injector.get(task_service_1.TaskService);
|
21
30
|
const manager = injector.get(rabbitmq_1.TaskManager);
|
22
31
|
const db = injector.get(typeorm_1.Db);
|
32
|
+
// check file size
|
23
33
|
const old = await db.manager.findOne(entities_1.FkDownloadTaskEntity, { where: { filename: task.filename } });
|
24
34
|
// not exist
|
25
35
|
if (!old) {
|