@nger/fk-upload 1.0.4 → 1.0.7
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/core.d.ts +1 -0
- package/dist/entities/fk-download-task.entity.d.ts +12 -0
- package/dist/entities/fk-download-task.entity.js +83 -0
- package/dist/entities/fk-login-account.entity.d.ts +5 -0
- package/dist/entities/fk-login-account.entity.js +38 -0
- package/dist/entities/fk-login-cookie.entity.d.ts +7 -0
- package/dist/entities/fk-login-cookie.entity.js +54 -0
- package/dist/entities/fk-login.entity.d.ts +12 -0
- package/dist/entities/fk-login.entity.js +88 -0
- package/dist/entities/index.d.ts +3 -0
- package/dist/entities/index.js +19 -0
- package/dist/fk-upload.controller.d.ts +28 -0
- package/dist/fk-upload.controller.js +271 -0
- package/dist/fk-upload.module.d.ts +2 -0
- package/dist/fk-upload.module.js +66 -0
- package/dist/fk-v2.service.d.ts +29 -0
- package/dist/fk-v2.service.js +153 -0
- package/dist/fk.service.d.ts +18 -0
- package/dist/fk.service.js +89 -0
- package/dist/login.controller.d.ts +14 -0
- package/dist/login.controller.js +211 -0
- package/dist/main.d.ts +3 -0
- package/dist/main.js +36 -0
- package/dist/templates/account-manage.d.ts +3 -0
- package/dist/templates/account-manage.js +27 -0
- package/dist/templates/add-account.d.ts +0 -0
- package/dist/templates/add-account.js +1 -0
- package/dist/templates/add-fk-login.d.ts +10 -0
- package/dist/templates/add-fk-login.js +96 -0
- package/dist/templates/add-task.d.ts +10 -0
- package/dist/templates/add-task.js +76 -0
- package/dist/templates/code.d.ts +3 -0
- package/dist/templates/code.js +51 -0
- package/dist/templates/component.d.ts +9 -0
- package/dist/templates/component.js +34 -0
- package/dist/templates/download-task.d.ts +12 -0
- package/dist/templates/download-task.js +103 -0
- package/dist/templates/error.d.ts +3 -0
- package/dist/templates/error.js +41 -0
- package/dist/templates/help.d.ts +6 -0
- package/dist/templates/help.js +67 -0
- package/dist/templates/login.service.d.ts +2 -0
- package/dist/templates/login.service.js +16 -0
- package/dist/templates/relogin.d.ts +5 -0
- package/dist/templates/relogin.js +25 -0
- package/dist/templates/task-manage.d.ts +6 -0
- package/dist/templates/task-manage.js +76 -0
- package/dist/templates/upload-task.d.ts +9 -0
- package/dist/templates/upload-task.js +155 -0
- package/dist/templates/upload.d.ts +15 -0
- package/dist/templates/upload.js +248 -0
- package/dist/templates/upload.service.d.ts +18 -0
- package/dist/templates/upload.service.js +293 -0
- package/dist/templates/verify.d.ts +15 -0
- package/dist/templates/verify.js +75 -0
- package/dist/tests/test.d.ts +3 -0
- package/dist/tests/test.js +101 -0
- package/dist/urlSafeBase64Decode.d.ts +3 -0
- package/dist/urlSafeBase64Decode.js +37 -0
- package/package.json +6 -5
- package/pnpm-lock.yaml +1172 -0
- package/tsconfig.json +12 -0
@@ -0,0 +1,76 @@
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
13
|
+
};
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
15
|
+
exports.TaskManageController = 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 react_1 = __importDefault(require("react"));
|
20
|
+
const entities_1 = require("../entities");
|
21
|
+
const component_1 = require("./component");
|
22
|
+
function getStatusTitle(status) {
|
23
|
+
switch (status) {
|
24
|
+
case 0:
|
25
|
+
return 'downling';
|
26
|
+
case 1:
|
27
|
+
return 'uploading';
|
28
|
+
default:
|
29
|
+
return 'finish';
|
30
|
+
}
|
31
|
+
}
|
32
|
+
let TaskManageController = class TaskManageController {
|
33
|
+
db;
|
34
|
+
constructor(db) {
|
35
|
+
this.db = db;
|
36
|
+
}
|
37
|
+
async taskManage() {
|
38
|
+
const tasks = await this.db.manager.find(entities_1.FkDownloadTaskEntity, { where: {}, order: { loginId: "DESC" } });
|
39
|
+
return react_1.default.createElement(component_1.Nav, { active: 2 },
|
40
|
+
react_1.default.createElement("div", { className: "card" },
|
41
|
+
react_1.default.createElement("div", { className: "card-body" },
|
42
|
+
react_1.default.createElement("table", { className: 'table' },
|
43
|
+
react_1.default.createElement("thead", null,
|
44
|
+
react_1.default.createElement("tr", null,
|
45
|
+
react_1.default.createElement("td", { width: '180px' }, "filename"),
|
46
|
+
react_1.default.createElement("td", null, "status"),
|
47
|
+
react_1.default.createElement("td", null, "total size"),
|
48
|
+
react_1.default.createElement("td", null, "download size"),
|
49
|
+
react_1.default.createElement("td", null, "upload size"),
|
50
|
+
react_1.default.createElement("td", { width: '240px' }, "upload url"),
|
51
|
+
react_1.default.createElement("td", null))),
|
52
|
+
react_1.default.createElement("tbody", null, tasks.map((task, key) => {
|
53
|
+
return react_1.default.createElement("tr", { key: key },
|
54
|
+
react_1.default.createElement("td", null, task.filename),
|
55
|
+
react_1.default.createElement("td", null, getStatusTitle(task.status)),
|
56
|
+
react_1.default.createElement("td", null, task.totalSize),
|
57
|
+
react_1.default.createElement("td", null, task.size),
|
58
|
+
react_1.default.createElement("td", null, task.uploadSize),
|
59
|
+
react_1.default.createElement("td", null, task.uploadUrl),
|
60
|
+
react_1.default.createElement("td", null,
|
61
|
+
react_1.default.createElement("a", { href: "", className: 'btn' }, "download"),
|
62
|
+
react_1.default.createElement("a", { href: "", className: 'btn' }, "upload")));
|
63
|
+
}))))));
|
64
|
+
}
|
65
|
+
};
|
66
|
+
__decorate([
|
67
|
+
(0, http_1.Get)('task-manage'),
|
68
|
+
__metadata("design:type", Function),
|
69
|
+
__metadata("design:paramtypes", []),
|
70
|
+
__metadata("design:returntype", Promise)
|
71
|
+
], TaskManageController.prototype, "taskManage", null);
|
72
|
+
TaskManageController = __decorate([
|
73
|
+
(0, core_1.Controller)(`@nger/fk-upload`),
|
74
|
+
__metadata("design:paramtypes", [typeorm_1.Db])
|
75
|
+
], TaskManageController);
|
76
|
+
exports.TaskManageController = TaskManageController;
|
@@ -0,0 +1,155 @@
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
15
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
16
|
+
};
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
18
|
+
exports.UploadTaskController = void 0;
|
19
|
+
const core_1 = require("@nger/core");
|
20
|
+
const http_1 = require("@nger/http");
|
21
|
+
const typeorm_1 = require("@nger/typeorm");
|
22
|
+
const entities_1 = require("../entities");
|
23
|
+
const form_data_1 = __importDefault(require("form-data"));
|
24
|
+
const axios_1 = __importDefault(require("axios"));
|
25
|
+
const fs_1 = require("fs");
|
26
|
+
const path_1 = require("path");
|
27
|
+
let UploadTaskController = class UploadTaskController {
|
28
|
+
db;
|
29
|
+
getUploadUrl(token, forceDirect = true) {
|
30
|
+
if (forceDirect) {
|
31
|
+
return `https://${token.url}/${token.visitType}/${token.app}/upload?cmd=${token.cmd}&token=${token.token}`;
|
32
|
+
}
|
33
|
+
else {
|
34
|
+
return `https://${token.url}/${token.visitType}/${token.app}/advance?cmd=${token.cmd}&token=${token.token}`;
|
35
|
+
}
|
36
|
+
}
|
37
|
+
constructor(db) {
|
38
|
+
this.db = db;
|
39
|
+
}
|
40
|
+
async uploadTask(filename) {
|
41
|
+
const task = await this.db.manager.findOne(entities_1.FkDownloadTaskEntity, { where: { filename } });
|
42
|
+
if (task) {
|
43
|
+
if (task.status === 0) {
|
44
|
+
return {
|
45
|
+
msg: 'downloading'
|
46
|
+
};
|
47
|
+
}
|
48
|
+
if (task.status === 2) {
|
49
|
+
return {
|
50
|
+
msg: 'uploaded'
|
51
|
+
};
|
52
|
+
}
|
53
|
+
const loginEntity = await this.db.manager.findOne(entities_1.FkLoginEntity, { where: { fkLoginId: task.loginId } });
|
54
|
+
const cookies = await this.db.manager.find(entities_1.FkLoginCookieEntity, { where: { fkLoginId: task.loginId } });
|
55
|
+
const cookie = cookies.map(cookie => `${cookie.key}=${cookie.value}`).join(';');
|
56
|
+
// 00 take token
|
57
|
+
const url = `https://i.vip.webportal.top/`;
|
58
|
+
const iVipWebPortal = await axios_1.default.get(url, {
|
59
|
+
headers: {
|
60
|
+
Cookie: cookie
|
61
|
+
}
|
62
|
+
}).then(res => res.data);
|
63
|
+
const items = iVipWebPortal.match(/<meta id='_TOKEN' value='(.*?)'\/>/);
|
64
|
+
let token = ``;
|
65
|
+
if (items && items.length === 2) {
|
66
|
+
token = items[1];
|
67
|
+
}
|
68
|
+
if (token.length > 0) {
|
69
|
+
// 01
|
70
|
+
const url = `https://smr00.vip.webportal.top/cn/api/manage/advanceUpload/genAccessKey?_v=1651232099799&_TOKEN=${token}`;
|
71
|
+
const accessKey = await axios_1.default.get(url).then(res => res.data);
|
72
|
+
if (accessKey.success) {
|
73
|
+
const accessTokenString = decode(accessKey.accessKey);
|
74
|
+
if (accessTokenString) {
|
75
|
+
const accessToken = JSON.parse(accessTokenString);
|
76
|
+
const ext = (0, path_1.extname)(filename);
|
77
|
+
const uploadUrl = this.getUploadUrl(accessToken, ['jpeg', 'jpg', 'png', 'svg'].includes(ext));
|
78
|
+
const fileStream = (0, fs_1.createReadStream)(task.path, {});
|
79
|
+
let length = 0;
|
80
|
+
let size = 0;
|
81
|
+
let index = 0;
|
82
|
+
fileStream.on('data', (chunk) => {
|
83
|
+
const totalChunks = (task.totalSize - length) / size;
|
84
|
+
length += chunk.length;
|
85
|
+
size = chunk.length;
|
86
|
+
index += 1;
|
87
|
+
const complete = length >= task.totalSize;
|
88
|
+
const data = new form_data_1.default();
|
89
|
+
data.append('ctrl', fileStream);
|
90
|
+
data.append('isFreeVer', 'false');
|
91
|
+
data.append('aid', loginEntity.aid);
|
92
|
+
data.append('folderId', loginEntity.uploadGroupId);
|
93
|
+
data.append('fileName', task.filename);
|
94
|
+
// chunk
|
95
|
+
data.append(`totalSize`, task.totalSize);
|
96
|
+
data.append(`fileMd5`, task.fileMd5);
|
97
|
+
data.append('index', index);
|
98
|
+
data.append('chunkSize', chunk.length);
|
99
|
+
data.append('totalChunks', totalChunks);
|
100
|
+
data.append(`complete`, complete);
|
101
|
+
const bssInfo = {
|
102
|
+
fromSite: true, siteId: 0, groupId: 0, fileSizeLimit: 1024
|
103
|
+
};
|
104
|
+
data.append('bssInfo', JSON.stringify(bssInfo));
|
105
|
+
const headers = data.getHeaders();
|
106
|
+
axios_1.default.post(uploadUrl, data, {
|
107
|
+
headers: {
|
108
|
+
...headers,
|
109
|
+
Cookie: cookie
|
110
|
+
},
|
111
|
+
onUploadProgress: (upload) => {
|
112
|
+
debugger;
|
113
|
+
}
|
114
|
+
}).then(res => res.data);
|
115
|
+
});
|
116
|
+
}
|
117
|
+
}
|
118
|
+
}
|
119
|
+
return { msg: `error` };
|
120
|
+
}
|
121
|
+
}
|
122
|
+
};
|
123
|
+
__decorate([
|
124
|
+
(0, http_1.Get)('upload-task'),
|
125
|
+
__param(0, (0, http_1.Query)('filename')),
|
126
|
+
__metadata("design:type", Function),
|
127
|
+
__metadata("design:paramtypes", [String]),
|
128
|
+
__metadata("design:returntype", Promise)
|
129
|
+
], UploadTaskController.prototype, "uploadTask", null);
|
130
|
+
UploadTaskController = __decorate([
|
131
|
+
(0, core_1.Controller)(`@nger/fk-upload`),
|
132
|
+
__metadata("design:paramtypes", [typeorm_1.Db])
|
133
|
+
], UploadTaskController);
|
134
|
+
exports.UploadTaskController = UploadTaskController;
|
135
|
+
function decode(base64Str) {
|
136
|
+
if (!base64Str)
|
137
|
+
return;
|
138
|
+
const t = base64Str.replace(/_/g, "/").replace(/-/g, "+");
|
139
|
+
const f = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
140
|
+
let l = 0;
|
141
|
+
let p = 0;
|
142
|
+
let h = [];
|
143
|
+
do {
|
144
|
+
const o = f.indexOf(t.charAt(l++));
|
145
|
+
const u = f.indexOf(t.charAt(l++));
|
146
|
+
const a = f.indexOf(t.charAt(l++));
|
147
|
+
const c = f.indexOf(t.charAt(l++));
|
148
|
+
const s = o << 18 | u << 12 | a << 6 | c;
|
149
|
+
const e = s >> 16 & 255;
|
150
|
+
const r = s >> 8 & 255;
|
151
|
+
const n = 255 & s;
|
152
|
+
h[p++] = 64 === a ? String.fromCharCode(e) : 64 === c ? String.fromCharCode(e, r) : String.fromCharCode(e, r, n);
|
153
|
+
} while (l < t.length);
|
154
|
+
return h.join('');
|
155
|
+
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import { Db } from '@nger/typeorm';
|
2
|
+
import { Context } from 'koa';
|
3
|
+
export declare class UploadController {
|
4
|
+
private db;
|
5
|
+
constructor(db: Db);
|
6
|
+
upload(): JSX.Element;
|
7
|
+
postUpload(file: any, loginId: string, ctx: Context): Promise<any>;
|
8
|
+
preview(src: string): JSX.Element;
|
9
|
+
downloadFile(cloudUrl: string): Promise<{
|
10
|
+
path: string;
|
11
|
+
filename: string;
|
12
|
+
}>;
|
13
|
+
uploadCloud(loginId: string, cloudUrl: string, ctx: Context): Promise<any>;
|
14
|
+
getUploadUrl(token: any): string;
|
15
|
+
}
|
@@ -0,0 +1,248 @@
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
15
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
16
|
+
};
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
18
|
+
exports.UploadController = void 0;
|
19
|
+
const core_1 = require("@nger/core");
|
20
|
+
const http_1 = require("@nger/http");
|
21
|
+
const react_1 = __importDefault(require("react"));
|
22
|
+
const form_data_1 = __importDefault(require("form-data"));
|
23
|
+
const axios_1 = __importDefault(require("axios"));
|
24
|
+
const typeorm_1 = require("@nger/typeorm");
|
25
|
+
const entities_1 = require("../entities");
|
26
|
+
const fs_1 = require("fs");
|
27
|
+
const path_1 = require("path");
|
28
|
+
const url_1 = require("url");
|
29
|
+
const fs_extra_1 = require("fs-extra");
|
30
|
+
const request_1 = __importDefault(require("request"));
|
31
|
+
const component_1 = require("./component");
|
32
|
+
let UploadController = class UploadController {
|
33
|
+
db;
|
34
|
+
constructor(db) {
|
35
|
+
this.db = db;
|
36
|
+
}
|
37
|
+
upload() {
|
38
|
+
return react_1.default.createElement(component_1.Nav, { active: -1 },
|
39
|
+
react_1.default.createElement("div", { className: "card" },
|
40
|
+
react_1.default.createElement("div", { className: "card-body" },
|
41
|
+
react_1.default.createElement("form", { action: "", method: "post", encType: 'multipart/form-data' },
|
42
|
+
react_1.default.createElement("div", null,
|
43
|
+
react_1.default.createElement("input", { className: 'form-control', type: "file", name: "file" })),
|
44
|
+
react_1.default.createElement("div", { style: { marginTop: "20px" } },
|
45
|
+
react_1.default.createElement("button", { className: "btn btn-primary", type: "submit" }, "submit"))))));
|
46
|
+
}
|
47
|
+
async postUpload(file, loginId, ctx) {
|
48
|
+
const loginEntity = await this.db.manager.findOne(entities_1.FkLoginEntity, { where: { fkLoginId: Number(loginId) } });
|
49
|
+
const cookies = await this.db.manager.find(entities_1.FkLoginCookieEntity, { where: { fkLoginId: Number(loginId) } });
|
50
|
+
const cookie = cookies.map(cookie => `${cookie.key}=${cookie.value}`).join(';');
|
51
|
+
// 00 take token
|
52
|
+
const url = `https://i.vip.webportal.top/`;
|
53
|
+
const iVipWebPortal = await axios_1.default.get(url, {
|
54
|
+
headers: {
|
55
|
+
Cookie: cookie
|
56
|
+
}
|
57
|
+
}).then(res => res.data);
|
58
|
+
const items = iVipWebPortal.match(/<meta id='_TOKEN' value='(.*?)'\/>/);
|
59
|
+
let token = ``;
|
60
|
+
if (items && items.length === 2) {
|
61
|
+
token = items[1];
|
62
|
+
}
|
63
|
+
if (token.length > 0) {
|
64
|
+
// 01
|
65
|
+
const url = `https://smr00.vip.webportal.top/cn/api/manage/advanceUpload/genAccessKey?_v=1651232099799&_TOKEN=${token}`;
|
66
|
+
const accessKey = await axios_1.default.get(url).then(res => res.data);
|
67
|
+
if (accessKey.success) {
|
68
|
+
const accessTokenString = decode(accessKey.accessKey);
|
69
|
+
if (accessTokenString) {
|
70
|
+
const accessToken = JSON.parse(accessTokenString);
|
71
|
+
const uploadUrl = this.getUploadUrl(accessToken);
|
72
|
+
const data = new form_data_1.default();
|
73
|
+
const fileStream = (0, fs_1.createReadStream)(file.path);
|
74
|
+
data.append('ctrl', fileStream);
|
75
|
+
data.append('isFreeVer', 'false');
|
76
|
+
data.append('aid', loginEntity.aid);
|
77
|
+
data.append('folderId', loginEntity.uploadGroupId);
|
78
|
+
data.append('fileName', file.name);
|
79
|
+
const bssInfo = {
|
80
|
+
fromSite: true, siteId: 0, groupId: 0, fileSizeLimit: 1024
|
81
|
+
};
|
82
|
+
data.append('bssInfo', JSON.stringify(bssInfo));
|
83
|
+
const headers = data.getHeaders();
|
84
|
+
const res = await axios_1.default.post(uploadUrl, data, {
|
85
|
+
headers: {
|
86
|
+
...headers,
|
87
|
+
Cookie: cookie
|
88
|
+
}
|
89
|
+
}).then(res => res.data);
|
90
|
+
if (res.data) {
|
91
|
+
const data = res.data;
|
92
|
+
const src = data.downUrl;
|
93
|
+
ctx.redirect('/@nger/fk-upload/preview?src=https://' + src);
|
94
|
+
return;
|
95
|
+
}
|
96
|
+
if (res.msg) {
|
97
|
+
return res.msg;
|
98
|
+
}
|
99
|
+
}
|
100
|
+
}
|
101
|
+
}
|
102
|
+
return `error`;
|
103
|
+
}
|
104
|
+
preview(src) {
|
105
|
+
return react_1.default.createElement(component_1.Nav, { active: -1 },
|
106
|
+
react_1.default.createElement("div", { className: "card", style: { width: '300px', marginTop: '10px' } },
|
107
|
+
react_1.default.createElement("img", { src: src, style: { height: '300px' }, className: "card-img-top" }),
|
108
|
+
react_1.default.createElement("div", { className: "card-body" },
|
109
|
+
react_1.default.createElement("div", { className: "card-title" },
|
110
|
+
react_1.default.createElement("p", null, src)))));
|
111
|
+
}
|
112
|
+
downloadFile(cloudUrl) {
|
113
|
+
return new Promise((resolve, reject) => {
|
114
|
+
const url = new url_1.URL(cloudUrl);
|
115
|
+
const list = url.pathname.split('/');
|
116
|
+
const filename = list.pop();
|
117
|
+
const req = request_1.default.get(cloudUrl);
|
118
|
+
(0, fs_extra_1.ensureDirSync)((0, path_1.join)(__dirname, 'dist'));
|
119
|
+
const file = (0, path_1.join)(__dirname, 'dist', filename);
|
120
|
+
const writeStream = (0, fs_1.createWriteStream)(file);
|
121
|
+
req.pipe(writeStream);
|
122
|
+
req.on('end', () => {
|
123
|
+
resolve({
|
124
|
+
path: file,
|
125
|
+
filename
|
126
|
+
});
|
127
|
+
});
|
128
|
+
});
|
129
|
+
}
|
130
|
+
async uploadCloud(loginId, cloudUrl, ctx) {
|
131
|
+
const loginEntity = await this.db.manager.findOne(entities_1.FkLoginEntity, { where: { fkLoginId: Number(loginId) } });
|
132
|
+
const cookies = await this.db.manager.find(entities_1.FkLoginCookieEntity, { where: { fkLoginId: Number(loginId) } });
|
133
|
+
const cookie = cookies.map(cookie => `${cookie.key}=${cookie.value}`).join(';');
|
134
|
+
// 00 take token
|
135
|
+
const url = `https://i.vip.webportal.top/`;
|
136
|
+
const iVipWebPortal = await axios_1.default.get(url, {
|
137
|
+
headers: {
|
138
|
+
Cookie: cookie
|
139
|
+
}
|
140
|
+
}).then(res => res.data);
|
141
|
+
const items = iVipWebPortal.match(/<meta id='_TOKEN' value='(.*?)'\/>/);
|
142
|
+
let token = ``;
|
143
|
+
if (items && items.length === 2) {
|
144
|
+
token = items[1];
|
145
|
+
}
|
146
|
+
if (token.length > 0) {
|
147
|
+
// 01
|
148
|
+
const url = `https://smr00.vip.webportal.top/cn/api/manage/advanceUpload/genAccessKey?_v=1651232099799&_TOKEN=${token}`;
|
149
|
+
const accessKey = await axios_1.default.get(url).then(res => res.data);
|
150
|
+
if (accessKey.success) {
|
151
|
+
const accessTokenString = decode(accessKey.accessKey);
|
152
|
+
if (accessTokenString) {
|
153
|
+
const accessToken = JSON.parse(accessTokenString);
|
154
|
+
const uploadUrl = this.getUploadUrl(accessToken);
|
155
|
+
const data = new form_data_1.default();
|
156
|
+
const file = await this.downloadFile(cloudUrl);
|
157
|
+
const fileStream = (0, fs_1.createReadStream)(file.path);
|
158
|
+
data.append('ctrl', fileStream);
|
159
|
+
data.append('isFreeVer', 'false');
|
160
|
+
data.append('aid', loginEntity.aid);
|
161
|
+
data.append('folderId', loginEntity.uploadGroupId);
|
162
|
+
data.append('fileName', file.filename);
|
163
|
+
const bssInfo = {
|
164
|
+
fromSite: true, siteId: 0, groupId: 0, fileSizeLimit: 1024
|
165
|
+
};
|
166
|
+
data.append('bssInfo', JSON.stringify(bssInfo));
|
167
|
+
const headers = data.getHeaders();
|
168
|
+
const res = await axios_1.default.post(uploadUrl, data, {
|
169
|
+
headers: {
|
170
|
+
...headers,
|
171
|
+
Cookie: cookie
|
172
|
+
}
|
173
|
+
}).then(res => res.data);
|
174
|
+
if (res.data) {
|
175
|
+
const data = res.data;
|
176
|
+
const src = data.downUrl;
|
177
|
+
ctx.redirect('/@nger/fk-upload/preview?src=https://' + src);
|
178
|
+
return;
|
179
|
+
}
|
180
|
+
if (res.msg) {
|
181
|
+
return res.msg;
|
182
|
+
}
|
183
|
+
}
|
184
|
+
}
|
185
|
+
}
|
186
|
+
return `error`;
|
187
|
+
}
|
188
|
+
getUploadUrl(token) {
|
189
|
+
return `https://${token.url}/${token.visitType}/${token.app}/upload?cmd=${token.cmd}&token=${token.token}`;
|
190
|
+
}
|
191
|
+
};
|
192
|
+
__decorate([
|
193
|
+
(0, http_1.Get)('upload'),
|
194
|
+
__metadata("design:type", Function),
|
195
|
+
__metadata("design:paramtypes", []),
|
196
|
+
__metadata("design:returntype", void 0)
|
197
|
+
], UploadController.prototype, "upload", null);
|
198
|
+
__decorate([
|
199
|
+
(0, http_1.Post)('upload'),
|
200
|
+
__param(0, (0, http_1.File)('file')),
|
201
|
+
__param(1, (0, http_1.Query)('loginId')),
|
202
|
+
__param(2, (0, core_1.Inject)(http_1.CONTEXT)),
|
203
|
+
__metadata("design:type", Function),
|
204
|
+
__metadata("design:paramtypes", [Object, String, Object]),
|
205
|
+
__metadata("design:returntype", Promise)
|
206
|
+
], UploadController.prototype, "postUpload", null);
|
207
|
+
__decorate([
|
208
|
+
(0, http_1.Get)('preview'),
|
209
|
+
__param(0, (0, http_1.Query)(`src`)),
|
210
|
+
__metadata("design:type", Function),
|
211
|
+
__metadata("design:paramtypes", [String]),
|
212
|
+
__metadata("design:returntype", void 0)
|
213
|
+
], UploadController.prototype, "preview", null);
|
214
|
+
__decorate([
|
215
|
+
(0, http_1.Get)('upload_cloud'),
|
216
|
+
__param(0, (0, http_1.Query)('loginId')),
|
217
|
+
__param(1, (0, http_1.Query)('cloudUrl')),
|
218
|
+
__param(2, (0, core_1.Inject)(http_1.CONTEXT)),
|
219
|
+
__metadata("design:type", Function),
|
220
|
+
__metadata("design:paramtypes", [String, String, Object]),
|
221
|
+
__metadata("design:returntype", Promise)
|
222
|
+
], UploadController.prototype, "uploadCloud", null);
|
223
|
+
UploadController = __decorate([
|
224
|
+
(0, core_1.Controller)('@nger/fk-upload'),
|
225
|
+
__metadata("design:paramtypes", [typeorm_1.Db])
|
226
|
+
], UploadController);
|
227
|
+
exports.UploadController = UploadController;
|
228
|
+
function decode(base64Str) {
|
229
|
+
if (!base64Str)
|
230
|
+
return;
|
231
|
+
const t = base64Str.replace(/_/g, "/").replace(/-/g, "+");
|
232
|
+
const f = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
233
|
+
let l = 0;
|
234
|
+
let p = 0;
|
235
|
+
let h = [];
|
236
|
+
do {
|
237
|
+
const o = f.indexOf(t.charAt(l++));
|
238
|
+
const u = f.indexOf(t.charAt(l++));
|
239
|
+
const a = f.indexOf(t.charAt(l++));
|
240
|
+
const c = f.indexOf(t.charAt(l++));
|
241
|
+
const s = o << 18 | u << 12 | a << 6 | c;
|
242
|
+
const e = s >> 16 & 255;
|
243
|
+
const r = s >> 8 & 255;
|
244
|
+
const n = 255 & s;
|
245
|
+
h[p++] = 64 === a ? String.fromCharCode(e) : 64 === c ? String.fromCharCode(e, r) : String.fromCharCode(e, r, n);
|
246
|
+
} while (l < t.length);
|
247
|
+
return h.join('');
|
248
|
+
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import { FkDownloadTaskEntity } from '../entities';
|
2
|
+
import { Db } from '@nger/typeorm';
|
3
|
+
import { Observable } from 'rxjs';
|
4
|
+
export declare class UploadService {
|
5
|
+
private db;
|
6
|
+
constructor(db: Db);
|
7
|
+
createDownLoadTask(url: string, fkLoginId: number): Promise<import("rxjs").Subscription>;
|
8
|
+
getUploadUrl(token: any, forceDirect?: boolean): string;
|
9
|
+
getUploadInfourl(token: any): string;
|
10
|
+
encodeURIComponent(data: any): string;
|
11
|
+
createUplaodTask(filename: string): Promise<{
|
12
|
+
msg: string;
|
13
|
+
} | undefined>;
|
14
|
+
createObservable(url: string): Promise<{
|
15
|
+
listen: Observable<FkDownloadTaskEntity>;
|
16
|
+
filename: string;
|
17
|
+
}>;
|
18
|
+
}
|