@nger/fk-upload 1.0.123 → 1.0.126
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.
@@ -7,7 +7,6 @@ const typeorm_1 = require("@nger/typeorm");
|
|
7
7
|
const w7_1 = require("@nger/w7");
|
8
8
|
const entities_1 = require("../../entities");
|
9
9
|
const fs_extra_1 = require("fs-extra");
|
10
|
-
const task_service_1 = require("./task.service");
|
11
10
|
class EffectTask extends rabbitmq_1.Task {
|
12
11
|
constructor() {
|
13
12
|
super(actions_1.EFFECT_ACTION);
|
@@ -17,31 +16,44 @@ class EffectTask extends rabbitmq_1.Task {
|
|
17
16
|
const task = injector.get(rabbitmq_1.DATA);
|
18
17
|
const complete = injector.get(rabbitmq_1.COMPLETE);
|
19
18
|
const manager = injector.get(rabbitmq_1.TaskManager);
|
20
|
-
const taskService = injector.get(task_service_1.TaskService);
|
21
19
|
console.log(`effect`, task.filename);
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
20
|
+
try {
|
21
|
+
if (task.uploadUrl.startsWith('https://site')) {
|
22
|
+
// redownload
|
23
|
+
const item = await db.manager.findOne(entities_1.FkDownloadTaskEntity, { where: { filename: task.filename } });
|
24
|
+
if (item) {
|
25
|
+
const download = {
|
26
|
+
filename: item.filename,
|
27
|
+
path: item.path,
|
28
|
+
url: item.url,
|
29
|
+
topicId: item.topicId,
|
30
|
+
loginId: item.loginId
|
31
|
+
};
|
32
|
+
const downloadTask = new rabbitmq_1.TaskEntity();
|
33
|
+
downloadTask.topic = actions_1.DOWNLOAD_ACTION;
|
34
|
+
downloadTask.data = download;
|
35
|
+
await manager.send(downloadTask);
|
36
|
+
}
|
37
|
+
await complete();
|
38
|
+
return next && next();
|
28
39
|
}
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
await (
|
40
|
+
const fail = injector.get(rabbitmq_1.FAIL);
|
41
|
+
const w7 = injector.get(w7_1.W7DataSource);
|
42
|
+
await db.manager.update(entities_1.FkDownloadTaskEntity, task.filename, { status: 3 });
|
43
|
+
if (task.topicId) {
|
44
|
+
try {
|
45
|
+
await (0, fs_extra_1.unlink)(task.path);
|
46
|
+
}
|
47
|
+
catch (e) { }
|
48
|
+
await w7.manager.update(w7_1.W7ChatTopicEntity, task.topicId, { foreverUrl: task.uploadUrl }).then(() => complete()).catch(() => fail());
|
49
|
+
await complete();
|
50
|
+
}
|
51
|
+
else {
|
52
|
+
await complete();
|
38
53
|
}
|
39
|
-
catch (e) { }
|
40
|
-
await w7.manager.update(w7_1.W7ChatTopicEntity, task.topicId, { foreverUrl: task.uploadUrl }).then(() => complete()).catch(() => fail());
|
41
|
-
await complete();
|
42
54
|
}
|
43
|
-
|
44
|
-
|
55
|
+
catch (e) {
|
56
|
+
console.log(`effect error`, e.message);
|
45
57
|
}
|
46
58
|
if (next)
|
47
59
|
await next();
|
@@ -125,72 +125,83 @@ let FkService = class FkService {
|
|
125
125
|
return size;
|
126
126
|
}
|
127
127
|
async uploadFile(task) {
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
128
|
+
const upload = async () => {
|
129
|
+
const info = await this.getUploadInfo(task.loginId, task.filename, task.fileMd5, task.total);
|
130
|
+
task.cookies = info.cookies;
|
131
|
+
task.splitSize = info.splitSize;
|
132
|
+
task.start = info.uploadedSize;
|
133
|
+
task.uploadUrl = info.uploadUrl;
|
134
|
+
task.index = Math.ceil(info.uploadedSize / info.splitSize);
|
135
|
+
let complete = false;
|
136
|
+
const max = task.total - 1;
|
137
|
+
let index = task.index || 0;
|
138
|
+
let uploadResult;
|
139
|
+
do {
|
140
|
+
let start = index * task.splitSize;
|
141
|
+
let _end = start + task.splitSize - 1;
|
142
|
+
let end = _end > max ? max : _end;
|
143
|
+
if (end >= max) {
|
144
|
+
complete = true;
|
145
|
+
}
|
146
|
+
const fileStream = (0, fs_extra_1.createReadStream)(task.path, { start: start, end: end });
|
147
|
+
const formdata = new form_data_1.default();
|
148
|
+
formdata.append('ctrl', fileStream);
|
149
|
+
formdata.append('isFreeVer', this.encodeURIComponent(false));
|
150
|
+
formdata.append('aid', this.encodeURIComponent(task.aid));
|
151
|
+
formdata.append('folderId', this.encodeURIComponent(task.folderId));
|
152
|
+
formdata.append('fileName', task.filename);
|
153
|
+
formdata.append(`totalSize`, this.encodeURIComponent(task.total));
|
154
|
+
formdata.append(`fileMd5`, task.fileMd5);
|
155
|
+
formdata.append('index', this.encodeURIComponent(index));
|
156
|
+
formdata.append('chunkSize', this.encodeURIComponent(task.splitSize));
|
157
|
+
formdata.append('totalChunks', this.encodeURIComponent(task.totalChunks));
|
158
|
+
formdata.append(`complete`, this.encodeURIComponent(complete));
|
159
|
+
const bssInfo = {
|
160
|
+
fromSite: true, siteId: 0, groupId: 0, fileSizeLimit: 1024
|
161
|
+
};
|
162
|
+
formdata.append('bssInfo', JSON.stringify(bssInfo));
|
163
|
+
const headers = formdata.getHeaders();
|
164
|
+
uploadResult = await axios_1.default.post(task.uploadUrl, formdata, {
|
165
|
+
headers: {
|
166
|
+
...headers,
|
167
|
+
Cookie: task.cookies
|
168
|
+
},
|
169
|
+
timeout: 8000
|
170
|
+
}).then(res => {
|
171
|
+
return res.data;
|
172
|
+
}).catch((e) => {
|
173
|
+
console.log(`upload error`, e.message);
|
174
|
+
return upload();
|
175
|
+
});
|
176
|
+
if (uploadResult.code !== 200) {
|
177
|
+
if (uploadResult.data) {
|
178
|
+
const data = uploadResult.data;
|
179
|
+
if (data.limit) {
|
180
|
+
// to big
|
181
|
+
throw new Error(`to big`);
|
182
|
+
}
|
173
183
|
}
|
184
|
+
throw new Error(`${task.filename}--${uploadResult.msg}`);
|
174
185
|
}
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
186
|
+
console.log(`upload ----- `, { index, max, start, end });
|
187
|
+
if (uploadResult) {
|
188
|
+
const data = uploadResult.data;
|
189
|
+
const downUrl = data.path;
|
190
|
+
if (downUrl) {
|
191
|
+
if (downUrl.startsWith('https://site-upload')) {
|
192
|
+
console.log(`upload fail`);
|
193
|
+
throw new Error(`need re bind`);
|
194
|
+
}
|
195
|
+
const fullUrl = downUrl.startsWith('http') ? downUrl : `https:` + downUrl;
|
196
|
+
task.uploadUrl = fullUrl;
|
185
197
|
}
|
186
|
-
const fullUrl = downUrl.startsWith('http') ? downUrl : `https:` + downUrl;
|
187
|
-
task.uploadUrl = fullUrl;
|
188
198
|
}
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
199
|
+
index = index + 1;
|
200
|
+
} while (!complete);
|
201
|
+
return uploadResult;
|
202
|
+
};
|
203
|
+
const result = await upload();
|
204
|
+
console.log(`upload result: -----> `, result);
|
194
205
|
// upload complete
|
195
206
|
axios_1.default.post(`https://smr00.vip.webportal.top/ajax/advanceUpload.jsp?cmd=_report&_TOKEN=${task.token}`, this.encodeURIComponent({
|
196
207
|
type: 1,
|