@nger/fk-upload 1.0.28 → 1.0.31

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.
@@ -62,6 +62,7 @@ export declare class TaskService {
62
62
  private getUploadInfourl;
63
63
  private encodeURIComponent;
64
64
  private getUploadUrl;
65
+ reUploadTask(): Promise<void>;
65
66
  startUploadTask(filename: string): Promise<void>;
66
67
  download(task: DownloadTask): Observable<DownloadTask>;
67
68
  }
@@ -70,15 +70,16 @@ let TaskService = class TaskService {
70
70
  async createDownLoadTask(url, fkLoginId, topicId) {
71
71
  const hash = await (0, multihashing_async_1.default)(Buffer.from(url), 'sha1', 16);
72
72
  const cid = new cids_1.default(1, 'raw', hash, 'base64');
73
- const filename = encodeURIComponent(cid.toString('base64'));
73
+ let filename = encodeURIComponent(cid.toString('base64'));
74
74
  const _url = new URL(url);
75
75
  const filePath = _url.pathname;
76
- const ext = (0, path_1.extname)(filePath);
76
+ let ext = (0, path_1.extname)(filePath);
77
+ filename += ext === '.' ? '.mp4' : ext;
77
78
  const task = new entities_1.FkDownloadTaskEntity();
78
79
  const root = this.injector.get(core_1.APP_ROOT);
79
80
  (0, fs_extra_1.ensureDirSync)((0, path_1.join)(root, 'attachments/fk-upload'));
80
- const path = (0, path_1.join)(root, 'attachments/fk-upload', filename + ext);
81
- task.filename = filename + ext;
81
+ const path = (0, path_1.join)(root, 'attachments/fk-upload', filename);
82
+ task.filename = filename;
82
83
  task.url = url;
83
84
  task.loginId = fkLoginId;
84
85
  task.totalSize = 0;
@@ -202,55 +203,59 @@ let TaskService = class TaskService {
202
203
  total: task.total
203
204
  }
204
205
  });
205
- this.redis.set(task.filename, `${task.index + 1}`);
206
- if (data) {
207
- // fullDownUrl
208
- const downUrl = data.fullDownUrl;
209
- if (downUrl) {
210
- const fullUrl = downUrl.startsWith('http') ? downUrl : `https:` + downUrl;
211
- console.log({ data, task });
212
- axios_1.default.post(`https://smr00.vip.webportal.top/ajax/advanceUpload.jsp?cmd=_report&_TOKEN=${task.token}`, this.encodeURIComponent({
213
- type: 1,
214
- size: task.total,
215
- time: NaN,
216
- flag: true,
217
- name: task.filename
218
- }), {
219
- headers: {
220
- [`Content-Type`]: `application/x-www-form-urlencoded; charset=UTF-8`,
221
- Cookie: task.cookies
222
- }
223
- });
224
- this.redis.del(task.filename);
225
- this.ws.send({
226
- action: `@nger/fk-upload/uploading`,
227
- data: {
228
- uploadSize: task.end,
206
+ this.redis.set(task.filename, `${task.index + 1}`, (err) => {
207
+ if (err)
208
+ return fail();
209
+ if (data) {
210
+ // fullDownUrl
211
+ const downUrl = data.path;
212
+ if (downUrl) {
213
+ const fullUrl = downUrl.startsWith('http') ? downUrl : `https:` + downUrl;
214
+ axios_1.default.post(`https://smr00.vip.webportal.top/ajax/advanceUpload.jsp?cmd=_report&_TOKEN=${task.token}`, this.encodeURIComponent({
215
+ type: 1,
216
+ size: task.total,
217
+ time: NaN,
218
+ flag: true,
219
+ name: task.filename
220
+ }), {
221
+ headers: {
222
+ [`Content-Type`]: `application/x-www-form-urlencoded; charset=UTF-8`,
223
+ Cookie: task.cookies
224
+ }
225
+ });
226
+ this.redis.del(task.filename, () => {
227
+ complete();
228
+ });
229
+ this.ws.send({
230
+ action: `@nger/fk-upload/uploading`,
231
+ data: {
232
+ uploadSize: task.end,
233
+ filename: task.filename,
234
+ total: task.total,
235
+ uploadUrl: fullUrl
236
+ }
237
+ });
238
+ this.addEffectTask({
229
239
  filename: task.filename,
230
- total: task.total,
231
- uploadUrl: fullUrl
232
- }
233
- });
234
- this.addEffectTask({
235
- filename: task.filename,
236
- uploadUrl: fullUrl,
237
- topicId: task.topicId
238
- });
239
- this.db.manager.update(entities_1.FkDownloadTaskEntity, task.filename, {
240
- status: 2,
241
- uploadUrl: fullUrl,
242
- uploadSize: task.total
243
- }).then(() => complete()).catch(() => fail());
240
+ uploadUrl: fullUrl,
241
+ topicId: task.topicId
242
+ });
243
+ this.db.manager.update(entities_1.FkDownloadTaskEntity, task.filename, {
244
+ status: 2,
245
+ uploadUrl: fullUrl,
246
+ uploadSize: task.total
247
+ });
248
+ }
249
+ else {
250
+ this.db.manager.update(entities_1.FkDownloadTaskEntity, task.filename, {
251
+ uploadSize: task.end
252
+ });
253
+ }
244
254
  }
245
255
  else {
246
- this.db.manager.update(entities_1.FkDownloadTaskEntity, task.filename, {
247
- uploadSize: task.end
248
- }).then(() => complete()).catch(() => fail());
256
+ console.log(`data is empty`, uploadResult);
249
257
  }
250
- }
251
- else {
252
- fail();
253
- }
258
+ });
254
259
  }
255
260
  else {
256
261
  fail();
@@ -330,6 +335,7 @@ let TaskService = class TaskService {
330
335
  return `https://${token.url}/${token.visitType}/${token.app}/advance?cmd=${token.cmd}&token=${token.token}`;
331
336
  }
332
337
  }
338
+ async reUploadTask() { }
333
339
  async startUploadTask(filename) {
334
340
  const task = await this.db.manager.findOne(entities_1.FkDownloadTaskEntity, { where: { filename } });
335
341
  if (task && task.status === 1) {
@@ -374,8 +380,8 @@ let TaskService = class TaskService {
374
380
  const { delayTime, splitSize, uploadedSize } = data;
375
381
  const uploadUrl = this.getUploadUrl(accessToken, false);
376
382
  const totalChunks = Math.ceil((task.totalSize) / splitSize);
377
- let start = 0;
378
- let index = 0;
383
+ let start = uploadedSize;
384
+ let index = Math.ceil(uploadedSize / splitSize);
379
385
  let complete = false;
380
386
  this.beginUploadTask(task.filename);
381
387
  do {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nger/fk-upload",
3
- "version": "1.0.28",
3
+ "version": "1.0.31",
4
4
  "description": "",
5
5
  "main": "dist/core.js",
6
6
  "types": "dist/core.d.ts",