@nger/fk-upload 1.0.161 → 1.0.165
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/{tests/test.d.ts → electon.d.ts} +0 -0
- package/dist/electon.js +70 -0
- package/dist/templates/add-fk-login.js +1 -3
- package/dist/templates/add-task.d.ts +1 -1
- package/dist/templates/add-task.js +11 -5
- package/dist/templates/code.js +2 -1
- package/dist/templates/component.js +1 -1
- package/dist/templates/help.js +0 -1
- package/dist/templates/setting.d.ts +1 -3
- package/dist/templates/setting.js +2 -5
- package/dist/templates/task-manage.d.ts +5 -1
- package/dist/templates/task-manage.js +71 -34
- package/dist/templates/tasks/upload-task.js +11 -6
- package/electron/.env +32 -0
- package/electron/package.json +31 -0
- package/electron/pnpm-lock.yaml +2888 -0
- package/env.env +30 -0
- package/package.json +14 -5
- package/pnpm-lock.yaml +1847 -103
- package/dist/entities/fk-login-account.entity.d.ts +0 -6
- package/dist/entities/fk-login-account.entity.js +0 -47
- package/dist/fk-upload.controller.d.ts +0 -28
- package/dist/fk-upload.controller.js +0 -271
- package/dist/fk-v2.service.d.ts +0 -29
- package/dist/fk-v2.service.js +0 -152
- package/dist/fk.service.d.ts +0 -17
- package/dist/fk.service.js +0 -89
- package/dist/templates/account-manage.d.ts +0 -3
- package/dist/templates/account-manage.js +0 -27
- package/dist/templates/add-account.d.ts +0 -0
- package/dist/templates/add-account.js +0 -1
- package/dist/templates/create-download-task.d.ts +0 -0
- package/dist/templates/create-download-task.js +0 -1
- package/dist/templates/download-task.d.ts +0 -10
- package/dist/templates/download-task.js +0 -47
- package/dist/templates/login.service.d.ts +0 -2
- package/dist/templates/login.service.js +0 -16
- package/dist/templates/receive-shedule-task.d.ts +0 -14
- package/dist/templates/receive-shedule-task.js +0 -64
- package/dist/templates/relogin.d.ts +0 -5
- package/dist/templates/relogin.js +0 -25
- package/dist/templates/task-types.d.ts +0 -34
- package/dist/templates/task-types.js +0 -2
- package/dist/templates/task.service.d.ts +0 -0
- package/dist/templates/task.service.js +0 -407
- package/dist/templates/tasks/create-download-task.d.ts +0 -12
- package/dist/templates/tasks/create-download-task.js +0 -65
- package/dist/templates/tasks/index.d.ts +0 -0
- package/dist/templates/tasks/index.js +0 -1
- package/dist/templates/tasks/receive-shedule-task.d.ts +0 -16
- package/dist/templates/tasks/receive-shedule-task.js +0 -66
- package/dist/templates/upload.service.d.ts +0 -0
- package/dist/templates/upload.service.js +0 -1
- package/dist/tests/test.js +0 -101
File without changes
|
@@ -1 +0,0 @@
|
|
1
|
-
"use strict";
|
@@ -1,10 +0,0 @@
|
|
1
|
-
import { Db } from '@nger/typeorm';
|
2
|
-
import { Context } from 'koa';
|
3
|
-
import { UploadService } from './upload.service';
|
4
|
-
export declare const CREATE_TASK_DOWNLOADING = "@nger/fk-upload/create-task/downloading";
|
5
|
-
export declare class DownloadTaskController {
|
6
|
-
private db;
|
7
|
-
private upload;
|
8
|
-
constructor(db: Db, upload: UploadService);
|
9
|
-
createTask(url: string, ctx: Context): Promise<void>;
|
10
|
-
}
|
@@ -1,47 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
7
|
-
};
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
10
|
-
};
|
11
|
-
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
12
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
13
|
-
};
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
15
|
-
exports.DownloadTaskController = exports.CREATE_TASK_DOWNLOADING = void 0;
|
16
|
-
const core_1 = require("@nger/core");
|
17
|
-
const http_1 = require("@nger/http");
|
18
|
-
const typeorm_1 = require("@nger/typeorm");
|
19
|
-
const upload_service_1 = require("./upload.service");
|
20
|
-
// md5-file
|
21
|
-
exports.CREATE_TASK_DOWNLOADING = `@nger/fk-upload/create-task/downloading`;
|
22
|
-
let DownloadTaskController = class DownloadTaskController {
|
23
|
-
db;
|
24
|
-
upload;
|
25
|
-
constructor(db, upload) {
|
26
|
-
this.db = db;
|
27
|
-
this.upload = upload;
|
28
|
-
}
|
29
|
-
async createTask(url, ctx) {
|
30
|
-
this.upload.createDownLoadTask(url);
|
31
|
-
ctx.redirect('/@nger/fk-upload/help');
|
32
|
-
return;
|
33
|
-
}
|
34
|
-
};
|
35
|
-
__decorate([
|
36
|
-
(0, http_1.Get)('create-task'),
|
37
|
-
__param(0, (0, http_1.Query)('url')),
|
38
|
-
__param(1, (0, core_1.Inject)(http_1.CONTEXT)),
|
39
|
-
__metadata("design:type", Function),
|
40
|
-
__metadata("design:paramtypes", [String, Object]),
|
41
|
-
__metadata("design:returntype", Promise)
|
42
|
-
], DownloadTaskController.prototype, "createTask", null);
|
43
|
-
DownloadTaskController = __decorate([
|
44
|
-
(0, core_1.Controller)('@nger/fk-upload'),
|
45
|
-
__metadata("design:paramtypes", [typeorm_1.Db, upload_service_1.UploadService])
|
46
|
-
], DownloadTaskController);
|
47
|
-
exports.DownloadTaskController = DownloadTaskController;
|
@@ -1,16 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
7
|
-
};
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
9
|
-
exports.LoginService = void 0;
|
10
|
-
const core_1 = require("@nger/core");
|
11
|
-
let LoginService = class LoginService {
|
12
|
-
};
|
13
|
-
LoginService = __decorate([
|
14
|
-
(0, core_1.Injectable)()
|
15
|
-
], LoginService);
|
16
|
-
exports.LoginService = LoginService;
|
@@ -1,14 +0,0 @@
|
|
1
|
-
import { RabbitMqService } from "@nger/rabbitmq";
|
2
|
-
import { RedisService } from "@nger/redis";
|
3
|
-
import { ScheduleService } from "@nger/schedule";
|
4
|
-
import { Db } from "@nger/typeorm";
|
5
|
-
import { W7DataSource } from "packages/w7/dist/core";
|
6
|
-
export declare class ReceiveScheduleTask {
|
7
|
-
private rabbit;
|
8
|
-
private redis;
|
9
|
-
private schedule;
|
10
|
-
private db;
|
11
|
-
private w7;
|
12
|
-
constructor(rabbit: RabbitMqService, redis: RedisService, schedule: ScheduleService, db: Db, w7: W7DataSource);
|
13
|
-
receiveScheduleTask(runner: Function): Promise<void>;
|
14
|
-
}
|
@@ -1,64 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.ReceiveScheduleTask = void 0;
|
4
|
-
const core_1 = require("packages/w7/dist/core");
|
5
|
-
const entities_1 = require("../entities");
|
6
|
-
const typeorm_1 = require("typeorm");
|
7
|
-
class ReceiveScheduleTask {
|
8
|
-
rabbit;
|
9
|
-
redis;
|
10
|
-
schedule;
|
11
|
-
db;
|
12
|
-
w7;
|
13
|
-
constructor(rabbit, redis, schedule, db, w7) {
|
14
|
-
this.rabbit = rabbit;
|
15
|
-
this.redis = redis;
|
16
|
-
this.schedule = schedule;
|
17
|
-
this.db = db;
|
18
|
-
this.w7 = w7;
|
19
|
-
}
|
20
|
-
async receiveScheduleTask(runner) {
|
21
|
-
const obs = await this.rabbit.receive(`@nger/fk-upload/schedule-task`);
|
22
|
-
obs.subscribe({
|
23
|
-
next: async ([data, complete, fail]) => {
|
24
|
-
try {
|
25
|
-
const task = JSON.parse(data);
|
26
|
-
const setting = await this.redis.get(`setting`);
|
27
|
-
if (!setting) {
|
28
|
-
return complete();
|
29
|
-
}
|
30
|
-
if (task.name === setting.name) {
|
31
|
-
console.log(`shedule job regist ${task.name}`);
|
32
|
-
this.schedule.scheduleJob(task.name, task.rule, async (time) => {
|
33
|
-
const accounts = await this.db.manager.find(entities_1.FkLoginEntity, {});
|
34
|
-
const w7Usernames = accounts.map(account => account.w7Username);
|
35
|
-
const users = await this.w7.manager.find(core_1.W7UsersEntity, { where: { username: (0, typeorm_1.In)(w7Usernames) } });
|
36
|
-
const uids = users.map(user => user.uid);
|
37
|
-
const uniAccounts = await this.w7.manager.find(core_1.W7UniAccountEntity, { where: { createUid: (0, typeorm_1.In)(uids) } });
|
38
|
-
const uniacids = uniAccounts.map(a => a.uniacid);
|
39
|
-
const tasks = await this.db.manager.find(entities_1.FkDownloadTaskEntity, { select: ['topicId'] });
|
40
|
-
const ids = tasks.map(task => task.topicId);
|
41
|
-
const topics = await this.w7.manager.find(core_1.W7ChatTopicEntity, { where: { uniacid: (0, typeorm_1.In)(uniacids), id: (0, typeorm_1.Not)((0, typeorm_1.In)(ids)) } });
|
42
|
-
topics.map(topic => {
|
43
|
-
if (topic.thirdUrl) {
|
44
|
-
const uniacid = topic.uniacid;
|
45
|
-
const account = uniAccounts.find(a => a.uniacid === uniacid);
|
46
|
-
const user = users.find(u => u.uid === account.createUid);
|
47
|
-
const login = accounts.find(a => a.w7Username === user.username);
|
48
|
-
this.createDownLoadTask(topic.thirdUrl, login.fkLoginId, topic.id);
|
49
|
-
}
|
50
|
-
});
|
51
|
-
});
|
52
|
-
}
|
53
|
-
else {
|
54
|
-
complete();
|
55
|
-
}
|
56
|
-
}
|
57
|
-
catch (e) {
|
58
|
-
fail();
|
59
|
-
}
|
60
|
-
}
|
61
|
-
});
|
62
|
-
}
|
63
|
-
}
|
64
|
-
exports.ReceiveScheduleTask = ReceiveScheduleTask;
|
@@ -1,25 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
7
|
-
};
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
10
|
-
};
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
12
|
-
exports.ReloginController = void 0;
|
13
|
-
const core_1 = require("@nger/core");
|
14
|
-
const typeorm_1 = require("@nger/typeorm");
|
15
|
-
let ReloginController = class ReloginController {
|
16
|
-
db;
|
17
|
-
constructor(db) {
|
18
|
-
this.db = db;
|
19
|
-
}
|
20
|
-
};
|
21
|
-
ReloginController = __decorate([
|
22
|
-
(0, core_1.Controller)('@nger/fk-upload'),
|
23
|
-
__metadata("design:paramtypes", [typeorm_1.Db])
|
24
|
-
], ReloginController);
|
25
|
-
exports.ReloginController = ReloginController;
|
@@ -1,34 +0,0 @@
|
|
1
|
-
export interface EffectTask {
|
2
|
-
filename: string;
|
3
|
-
uploadUrl: string;
|
4
|
-
topicId: number;
|
5
|
-
}
|
6
|
-
export interface ScheduleTask {
|
7
|
-
name: string;
|
8
|
-
rule: string;
|
9
|
-
}
|
10
|
-
export interface DownloadTask {
|
11
|
-
filename: string;
|
12
|
-
path: string;
|
13
|
-
size: number;
|
14
|
-
url: string;
|
15
|
-
totalSize: number;
|
16
|
-
}
|
17
|
-
export interface UploadTask {
|
18
|
-
filename: string;
|
19
|
-
path: string;
|
20
|
-
uploadUrl: string;
|
21
|
-
start: number;
|
22
|
-
end: number;
|
23
|
-
total: number;
|
24
|
-
cookies: string;
|
25
|
-
aid: number;
|
26
|
-
folderId: number;
|
27
|
-
fileMd5: string;
|
28
|
-
index: number;
|
29
|
-
splitSize: number;
|
30
|
-
totalChunks: number;
|
31
|
-
complete: boolean;
|
32
|
-
topicId: number;
|
33
|
-
token: string;
|
34
|
-
}
|
File without changes
|
@@ -1,407 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
// import { APP_ROOT, Injectable, Injector, isPrimitive } from '@nger/core';
|
3
|
-
// import { RabbitMqService } from '@nger/rabbitmq';
|
4
|
-
// import { Client } from '@nger/redis';
|
5
|
-
// import { Db } from '@nger/typeorm';
|
6
|
-
// import { createReadStream, createWriteStream, ensureDirSync, statSync } from 'fs-extra';
|
7
|
-
// import { FkDownloadTaskEntity, FkLoginCookieEntity, FkLoginEntity } from '../entities';
|
8
|
-
// import { get } from 'request'
|
9
|
-
// import { Observable, throttleTime, switchMap } from 'rxjs';
|
10
|
-
// import { WsService } from '@nger/ws';
|
11
|
-
// import md5file from 'md5-file'
|
12
|
-
// import { In, Not } from 'typeorm';
|
13
|
-
// import Cid from 'cids';
|
14
|
-
// import multihash from 'multihashing-async'
|
15
|
-
// export interface DownloadTask {
|
16
|
-
// filename: string;
|
17
|
-
// path: string;
|
18
|
-
// size: number;
|
19
|
-
// url: string;
|
20
|
-
// totalSize: number;
|
21
|
-
// }
|
22
|
-
// export interface UploadTask {
|
23
|
-
// filename: string;
|
24
|
-
// path: string;
|
25
|
-
// uploadUrl: string;
|
26
|
-
// start: number;
|
27
|
-
// end: number;
|
28
|
-
// total: number;
|
29
|
-
// cookies: string;
|
30
|
-
// aid: number;
|
31
|
-
// folderId: number;
|
32
|
-
// fileMd5: string;
|
33
|
-
// index: number;
|
34
|
-
// splitSize: number;
|
35
|
-
// totalChunks: number;
|
36
|
-
// complete: boolean;
|
37
|
-
// topicId: number;
|
38
|
-
// token: string;
|
39
|
-
// }
|
40
|
-
// import FromData from 'form-data';
|
41
|
-
// import axios from 'axios';
|
42
|
-
// import { ScheduleService } from '@nger/schedule';
|
43
|
-
// import { W7ChatTopicEntity, W7DataSource, W7UniAccountEntity, W7UsersEntity } from '@nger/w7'
|
44
|
-
// import { dirname, extname, join } from 'path';
|
45
|
-
// export interface EffectTask {
|
46
|
-
// filename: string;
|
47
|
-
// uploadUrl: string;
|
48
|
-
// topicId: number;
|
49
|
-
// }
|
50
|
-
// export interface ScheduleTask {
|
51
|
-
// name: string;
|
52
|
-
// rule: string;
|
53
|
-
// }
|
54
|
-
// @Injectable()
|
55
|
-
// export class TaskService {
|
56
|
-
// constructor(
|
57
|
-
// private rabbit: RabbitMqService,
|
58
|
-
// private redis: Client,
|
59
|
-
// private db: Db,
|
60
|
-
// private ws: WsService,
|
61
|
-
// private schedule: ScheduleService,
|
62
|
-
// private w7: W7DataSource,
|
63
|
-
// private injector: Injector
|
64
|
-
// ) { }
|
65
|
-
// async addDownloadTask(task: DownloadTask) {
|
66
|
-
// const content = Buffer.from(JSON.stringify(task));
|
67
|
-
// await this.rabbit.send('@nger/fk-upload/download-task', content)
|
68
|
-
// }
|
69
|
-
// async addUploadTask(task: UploadTask) {
|
70
|
-
// const content = Buffer.from(JSON.stringify(task));
|
71
|
-
// await this.rabbit.send('@nger/fk-upload/upload-task', content)
|
72
|
-
// }
|
73
|
-
// async beginUploadTask(filename: string) {
|
74
|
-
// this.redis.set(filename, `0`);
|
75
|
-
// }
|
76
|
-
// async addEffectTask(task: EffectTask) {
|
77
|
-
// // const content = Buffer.from(JSON.stringify(task)); // await this.rabbit.send('@nger/fk-upload/effect-task', content)
|
78
|
-
// }
|
79
|
-
// async addScheduleTask(task: ScheduleTask) {
|
80
|
-
// const content = Buffer.from(JSON.stringify(task));
|
81
|
-
// await this.rabbit.send('@nger/fk-upload/schedule-task', content)
|
82
|
-
// }
|
83
|
-
// async receiveEffectTask() {
|
84
|
-
// const obs = await this.rabbit.receive(`@nger/fk-upload/effect-task`);
|
85
|
-
// obs.subscribe({
|
86
|
-
// next: async ([data, complete, fail]) => {
|
87
|
-
// const task = JSON.parse(data) as EffectTask;
|
88
|
-
// if (task.topicId) {
|
89
|
-
// this.w7.manager.update(W7ChatTopicEntity, task.topicId, { thirdUrl: task.uploadUrl }).then(() => complete()).catch(() => fail())
|
90
|
-
// } else {
|
91
|
-
// complete();
|
92
|
-
// }
|
93
|
-
// }
|
94
|
-
// })
|
95
|
-
// }
|
96
|
-
// async receiveUploadTask() {
|
97
|
-
// const obs = await this.rabbit.receive(`@nger/fk-upload/upload-task`);
|
98
|
-
// obs.subscribe({
|
99
|
-
// next: async ([data, complete, fail]) => {
|
100
|
-
// const task = JSON.parse(data) as UploadTask;
|
101
|
-
// this.redis.get(task.filename, async (err, reply) => {
|
102
|
-
// if (err) return fail();
|
103
|
-
// if (reply) {
|
104
|
-
// const isExist = await this.db.manager.find(FkDownloadTaskEntity, { where: { filename: task.filename } });
|
105
|
-
// if (!isExist) {
|
106
|
-
// return complete();
|
107
|
-
// }
|
108
|
-
// const taskIndex = Number(reply); // next
|
109
|
-
// const isComplete = task.complete && task.index === taskIndex;
|
110
|
-
// const isShouldRunning = isComplete || (!isComplete && task.index == taskIndex);
|
111
|
-
// if (isShouldRunning) {
|
112
|
-
// // uploading
|
113
|
-
// // should handler
|
114
|
-
// const fileStream = createReadStream(task.path, { start: task.start, end: task.end, encoding: 'utf8' });
|
115
|
-
// const formdata = new FromData();
|
116
|
-
// formdata.append('ctrl', fileStream);
|
117
|
-
// formdata.append('isFreeVer', this.encodeURIComponent(false));
|
118
|
-
// formdata.append('aid', this.encodeURIComponent(task.aid));
|
119
|
-
// formdata.append('folderId', this.encodeURIComponent(task.folderId));
|
120
|
-
// formdata.append('fileName', task.filename);
|
121
|
-
// formdata.append(`totalSize`, this.encodeURIComponent(task.total));
|
122
|
-
// formdata.append(`fileMd5`, task.fileMd5);
|
123
|
-
// formdata.append('index', this.encodeURIComponent(task.index));
|
124
|
-
// formdata.append('chunkSize', this.encodeURIComponent(task.splitSize));
|
125
|
-
// formdata.append('totalChunks', this.encodeURIComponent(task.totalChunks))
|
126
|
-
// formdata.append(`complete`, this.encodeURIComponent(task.complete))
|
127
|
-
// const bssInfo = {
|
128
|
-
// fromSite: true, siteId: 0, groupId: 0, fileSizeLimit: 1024
|
129
|
-
// };
|
130
|
-
// formdata.append('bssInfo', JSON.stringify(bssInfo))
|
131
|
-
// const headers = formdata.getHeaders();
|
132
|
-
// const uploadResult = await axios.post(task.uploadUrl, formdata, {
|
133
|
-
// headers: {
|
134
|
-
// ...headers,
|
135
|
-
// Cookie: task.cookies
|
136
|
-
// }
|
137
|
-
// }).then(res => res.data).catch((e) => fail());
|
138
|
-
// if (uploadResult && uploadResult.code === 200) {
|
139
|
-
// const data = uploadResult.data;
|
140
|
-
// this.ws.send({
|
141
|
-
// action: `@nger/fk-upload/uploading`,
|
142
|
-
// data: {
|
143
|
-
// uploadSize: task.end,
|
144
|
-
// filename: task.filename,
|
145
|
-
// total: task.total
|
146
|
-
// }
|
147
|
-
// });
|
148
|
-
// this.redis.set(task.filename, `${task.index + 1}`, (err) => {
|
149
|
-
// if (err) return fail();
|
150
|
-
// if (data) {
|
151
|
-
// // fullDownUrl
|
152
|
-
// const downUrl = data.path as string;
|
153
|
-
// if (downUrl) {
|
154
|
-
// const fullUrl = downUrl.startsWith('http') ? downUrl : `https:` + downUrl;
|
155
|
-
// axios.post(`https://smr00.vip.webportal.top/ajax/advanceUpload.jsp?cmd=_report&_TOKEN=${task.token}`, this.encodeURIComponent({
|
156
|
-
// type: 1,
|
157
|
-
// size: task.total,
|
158
|
-
// time: NaN,
|
159
|
-
// flag: true,
|
160
|
-
// name: task.filename
|
161
|
-
// }), {
|
162
|
-
// headers: {
|
163
|
-
// [`Content-Type`]: `application/x-www-form-urlencoded; charset=UTF-8`,
|
164
|
-
// Cookie: task.cookies
|
165
|
-
// }
|
166
|
-
// });
|
167
|
-
// this.redis.del(task.filename, () => {
|
168
|
-
// complete()
|
169
|
-
// });
|
170
|
-
// this.ws.send({
|
171
|
-
// action: `@nger/fk-upload/uploading`,
|
172
|
-
// data: {
|
173
|
-
// uploadSize: task.end,
|
174
|
-
// filename: task.filename,
|
175
|
-
// total: task.total,
|
176
|
-
// uploadUrl: fullUrl
|
177
|
-
// }
|
178
|
-
// });
|
179
|
-
// this.addEffectTask({
|
180
|
-
// filename: task.filename,
|
181
|
-
// uploadUrl: fullUrl,
|
182
|
-
// topicId: task.topicId
|
183
|
-
// })
|
184
|
-
// this.db.manager.update(FkDownloadTaskEntity, task.filename, {
|
185
|
-
// status: 2,
|
186
|
-
// uploadUrl: fullUrl,
|
187
|
-
// uploadSize: task.total
|
188
|
-
// })
|
189
|
-
// } else {
|
190
|
-
// this.db.manager.update(FkDownloadTaskEntity, task.filename, {
|
191
|
-
// uploadSize: task.end
|
192
|
-
// })
|
193
|
-
// }
|
194
|
-
// } else {
|
195
|
-
// console.log(`data is empty`, uploadResult)
|
196
|
-
// }
|
197
|
-
// });
|
198
|
-
// } else {
|
199
|
-
// fail();
|
200
|
-
// }
|
201
|
-
// } else {
|
202
|
-
// fail();
|
203
|
-
// }
|
204
|
-
// } else {
|
205
|
-
// return complete();
|
206
|
-
// }
|
207
|
-
// })
|
208
|
-
// }
|
209
|
-
// })
|
210
|
-
// }
|
211
|
-
// async receiveDownloadTask() {
|
212
|
-
// const obs = await this.rabbit.receive(`@nger/fk-upload/download-task`);
|
213
|
-
// obs.subscribe({
|
214
|
-
// next: async ([data, complete, fail]) => {
|
215
|
-
// const task = JSON.parse(data) as DownloadTask;
|
216
|
-
// const download = await this.db.manager.findOne(FkDownloadTaskEntity, { where: { filename: task.filename } });
|
217
|
-
// if (download) {
|
218
|
-
// let total = 0;
|
219
|
-
// download.url = decodeURIComponent(download.url);
|
220
|
-
// this.download(download).pipe(
|
221
|
-
// throttleTime(1000),
|
222
|
-
// switchMap(async res => {
|
223
|
-
// const size = res.size;
|
224
|
-
// total = res.totalSize;
|
225
|
-
// this.ws.send({
|
226
|
-
// action: `@nger/fk-upload/downloading`,
|
227
|
-
// data: { total, size, filename: res.filename }
|
228
|
-
// });
|
229
|
-
// await this.db.manager.update(FkDownloadTaskEntity, download.filename, { size: size, totalSize: total })
|
230
|
-
// return res;
|
231
|
-
// })
|
232
|
-
// ).subscribe({
|
233
|
-
// next: (task) => { },
|
234
|
-
// complete: async () => {
|
235
|
-
// const md5 = await md5file(task.path);
|
236
|
-
// this.db.manager.update(FkDownloadTaskEntity, download.filename, { status: 1, size: total, fileMd5: md5 }).then(async () => {
|
237
|
-
// this.ws.send({
|
238
|
-
// action: `@nger/fk-upload/downloading`,
|
239
|
-
// data: { total, size: total, filename: download.filename }
|
240
|
-
// });
|
241
|
-
// this.redis.del(task.filename);
|
242
|
-
// await this.startUploadTask(task.filename);
|
243
|
-
// complete()
|
244
|
-
// }).catch(() => fail())
|
245
|
-
// },
|
246
|
-
// error: () => {
|
247
|
-
// fail();
|
248
|
-
// }
|
249
|
-
// })
|
250
|
-
// } else {
|
251
|
-
// complete();
|
252
|
-
// }
|
253
|
-
// }
|
254
|
-
// })
|
255
|
-
// }
|
256
|
-
// private getUploadInfourl(token: any) {
|
257
|
-
// return `https://${token.url}/${token.visitType}/${token.app}/advance/info?cmd=${token.cmd}&token=${token.token}`
|
258
|
-
// }
|
259
|
-
// private encodeURIComponent(data: any) {
|
260
|
-
// if (isPrimitive(data)) {
|
261
|
-
// return encodeURIComponent(data)
|
262
|
-
// }
|
263
|
-
// return Object.keys(data).map(key => {
|
264
|
-
// const value = Reflect.get(data, key)
|
265
|
-
// return `${key}=${encodeURIComponent(value)}`
|
266
|
-
// }).join('&')
|
267
|
-
// }
|
268
|
-
// private getUploadUrl(token: any, forceDirect: boolean = true) {
|
269
|
-
// if (forceDirect) {
|
270
|
-
// return `https://${token.url}/${token.visitType}/${token.app}/upload?cmd=${token.cmd}&token=${token.token}`
|
271
|
-
// } else {
|
272
|
-
// return `https://${token.url}/${token.visitType}/${token.app}/advance?cmd=${token.cmd}&token=${token.token}`
|
273
|
-
// }
|
274
|
-
// }
|
275
|
-
// async reUploadTask() { }
|
276
|
-
// async startUploadTask(filename: string) {
|
277
|
-
// const task = await this.db.manager.findOne(FkDownloadTaskEntity, { where: { filename } });
|
278
|
-
// if (task && task.status === 1) {
|
279
|
-
// const loginEntity = await this.db.manager.findOne(FkLoginEntity, { where: { fkLoginId: task.loginId } })
|
280
|
-
// const cookies = await this.db.manager.find(FkLoginCookieEntity, { where: { fkLoginId: task.loginId } });
|
281
|
-
// const cookie = cookies.map(cookie => `${cookie.key}=${cookie.value}`).join(';')
|
282
|
-
// // 00 take token
|
283
|
-
// const url = `https://i.vip.webportal.top/`;
|
284
|
-
// const iVipWebPortal: string = await axios.get(url, {
|
285
|
-
// headers: {
|
286
|
-
// Cookie: cookie
|
287
|
-
// }
|
288
|
-
// }).then(res => res.data);
|
289
|
-
// const items = iVipWebPortal.match(/<meta id='_TOKEN' value='(.*?)'\/>/);
|
290
|
-
// let token: string = ``;
|
291
|
-
// if (items && items.length === 2) {
|
292
|
-
// token = items[1];
|
293
|
-
// }
|
294
|
-
// if (token.length > 0) {
|
295
|
-
// // 01
|
296
|
-
// const url = `https://smr00.vip.webportal.top/cn/api/manage/advanceUpload/genAccessKey?_v=${new Date().getTime()}&_TOKEN=${token}`;
|
297
|
-
// const accessKey = await axios.get(url).then(res => res.data);
|
298
|
-
// if (accessKey.success) {
|
299
|
-
// const accessTokenString = decode(accessKey.accessKey)
|
300
|
-
// if (accessTokenString) {
|
301
|
-
// const accessToken = JSON.parse(accessTokenString);
|
302
|
-
// const uploadInfoUrl = this.getUploadInfourl(accessToken);
|
303
|
-
// const bssInfo = {
|
304
|
-
// fromSite: true, siteId: 0, groupId: 0, fileSizeLimit: 1024
|
305
|
-
// };
|
306
|
-
// const info = await axios.post(uploadInfoUrl, this.encodeURIComponent({
|
307
|
-
// fileMd5: task.fileMd5,
|
308
|
-
// fileSize: task.totalSize,
|
309
|
-
// isFreeVer: false,
|
310
|
-
// aid: loginEntity!.aid,
|
311
|
-
// folderId: loginEntity!.uploadGroupId,
|
312
|
-
// bssInfo: JSON.stringify(bssInfo),
|
313
|
-
// fileName: task.filename
|
314
|
-
// }), { headers: { cookie: cookie } }).then(res => res.data);
|
315
|
-
// if (info.code === 200) {
|
316
|
-
// const data = info.data;
|
317
|
-
// const { delayTime, splitSize, uploadedSize } = data;
|
318
|
-
// const uploadUrl = this.getUploadUrl(accessToken, false);
|
319
|
-
// const totalChunks = Math.ceil((task.totalSize) / splitSize);
|
320
|
-
// let start = uploadedSize;
|
321
|
-
// let index: number = Math.ceil(uploadedSize / splitSize);
|
322
|
-
// let complete: boolean = false;
|
323
|
-
// this.beginUploadTask(task.filename);
|
324
|
-
// do {
|
325
|
-
// const maxEndSize = start + splitSize;
|
326
|
-
// if (index >= totalChunks - 1 || maxEndSize >= task.totalSize) {
|
327
|
-
// complete = true;
|
328
|
-
// }
|
329
|
-
// const endSize = maxEndSize > task.totalSize ? task.totalSize : maxEndSize;
|
330
|
-
// await this.addUploadTask({
|
331
|
-
// filename: task.filename,
|
332
|
-
// path: task.path,
|
333
|
-
// uploadUrl: uploadUrl,
|
334
|
-
// cookies: cookie,
|
335
|
-
// aid: loginEntity?.aid || 0,
|
336
|
-
// folderId: loginEntity?.uploadGroupId || 0,
|
337
|
-
// start,
|
338
|
-
// end: endSize,
|
339
|
-
// total: task.totalSize,
|
340
|
-
// index,
|
341
|
-
// fileMd5: task.fileMd5,
|
342
|
-
// totalChunks: totalChunks,
|
343
|
-
// splitSize,
|
344
|
-
// complete,
|
345
|
-
// topicId: task.topicId,
|
346
|
-
// token: token
|
347
|
-
// });
|
348
|
-
// index = index + 1;
|
349
|
-
// start = endSize;
|
350
|
-
// } while (!complete);
|
351
|
-
// }
|
352
|
-
// }
|
353
|
-
// }
|
354
|
-
// }
|
355
|
-
// }
|
356
|
-
// }
|
357
|
-
// download(task: DownloadTask) {
|
358
|
-
// return new Observable<DownloadTask>((sub) => {
|
359
|
-
// // go on
|
360
|
-
// task.size = 0;
|
361
|
-
// let length = task.size;
|
362
|
-
// const writeStream = createWriteStream(task.path, { start: task.size });
|
363
|
-
// const req = get(task.url, {
|
364
|
-
// headers: {
|
365
|
-
// 'Content-Type': 'application/octet-stream'
|
366
|
-
// }
|
367
|
-
// });
|
368
|
-
// req.on('data', (buf) => {
|
369
|
-
// length = length + buf.length;
|
370
|
-
// task.size = length;
|
371
|
-
// writeStream.write(buf, (err: Error | undefined | null) => {
|
372
|
-
// if (err) sub.error(err)
|
373
|
-
// });
|
374
|
-
// sub.next(task);
|
375
|
-
// });
|
376
|
-
// req.on('end', () => {
|
377
|
-
// sub.complete();
|
378
|
-
// writeStream.end();
|
379
|
-
// });
|
380
|
-
// req.on('response', (resp: Response) => {
|
381
|
-
// const headers = resp.headers;
|
382
|
-
// task.totalSize = Number(Reflect.get(headers, 'content-length'))
|
383
|
-
// sub.next(task);
|
384
|
-
// })
|
385
|
-
// })
|
386
|
-
// }
|
387
|
-
// }
|
388
|
-
// function decode(base64Str: string): string | void {
|
389
|
-
// if (!base64Str) return;
|
390
|
-
// const t = base64Str.replace(/_/g, "/").replace(/-/g, "+")
|
391
|
-
// const f = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
392
|
-
// let l = 0;
|
393
|
-
// let p = 0;
|
394
|
-
// let h: string[] = [];
|
395
|
-
// do {
|
396
|
-
// const o = f.indexOf(t.charAt(l++))
|
397
|
-
// const u = f.indexOf(t.charAt(l++))
|
398
|
-
// const a = f.indexOf(t.charAt(l++))
|
399
|
-
// const c = f.indexOf(t.charAt(l++))
|
400
|
-
// const s = o << 18 | u << 12 | a << 6 | c;
|
401
|
-
// const e = s >> 16 & 255
|
402
|
-
// const r = s >> 8 & 255;
|
403
|
-
// const n = 255 & s;
|
404
|
-
// h[p++] = 64 === a ? String.fromCharCode(e) : 64 === c ? String.fromCharCode(e, r) : String.fromCharCode(e, r, n);
|
405
|
-
// } while (l < t.length)
|
406
|
-
// return h.join('')
|
407
|
-
// }
|