@nger/fk-upload 1.0.6 → 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/entities/fk-download-task.entity.js +5 -2
- package/dist/fk-upload.module.js +11 -3
- package/dist/main.js +3 -1
- package/dist/templates/add-fk-login.d.ts +5 -1
- package/dist/templates/add-fk-login.js +35 -7
- package/dist/templates/add-task.d.ts +10 -0
- package/dist/templates/add-task.js +76 -0
- package/dist/templates/download-task.d.ts +5 -3
- package/dist/templates/download-task.js +12 -92
- package/dist/templates/error.d.ts +3 -0
- package/dist/templates/error.js +41 -0
- package/dist/templates/help.d.ts +0 -1
- package/dist/templates/help.js +0 -21
- package/dist/templates/task-manage.js +2 -4
- package/dist/templates/upload-task.d.ts +0 -1
- package/dist/templates/upload-task.js +0 -2
- package/dist/templates/upload.js +6 -3
- package/dist/templates/upload.service.d.ts +18 -0
- package/dist/templates/upload.service.js +293 -0
- package/package.json +6 -1
- package/pnpm-lock.yaml +119 -0
@@ -40,7 +40,9 @@ __decorate([
|
|
40
40
|
__metadata("design:type", Number)
|
41
41
|
], FkDownloadTaskEntity.prototype, "size", void 0);
|
42
42
|
__decorate([
|
43
|
-
(0, typeorm_1.Column)(
|
43
|
+
(0, typeorm_1.Column)({
|
44
|
+
length: 320
|
45
|
+
}),
|
44
46
|
__metadata("design:type", String)
|
45
47
|
], FkDownloadTaskEntity.prototype, "url", void 0);
|
46
48
|
__decorate([
|
@@ -55,7 +57,8 @@ __decorate([
|
|
55
57
|
], FkDownloadTaskEntity.prototype, "uploadSize", void 0);
|
56
58
|
__decorate([
|
57
59
|
(0, typeorm_1.Column)({
|
58
|
-
default: ''
|
60
|
+
default: '',
|
61
|
+
length: 320
|
59
62
|
}),
|
60
63
|
__metadata("design:type", String)
|
61
64
|
], FkDownloadTaskEntity.prototype, "uploadUrl", void 0);
|
package/dist/fk-upload.module.js
CHANGED
@@ -9,6 +9,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.FkUploadModule = void 0;
|
10
10
|
const core_1 = require("@nger/core");
|
11
11
|
const typeorm_1 = require("@nger/typeorm");
|
12
|
+
const utils_1 = require("@nger/utils");
|
12
13
|
const entities_1 = require("./entities");
|
13
14
|
const fk_login_account_entity_1 = require("./entities/fk-login-account.entity");
|
14
15
|
const fk_upload_controller_1 = require("./fk-upload.controller");
|
@@ -16,12 +17,15 @@ const fk_v2_service_1 = require("./fk-v2.service");
|
|
16
17
|
const fk_service_1 = require("./fk.service");
|
17
18
|
const login_controller_1 = require("./login.controller");
|
18
19
|
const add_fk_login_1 = require("./templates/add-fk-login");
|
20
|
+
const add_task_1 = require("./templates/add-task");
|
19
21
|
const code_1 = require("./templates/code");
|
20
22
|
const download_task_1 = require("./templates/download-task");
|
23
|
+
const error_1 = require("./templates/error");
|
21
24
|
const help_1 = require("./templates/help");
|
22
25
|
const task_manage_1 = require("./templates/task-manage");
|
23
26
|
const upload_1 = require("./templates/upload");
|
24
27
|
const upload_task_1 = require("./templates/upload-task");
|
28
|
+
const upload_service_1 = require("./templates/upload.service");
|
25
29
|
const verify_1 = require("./templates/verify");
|
26
30
|
const urlSafeBase64Decode_1 = require("./urlSafeBase64Decode");
|
27
31
|
let FkUploadModule = class FkUploadModule {
|
@@ -31,7 +35,8 @@ FkUploadModule = __decorate([
|
|
31
35
|
providers: [
|
32
36
|
fk_service_1.FkService,
|
33
37
|
urlSafeBase64Decode_1.UrlSafeBase64,
|
34
|
-
fk_v2_service_1.FkV2Service
|
38
|
+
fk_v2_service_1.FkV2Service,
|
39
|
+
upload_service_1.UploadService
|
35
40
|
],
|
36
41
|
controllers: [
|
37
42
|
fk_upload_controller_1.FkAjaxController,
|
@@ -43,7 +48,9 @@ FkUploadModule = __decorate([
|
|
43
48
|
download_task_1.DownloadTaskController,
|
44
49
|
upload_task_1.UploadTaskController,
|
45
50
|
add_fk_login_1.AddFkLoginController,
|
46
|
-
task_manage_1.TaskManageController
|
51
|
+
task_manage_1.TaskManageController,
|
52
|
+
add_task_1.AddTaskController,
|
53
|
+
error_1.ErrorController
|
47
54
|
],
|
48
55
|
imports: [
|
49
56
|
typeorm_1.TypeormModule.forFeature([
|
@@ -51,7 +58,8 @@ FkUploadModule = __decorate([
|
|
51
58
|
entities_1.FkLoginCookieEntity,
|
52
59
|
entities_1.FkDownloadTaskEntity,
|
53
60
|
fk_login_account_entity_1.FkLoginAccountEntity
|
54
|
-
])
|
61
|
+
]),
|
62
|
+
utils_1.UtilsModule
|
55
63
|
]
|
56
64
|
})
|
57
65
|
], FkUploadModule);
|
package/dist/main.js
CHANGED
@@ -14,6 +14,7 @@ const core_2 = require("@nger/core");
|
|
14
14
|
const fk_upload_module_1 = require("./fk-upload.module");
|
15
15
|
const http_1 = require("@nger/http");
|
16
16
|
const typeorm_1 = require("@nger/typeorm");
|
17
|
+
const api_1 = require("@nger/api");
|
17
18
|
let AppModule = class AppModule {
|
18
19
|
};
|
19
20
|
AppModule = __decorate([
|
@@ -25,7 +26,8 @@ AppModule = __decorate([
|
|
25
26
|
imports: [
|
26
27
|
fk_upload_module_1.FkUploadModule,
|
27
28
|
http_1.HttpModule.forEnv(),
|
28
|
-
typeorm_1.TypeormModule.forEnv()
|
29
|
+
typeorm_1.TypeormModule.forEnv(),
|
30
|
+
api_1.ApiModule
|
29
31
|
],
|
30
32
|
controllers: []
|
31
33
|
})
|
@@ -1,6 +1,10 @@
|
|
1
1
|
import { Db } from '@nger/typeorm';
|
2
|
+
import { Context } from 'koa';
|
3
|
+
import { CryptoService } from '@nger/utils';
|
2
4
|
export declare class AddFkLoginController {
|
3
5
|
private db;
|
4
|
-
|
6
|
+
private crypto;
|
7
|
+
constructor(db: Db, crypto: CryptoService);
|
8
|
+
postAddFkLogin(fkLoginId: string, post: any, ctx: Context): Promise<void>;
|
5
9
|
addFkLogin(fkLoginId: string): Promise<JSX.Element>;
|
6
10
|
}
|
@@ -22,14 +22,33 @@ const typeorm_1 = require("@nger/typeorm");
|
|
22
22
|
const react_1 = __importDefault(require("react"));
|
23
23
|
const entities_1 = require("../entities");
|
24
24
|
const component_1 = require("./component");
|
25
|
+
const utils_1 = require("@nger/utils");
|
25
26
|
let AddFkLoginController = class AddFkLoginController {
|
26
27
|
db;
|
27
|
-
|
28
|
+
crypto;
|
29
|
+
constructor(db, crypto) {
|
28
30
|
this.db = db;
|
31
|
+
this.crypto = crypto;
|
29
32
|
}
|
30
|
-
async
|
33
|
+
async postAddFkLogin(fkLoginId, post, ctx) {
|
31
34
|
let fkLogin = new entities_1.FkLoginEntity();
|
35
|
+
fkLogin.username = post.username;
|
36
|
+
fkLogin.pass = post.pass;
|
37
|
+
fkLogin.w7Username = post.w7Username;
|
38
|
+
fkLogin.password = this.crypto.md5(post.pass);
|
32
39
|
if (fkLoginId) {
|
40
|
+
// edit
|
41
|
+
await this.db.manager.update(entities_1.FkLoginEntity, Number(fkLoginId), fkLogin);
|
42
|
+
}
|
43
|
+
else {
|
44
|
+
await this.db.manager.save(entities_1.FkLoginEntity, fkLogin);
|
45
|
+
}
|
46
|
+
ctx.redirect('/@nger/fk-upload/help');
|
47
|
+
return;
|
48
|
+
}
|
49
|
+
async addFkLogin(fkLoginId) {
|
50
|
+
let fkLogin = new entities_1.FkLoginEntity();
|
51
|
+
if (fkLoginId && Number(fkLoginId) > 0) {
|
33
52
|
const item = await this.db.manager.findOne(entities_1.FkLoginEntity, { where: { fkLoginId: Number(fkLoginId) } });
|
34
53
|
if (item)
|
35
54
|
fkLogin = item;
|
@@ -38,22 +57,31 @@ let AddFkLoginController = class AddFkLoginController {
|
|
38
57
|
react_1.default.createElement("link", { href: "https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/css/bootstrap.min.css", rel: "stylesheet" }),
|
39
58
|
react_1.default.createElement("div", { className: "card" },
|
40
59
|
react_1.default.createElement("div", { className: "card-body" },
|
41
|
-
react_1.default.createElement("form",
|
60
|
+
react_1.default.createElement("form", { action: '', method: 'post', encType: 'application/x-www-form-urlencoded' },
|
42
61
|
react_1.default.createElement("div", { className: "form-group" },
|
43
62
|
react_1.default.createElement("label", { htmlFor: "username" }, "username"),
|
44
|
-
react_1.default.createElement("input", { id: "username", onChange: e => { }, className: "form-control", type: "text", value: fkLogin.username })),
|
63
|
+
react_1.default.createElement("input", { id: "username", name: "username", onChange: e => { }, className: "form-control", type: "text", value: fkLogin.username })),
|
45
64
|
react_1.default.createElement("div", { className: "form-group" },
|
46
65
|
react_1.default.createElement("label", { htmlFor: "password" }, "password"),
|
47
|
-
react_1.default.createElement("input", { id: "password", onChange: e => { }, className: "form-control", type: "text", value: fkLogin.pass })),
|
66
|
+
react_1.default.createElement("input", { id: "password", name: "pass", onChange: e => { }, className: "form-control", type: "text", value: fkLogin.pass })),
|
48
67
|
react_1.default.createElement("div", { className: "form-group" },
|
49
68
|
react_1.default.createElement("label", { htmlFor: "w7Username" }, "w7Username"),
|
50
|
-
react_1.default.createElement("input", { id: "w7Username", onChange: e => { }, className: "form-control", type: "text", value: fkLogin.w7Username })),
|
69
|
+
react_1.default.createElement("input", { id: "w7Username", name: "w7Username", onChange: e => { }, className: "form-control", type: "text", value: fkLogin.w7Username })),
|
51
70
|
react_1.default.createElement("div", { className: "for-group" },
|
52
71
|
react_1.default.createElement("button", { type: "submit", className: 'btn btn-primary' }, "add"),
|
53
72
|
react_1.default.createElement("button", { type: "reset", className: 'btn' }, "reset"),
|
54
73
|
react_1.default.createElement("a", { className: "btn btn-link", href: "/@nger/fk-upload/help" }, "list"))))));
|
55
74
|
}
|
56
75
|
};
|
76
|
+
__decorate([
|
77
|
+
(0, http_1.Post)('add-fk-login'),
|
78
|
+
__param(0, (0, http_1.Query)('loginId')),
|
79
|
+
__param(1, (0, http_1.Body)()),
|
80
|
+
__param(2, (0, core_1.Inject)(http_1.CONTEXT)),
|
81
|
+
__metadata("design:type", Function),
|
82
|
+
__metadata("design:paramtypes", [String, Object, Object]),
|
83
|
+
__metadata("design:returntype", Promise)
|
84
|
+
], AddFkLoginController.prototype, "postAddFkLogin", null);
|
57
85
|
__decorate([
|
58
86
|
(0, http_1.Get)(`add-fk-login`),
|
59
87
|
__param(0, (0, http_1.Query)(`loginId`)),
|
@@ -63,6 +91,6 @@ __decorate([
|
|
63
91
|
], AddFkLoginController.prototype, "addFkLogin", null);
|
64
92
|
AddFkLoginController = __decorate([
|
65
93
|
(0, core_1.Controller)('@nger/fk-upload'),
|
66
|
-
__metadata("design:paramtypes", [typeorm_1.Db])
|
94
|
+
__metadata("design:paramtypes", [typeorm_1.Db, utils_1.CryptoService])
|
67
95
|
], AddFkLoginController);
|
68
96
|
exports.AddFkLoginController = AddFkLoginController;
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import { Db } from '@nger/typeorm';
|
2
|
+
import { UploadService } from './upload.service';
|
3
|
+
import { Context } from 'koa';
|
4
|
+
export declare class AddTaskController {
|
5
|
+
private db;
|
6
|
+
private upload;
|
7
|
+
constructor(db: Db, upload: UploadService);
|
8
|
+
postAddTask(post: any, ctx: Context): Promise<void>;
|
9
|
+
addTask(): JSX.Element;
|
10
|
+
}
|
@@ -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 __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.AddTaskController = void 0;
|
19
|
+
const core_1 = require("@nger/core");
|
20
|
+
const http_1 = require("@nger/http");
|
21
|
+
const component_1 = require("./component");
|
22
|
+
const react_1 = __importDefault(require("react"));
|
23
|
+
const typeorm_1 = require("@nger/typeorm");
|
24
|
+
const entities_1 = require("../entities");
|
25
|
+
const upload_service_1 = require("./upload.service");
|
26
|
+
let AddTaskController = class AddTaskController {
|
27
|
+
db;
|
28
|
+
upload;
|
29
|
+
constructor(db, upload) {
|
30
|
+
this.db = db;
|
31
|
+
this.upload = upload;
|
32
|
+
}
|
33
|
+
async postAddTask(post, ctx) {
|
34
|
+
const { url, we7Username } = post;
|
35
|
+
const loginEntity = await this.db.manager.findOne(entities_1.FkLoginEntity, { where: { w7Username: we7Username } });
|
36
|
+
if (loginEntity) {
|
37
|
+
await this.upload.createDownLoadTask(url, loginEntity.fkLoginId);
|
38
|
+
}
|
39
|
+
ctx.redirect('/@nger/fk-upload/task-manage');
|
40
|
+
return;
|
41
|
+
}
|
42
|
+
addTask() {
|
43
|
+
return react_1.default.createElement(component_1.Nav, { active: 3 },
|
44
|
+
react_1.default.createElement("div", { className: "card" },
|
45
|
+
react_1.default.createElement("div", { className: "card-body" },
|
46
|
+
react_1.default.createElement("form", { action: "/@nger/fk-upload/add-task", method: "post" },
|
47
|
+
react_1.default.createElement("div", { className: "form-group" },
|
48
|
+
react_1.default.createElement("label", { htmlFor: "url" }, "url"),
|
49
|
+
react_1.default.createElement("input", { type: "text", name: "url", className: 'form-control', id: "url" })),
|
50
|
+
react_1.default.createElement("div", { className: "form-group" },
|
51
|
+
react_1.default.createElement("label", { htmlFor: "w7Username" }, "w7 account"),
|
52
|
+
react_1.default.createElement("input", { type: "text", name: "we7Username", className: 'form-control', id: "w7Username" })),
|
53
|
+
react_1.default.createElement("div", { className: "form-group" },
|
54
|
+
react_1.default.createElement("button", { type: "submit", className: "btn btn-primary" }, "submit"),
|
55
|
+
react_1.default.createElement("button", { type: "reset", className: "btn" }, "reset"))))));
|
56
|
+
}
|
57
|
+
};
|
58
|
+
__decorate([
|
59
|
+
(0, http_1.Post)('add-task'),
|
60
|
+
__param(0, (0, http_1.Body)()),
|
61
|
+
__param(1, (0, core_1.Inject)(http_1.CONTEXT)),
|
62
|
+
__metadata("design:type", Function),
|
63
|
+
__metadata("design:paramtypes", [Object, Object]),
|
64
|
+
__metadata("design:returntype", Promise)
|
65
|
+
], AddTaskController.prototype, "postAddTask", null);
|
66
|
+
__decorate([
|
67
|
+
(0, http_1.Get)('add-task'),
|
68
|
+
__metadata("design:type", Function),
|
69
|
+
__metadata("design:paramtypes", []),
|
70
|
+
__metadata("design:returntype", void 0)
|
71
|
+
], AddTaskController.prototype, "addTask", null);
|
72
|
+
AddTaskController = __decorate([
|
73
|
+
(0, core_1.Controller)('@nger/fk-upload'),
|
74
|
+
__metadata("design:paramtypes", [typeorm_1.Db, upload_service_1.UploadService])
|
75
|
+
], AddTaskController);
|
76
|
+
exports.AddTaskController = AddTaskController;
|
@@ -1,10 +1,12 @@
|
|
1
1
|
import { Db } from '@nger/typeorm';
|
2
2
|
import { WsPluginContext } from '@nger/ws';
|
3
|
+
import { Context } from 'koa';
|
4
|
+
import { UploadService } from './upload.service';
|
3
5
|
export declare const CREATE_TASK_DOWNLOADING = "@nger/fk-upload/create-task/downloading";
|
4
6
|
export declare class DownloadTaskController {
|
5
7
|
private db;
|
6
|
-
|
7
|
-
|
8
|
-
|
8
|
+
private upload;
|
9
|
+
constructor(db: Db, upload: UploadService);
|
10
|
+
createTask(url: string, ctx: Context): Promise<void>;
|
9
11
|
createTaskWs(url: string, ctx: WsPluginContext): Promise<import("rxjs").Subscription>;
|
10
12
|
}
|
@@ -20,24 +20,21 @@ const core_1 = require("@nger/core");
|
|
20
20
|
const http_1 = require("@nger/http");
|
21
21
|
const typeorm_1 = require("@nger/typeorm");
|
22
22
|
const entities_1 = require("../entities");
|
23
|
-
const request_1 = require("request");
|
24
|
-
const path_1 = require("path");
|
25
|
-
const cids_1 = __importDefault(require("cids"));
|
26
|
-
const multihashing_async_1 = __importDefault(require("multihashing-async"));
|
27
|
-
const url_1 = require("url");
|
28
23
|
const rxjs_1 = require("rxjs");
|
29
24
|
const ws_1 = require("@nger/ws");
|
30
|
-
const fs_1 = require("fs");
|
31
25
|
const md5_file_1 = __importDefault(require("md5-file"));
|
26
|
+
const upload_service_1 = require("./upload.service");
|
32
27
|
// md5-file
|
33
28
|
exports.CREATE_TASK_DOWNLOADING = `@nger/fk-upload/create-task/downloading`;
|
34
29
|
let DownloadTaskController = class DownloadTaskController {
|
35
30
|
db;
|
36
|
-
|
31
|
+
upload;
|
32
|
+
constructor(db, upload) {
|
37
33
|
this.db = db;
|
34
|
+
this.upload = upload;
|
38
35
|
}
|
39
|
-
async createTask(url) {
|
40
|
-
const observable = await this.
|
36
|
+
async createTask(url, ctx) {
|
37
|
+
const observable = await this.upload.createObservable(url);
|
41
38
|
observable.listen.pipe((0, rxjs_1.throttleTime)(1000), (0, rxjs_1.switchMap)(async (res) => {
|
42
39
|
const exist = await this.db.manager.findOne(entities_1.FkDownloadTaskEntity, { where: { filename: observable.filename } });
|
43
40
|
if (exist) {
|
@@ -55,89 +52,11 @@ let DownloadTaskController = class DownloadTaskController {
|
|
55
52
|
await this.db.manager.update(entities_1.FkDownloadTaskEntity, observable.filename, { status: 1, fileMd5: md5 });
|
56
53
|
}
|
57
54
|
});
|
58
|
-
|
59
|
-
|
60
|
-
async createUrl(url) {
|
61
|
-
const hash = await (0, multihashing_async_1.default)(Buffer.from(url), 'sha1', 16);
|
62
|
-
const cid = new cids_1.default(1, 'raw', hash, 'base64');
|
63
|
-
const _url = new url_1.URL(url);
|
64
|
-
const pathname = _url.pathname;
|
65
|
-
const ext = (0, path_1.extname)(pathname);
|
66
|
-
const filename = cid.toString('base64') + ext;
|
67
|
-
let item = await this.db.manager.findOne(entities_1.FkDownloadTaskEntity, { where: { filename } });
|
68
|
-
if (item) {
|
69
|
-
let task = item;
|
70
|
-
if (task.status) {
|
71
|
-
return {
|
72
|
-
listen: (0, rxjs_1.of)(task),
|
73
|
-
filename
|
74
|
-
};
|
75
|
-
}
|
76
|
-
const observable = new rxjs_1.Observable((sub) => {
|
77
|
-
// go on
|
78
|
-
const writeStream = (0, fs_1.createWriteStream)(task.path, { start: task.size });
|
79
|
-
const req = (0, request_1.get)(url, {
|
80
|
-
headers: {
|
81
|
-
'Content-Type': 'application/octet-stream'
|
82
|
-
}
|
83
|
-
});
|
84
|
-
let length = 0;
|
85
|
-
req.on('data', (buf) => {
|
86
|
-
length += buf.length;
|
87
|
-
if (length >= task.size) {
|
88
|
-
task.size = length;
|
89
|
-
writeStream.write(buf, (err) => {
|
90
|
-
if (err)
|
91
|
-
sub.error(err);
|
92
|
-
});
|
93
|
-
sub.next(task);
|
94
|
-
}
|
95
|
-
});
|
96
|
-
req.on('end', () => {
|
97
|
-
sub.complete();
|
98
|
-
writeStream.end();
|
99
|
-
});
|
100
|
-
});
|
101
|
-
return { listen: observable, filename };
|
102
|
-
}
|
103
|
-
;
|
104
|
-
const observable = new rxjs_1.Observable((sub) => {
|
105
|
-
let task = new entities_1.FkDownloadTaskEntity();
|
106
|
-
task.url = url;
|
107
|
-
const req = (0, request_1.get)(url);
|
108
|
-
const path = (0, path_1.join)(__dirname, 'dist', encodeURIComponent(filename));
|
109
|
-
const writeStream = (0, fs_1.createWriteStream)(path);
|
110
|
-
task.path = path;
|
111
|
-
let total = 0;
|
112
|
-
let length = 0;
|
113
|
-
task.filename = filename;
|
114
|
-
task.uploadSize = 0;
|
115
|
-
req.on('data', (buf) => {
|
116
|
-
length += buf.length;
|
117
|
-
task.size = length;
|
118
|
-
writeStream.write(buf, (err) => {
|
119
|
-
if (err)
|
120
|
-
sub.error(err);
|
121
|
-
});
|
122
|
-
sub.next(task);
|
123
|
-
});
|
124
|
-
req.on('end', () => {
|
125
|
-
sub.complete();
|
126
|
-
writeStream.end();
|
127
|
-
});
|
128
|
-
req.on('response', (resp) => {
|
129
|
-
const headers = resp.headers;
|
130
|
-
total = Number(Reflect.get(headers, 'content-length'));
|
131
|
-
task.totalSize = total;
|
132
|
-
task.size = 0;
|
133
|
-
task.status = 0;
|
134
|
-
sub.next(task);
|
135
|
-
});
|
136
|
-
});
|
137
|
-
return { listen: observable, filename };
|
55
|
+
ctx.redirect('/@nger/fk-upload/help');
|
56
|
+
return;
|
138
57
|
}
|
139
58
|
async createTaskWs(url, ctx) {
|
140
|
-
const observable = await this.
|
59
|
+
const observable = await this.upload.createObservable(url);
|
141
60
|
return observable.listen.pipe((0, rxjs_1.throttleTime)(1000), (0, rxjs_1.switchMap)(async (res) => {
|
142
61
|
const exist = await this.db.manager.findOne(entities_1.FkDownloadTaskEntity, { where: { filename: observable.filename } });
|
143
62
|
if (exist) {
|
@@ -164,8 +83,9 @@ let DownloadTaskController = class DownloadTaskController {
|
|
164
83
|
__decorate([
|
165
84
|
(0, http_1.Get)('create-task'),
|
166
85
|
__param(0, (0, http_1.Query)('url')),
|
86
|
+
__param(1, (0, core_1.Inject)(http_1.CONTEXT)),
|
167
87
|
__metadata("design:type", Function),
|
168
|
-
__metadata("design:paramtypes", [String]),
|
88
|
+
__metadata("design:paramtypes", [String, Object]),
|
169
89
|
__metadata("design:returntype", Promise)
|
170
90
|
], DownloadTaskController.prototype, "createTask", null);
|
171
91
|
__decorate([
|
@@ -178,6 +98,6 @@ __decorate([
|
|
178
98
|
], DownloadTaskController.prototype, "createTaskWs", null);
|
179
99
|
DownloadTaskController = __decorate([
|
180
100
|
(0, core_1.Controller)('@nger/fk-upload'),
|
181
|
-
__metadata("design:paramtypes", [typeorm_1.Db])
|
101
|
+
__metadata("design:paramtypes", [typeorm_1.Db, upload_service_1.UploadService])
|
182
102
|
], DownloadTaskController);
|
183
103
|
exports.DownloadTaskController = DownloadTaskController;
|
@@ -0,0 +1,41 @@
|
|
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.ErrorController = void 0;
|
19
|
+
const core_1 = require("@nger/core");
|
20
|
+
const http_1 = require("@nger/http");
|
21
|
+
const component_1 = require("./component");
|
22
|
+
const react_1 = __importDefault(require("react"));
|
23
|
+
let ErrorController = class ErrorController {
|
24
|
+
error(msg) {
|
25
|
+
return react_1.default.createElement(component_1.Nav, { active: -1 },
|
26
|
+
react_1.default.createElement("div", { className: "card" },
|
27
|
+
react_1.default.createElement("div", { className: "card-body" },
|
28
|
+
react_1.default.createElement("div", { className: "alert alert-danger", role: "alert" }, msg))));
|
29
|
+
}
|
30
|
+
};
|
31
|
+
__decorate([
|
32
|
+
(0, http_1.Get)('error'),
|
33
|
+
__param(0, (0, http_1.Query)('msg')),
|
34
|
+
__metadata("design:type", Function),
|
35
|
+
__metadata("design:paramtypes", [String]),
|
36
|
+
__metadata("design:returntype", void 0)
|
37
|
+
], ErrorController.prototype, "error", null);
|
38
|
+
ErrorController = __decorate([
|
39
|
+
(0, core_1.Controller)('@nger/fk-upload')
|
40
|
+
], ErrorController);
|
41
|
+
exports.ErrorController = ErrorController;
|
package/dist/templates/help.d.ts
CHANGED
package/dist/templates/help.js
CHANGED
@@ -24,21 +24,6 @@ let HelpController = class HelpController {
|
|
24
24
|
constructor(db) {
|
25
25
|
this.db = db;
|
26
26
|
}
|
27
|
-
addTask() {
|
28
|
-
return react_1.default.createElement(component_1.Nav, { active: 3 },
|
29
|
-
react_1.default.createElement("div", { className: "card" },
|
30
|
-
react_1.default.createElement("div", { className: "card-body" },
|
31
|
-
react_1.default.createElement("form", { action: "" },
|
32
|
-
react_1.default.createElement("div", { className: "form-group" },
|
33
|
-
react_1.default.createElement("label", { htmlFor: "url" }, "url"),
|
34
|
-
react_1.default.createElement("input", { type: "text", className: 'form-control', id: "url" })),
|
35
|
-
react_1.default.createElement("div", { className: "form-group" },
|
36
|
-
react_1.default.createElement("label", { htmlFor: "w7Username" }, "w7 account"),
|
37
|
-
react_1.default.createElement("input", { type: "text", className: 'form-control', id: "w7Username" })),
|
38
|
-
react_1.default.createElement("div", { className: "form-group" },
|
39
|
-
react_1.default.createElement("button", { type: "submit", className: "btn btn-primary" }, "submit"),
|
40
|
-
react_1.default.createElement("button", { type: "reset", className: "btn" }, "reset"))))));
|
41
|
-
}
|
42
27
|
async help() {
|
43
28
|
const list = await this.db.manager.find(fk_login_entity_1.FkLoginEntity, { where: {} });
|
44
29
|
return react_1.default.createElement(component_1.Nav, { active: 0 },
|
@@ -69,12 +54,6 @@ let HelpController = class HelpController {
|
|
69
54
|
}))))));
|
70
55
|
}
|
71
56
|
};
|
72
|
-
__decorate([
|
73
|
-
(0, http_1.Get)('add-task'),
|
74
|
-
__metadata("design:type", Function),
|
75
|
-
__metadata("design:paramtypes", []),
|
76
|
-
__metadata("design:returntype", void 0)
|
77
|
-
], HelpController.prototype, "addTask", null);
|
78
57
|
__decorate([
|
79
58
|
(0, http_1.Get)('help'),
|
80
59
|
__metadata("design:type", Function),
|
@@ -26,7 +26,7 @@ function getStatusTitle(status) {
|
|
26
26
|
case 1:
|
27
27
|
return 'uploading';
|
28
28
|
default:
|
29
|
-
return '
|
29
|
+
return 'finish';
|
30
30
|
}
|
31
31
|
}
|
32
32
|
let TaskManageController = class TaskManageController {
|
@@ -42,8 +42,7 @@ let TaskManageController = class TaskManageController {
|
|
42
42
|
react_1.default.createElement("table", { className: 'table' },
|
43
43
|
react_1.default.createElement("thead", null,
|
44
44
|
react_1.default.createElement("tr", null,
|
45
|
-
react_1.default.createElement("td",
|
46
|
-
react_1.default.createElement("td", { width: '240px' }, "url"),
|
45
|
+
react_1.default.createElement("td", { width: '180px' }, "filename"),
|
47
46
|
react_1.default.createElement("td", null, "status"),
|
48
47
|
react_1.default.createElement("td", null, "total size"),
|
49
48
|
react_1.default.createElement("td", null, "download size"),
|
@@ -53,7 +52,6 @@ let TaskManageController = class TaskManageController {
|
|
53
52
|
react_1.default.createElement("tbody", null, tasks.map((task, key) => {
|
54
53
|
return react_1.default.createElement("tr", { key: key },
|
55
54
|
react_1.default.createElement("td", null, task.filename),
|
56
|
-
react_1.default.createElement("td", null, task.url),
|
57
55
|
react_1.default.createElement("td", null, getStatusTitle(task.status)),
|
58
56
|
react_1.default.createElement("td", null, task.totalSize),
|
59
57
|
react_1.default.createElement("td", null, task.size),
|
package/dist/templates/upload.js
CHANGED
@@ -102,9 +102,12 @@ let UploadController = class UploadController {
|
|
102
102
|
return `error`;
|
103
103
|
}
|
104
104
|
preview(src) {
|
105
|
-
return react_1.default.createElement(
|
106
|
-
react_1.default.createElement("
|
107
|
-
|
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)))));
|
108
111
|
}
|
109
112
|
downloadFile(cloudUrl) {
|
110
113
|
return new Promise((resolve, reject) => {
|
@@ -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
|
+
}
|
@@ -0,0 +1,293 @@
|
|
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.UploadService = void 0;
|
16
|
+
const path_1 = require("path");
|
17
|
+
const entities_1 = require("../entities");
|
18
|
+
const cids_1 = __importDefault(require("cids"));
|
19
|
+
const multihashing_async_1 = __importDefault(require("multihashing-async"));
|
20
|
+
const typeorm_1 = require("@nger/typeorm");
|
21
|
+
const rxjs_1 = require("rxjs");
|
22
|
+
const request_1 = require("request");
|
23
|
+
const fs_1 = require("fs");
|
24
|
+
const md5_file_1 = __importDefault(require("md5-file"));
|
25
|
+
const core_1 = require("@nger/core");
|
26
|
+
const axios_1 = __importDefault(require("axios"));
|
27
|
+
const form_data_1 = __importDefault(require("form-data"));
|
28
|
+
let UploadService = class UploadService {
|
29
|
+
db;
|
30
|
+
constructor(db) {
|
31
|
+
this.db = db;
|
32
|
+
}
|
33
|
+
async createDownLoadTask(url, fkLoginId) {
|
34
|
+
const observable = await this.createObservable(url);
|
35
|
+
return observable.listen.pipe((0, rxjs_1.throttleTime)(1000), (0, rxjs_1.switchMap)(async (res) => {
|
36
|
+
const exist = await this.db.manager.findOne(entities_1.FkDownloadTaskEntity, { where: { filename: observable.filename } });
|
37
|
+
if (exist) {
|
38
|
+
const size = res.size;
|
39
|
+
const total = res.totalSize;
|
40
|
+
const num = Math.floor((size / total) * 100);
|
41
|
+
await this.db.manager.update(entities_1.FkDownloadTaskEntity, exist.filename, { size: num });
|
42
|
+
}
|
43
|
+
else {
|
44
|
+
await this.db.manager.save(entities_1.FkDownloadTaskEntity, res);
|
45
|
+
}
|
46
|
+
return res;
|
47
|
+
})).subscribe({
|
48
|
+
next: () => { },
|
49
|
+
complete: async () => {
|
50
|
+
const exist = await this.db.manager.findOne(entities_1.FkDownloadTaskEntity, { where: { filename: observable.filename } });
|
51
|
+
const md5 = await (0, md5_file_1.default)(exist.path);
|
52
|
+
await this.db.manager.update(entities_1.FkDownloadTaskEntity, observable.filename, { status: 1, size: 100, fileMd5: md5, loginId: fkLoginId });
|
53
|
+
// upload
|
54
|
+
return await this.createUplaodTask(exist.filename);
|
55
|
+
}
|
56
|
+
});
|
57
|
+
}
|
58
|
+
getUploadUrl(token, forceDirect = true) {
|
59
|
+
if (forceDirect) {
|
60
|
+
return `https://${token.url}/${token.visitType}/${token.app}/upload?cmd=${token.cmd}&token=${token.token}`;
|
61
|
+
}
|
62
|
+
else {
|
63
|
+
return `https://${token.url}/${token.visitType}/${token.app}/advance?cmd=${token.cmd}&token=${token.token}`;
|
64
|
+
}
|
65
|
+
}
|
66
|
+
getUploadInfourl(token) {
|
67
|
+
return `https://${token.url}/${token.visitType}/${token.app}/advance/info?cmd=${token.cmd}&token=${token.token}`;
|
68
|
+
}
|
69
|
+
encodeURIComponent(data) {
|
70
|
+
return Object.keys(data).map(key => {
|
71
|
+
const value = Reflect.get(data, key);
|
72
|
+
return `${key}=${encodeURIComponent(value)}`;
|
73
|
+
}).join('&');
|
74
|
+
}
|
75
|
+
async createUplaodTask(filename) {
|
76
|
+
//
|
77
|
+
const task = await this.db.manager.findOne(entities_1.FkDownloadTaskEntity, { where: { filename } });
|
78
|
+
if (task) {
|
79
|
+
if (task.status === 0) {
|
80
|
+
return {
|
81
|
+
msg: 'downloading'
|
82
|
+
};
|
83
|
+
}
|
84
|
+
if (task.status === 2) {
|
85
|
+
return {
|
86
|
+
msg: 'uploaded'
|
87
|
+
};
|
88
|
+
}
|
89
|
+
const loginEntity = await this.db.manager.findOne(entities_1.FkLoginEntity, { where: { fkLoginId: task.loginId } });
|
90
|
+
const cookies = await this.db.manager.find(entities_1.FkLoginCookieEntity, { where: { fkLoginId: task.loginId } });
|
91
|
+
const cookie = cookies.map(cookie => `${cookie.key}=${cookie.value}`).join(';');
|
92
|
+
// 00 take token
|
93
|
+
const url = `https://i.vip.webportal.top/`;
|
94
|
+
const iVipWebPortal = await axios_1.default.get(url, {
|
95
|
+
headers: {
|
96
|
+
Cookie: cookie
|
97
|
+
}
|
98
|
+
}).then(res => res.data);
|
99
|
+
const items = iVipWebPortal.match(/<meta id='_TOKEN' value='(.*?)'\/>/);
|
100
|
+
let token = ``;
|
101
|
+
if (items && items.length === 2) {
|
102
|
+
token = items[1];
|
103
|
+
}
|
104
|
+
if (token.length > 0) {
|
105
|
+
// 01
|
106
|
+
const url = `https://smr00.vip.webportal.top/cn/api/manage/advanceUpload/genAccessKey?_v=1651232099799&_TOKEN=${token}`;
|
107
|
+
const accessKey = await axios_1.default.get(url).then(res => res.data);
|
108
|
+
if (accessKey.success) {
|
109
|
+
const accessTokenString = decode(accessKey.accessKey);
|
110
|
+
if (accessTokenString) {
|
111
|
+
const accessToken = JSON.parse(accessTokenString);
|
112
|
+
const uploadInfoUrl = this.getUploadInfourl(accessToken);
|
113
|
+
const bssInfo = {
|
114
|
+
fromSite: true, siteId: 0, groupId: 0, fileSizeLimit: 1024
|
115
|
+
};
|
116
|
+
const info = await axios_1.default.post(uploadInfoUrl, this.encodeURIComponent({
|
117
|
+
fileMd5: task.fileMd5,
|
118
|
+
fileSize: task.totalSize,
|
119
|
+
isFreeVer: false,
|
120
|
+
aid: loginEntity.aid,
|
121
|
+
folderId: loginEntity.uploadGroupId,
|
122
|
+
bssInfo: JSON.stringify(bssInfo),
|
123
|
+
fileName: task.filename
|
124
|
+
}), { headers: { cookie: cookie } }).then(res => res.data);
|
125
|
+
if (info.code === 200) {
|
126
|
+
const data = info.data;
|
127
|
+
const { delayTime, splitSize, uploadedSize } = data;
|
128
|
+
const uploadUrl = this.getUploadUrl(accessToken, false);
|
129
|
+
const totalChunks = Math.ceil((task.totalSize - uploadedSize) / splitSize);
|
130
|
+
let start = uploadedSize;
|
131
|
+
let index = Math.ceil(uploadedSize / splitSize);
|
132
|
+
let complete = false;
|
133
|
+
do {
|
134
|
+
if (index >= totalChunks - 1) {
|
135
|
+
complete = true;
|
136
|
+
}
|
137
|
+
const fileStream = (0, fs_1.createReadStream)(task.path, { start: start, end: start + splitSize });
|
138
|
+
const formdata = new form_data_1.default();
|
139
|
+
formdata.append('ctrl', fileStream);
|
140
|
+
formdata.append('isFreeVer', 'false');
|
141
|
+
formdata.append('aid', `${loginEntity.aid || 0}`);
|
142
|
+
formdata.append('folderId', `${loginEntity.uploadGroupId || 0}`);
|
143
|
+
formdata.append('fileName', task.filename);
|
144
|
+
formdata.append(`totalSize`, `${task.totalSize}`);
|
145
|
+
formdata.append(`fileMd5`, task.fileMd5);
|
146
|
+
formdata.append('index', `${index}`);
|
147
|
+
formdata.append('chunkSize', `${splitSize}`);
|
148
|
+
formdata.append('totalChunks', `${totalChunks}`);
|
149
|
+
formdata.append(`complete`, `${complete}`);
|
150
|
+
formdata.append('bssInfo', JSON.stringify(bssInfo));
|
151
|
+
const headers = formdata.getHeaders();
|
152
|
+
const uploadResult = await axios_1.default.post(uploadUrl, formdata, {
|
153
|
+
headers: {
|
154
|
+
...headers,
|
155
|
+
Cookie: cookie
|
156
|
+
}
|
157
|
+
}).then(res => {
|
158
|
+
const data = res.data;
|
159
|
+
return data;
|
160
|
+
});
|
161
|
+
if (uploadResult.code === 200) {
|
162
|
+
const data = uploadResult.data;
|
163
|
+
if (data) {
|
164
|
+
const downUrl = data.downUrl;
|
165
|
+
if (downUrl) {
|
166
|
+
await this.db.manager.update(entities_1.FkDownloadTaskEntity, task.filename, {
|
167
|
+
status: 2,
|
168
|
+
uploadUrl: `https://` + downUrl,
|
169
|
+
uploadSize: 100
|
170
|
+
});
|
171
|
+
}
|
172
|
+
else {
|
173
|
+
await this.db.manager.update(entities_1.FkDownloadTaskEntity, task.filename, {
|
174
|
+
uploadSize: Math.floor(((index + 1) / totalChunks) * 100)
|
175
|
+
});
|
176
|
+
}
|
177
|
+
}
|
178
|
+
index = index + 1;
|
179
|
+
start = start + splitSize;
|
180
|
+
}
|
181
|
+
} while (!complete);
|
182
|
+
}
|
183
|
+
}
|
184
|
+
}
|
185
|
+
}
|
186
|
+
}
|
187
|
+
}
|
188
|
+
async createObservable(url) {
|
189
|
+
const hash = await (0, multihashing_async_1.default)(Buffer.from(url), 'sha1', 16);
|
190
|
+
const cid = new cids_1.default(1, 'raw', hash, 'base64');
|
191
|
+
// const _url = new URL(url);
|
192
|
+
// const pathname = _url.pathname;
|
193
|
+
// const ext = extname(pathname)
|
194
|
+
const filename = cid.toString('base64');
|
195
|
+
let item = await this.db.manager.findOne(entities_1.FkDownloadTaskEntity, { where: { filename } });
|
196
|
+
if (item) {
|
197
|
+
let task = item;
|
198
|
+
if (task.status) {
|
199
|
+
return {
|
200
|
+
listen: (0, rxjs_1.of)(task),
|
201
|
+
filename
|
202
|
+
};
|
203
|
+
}
|
204
|
+
const observable = new rxjs_1.Observable((sub) => {
|
205
|
+
// go on
|
206
|
+
const writeStream = (0, fs_1.createWriteStream)(task.path, { start: task.size });
|
207
|
+
const req = (0, request_1.get)(url, {
|
208
|
+
headers: {
|
209
|
+
'Content-Type': 'application/octet-stream'
|
210
|
+
}
|
211
|
+
});
|
212
|
+
let length = 0;
|
213
|
+
req.on('data', (buf) => {
|
214
|
+
length += buf.length;
|
215
|
+
if (length >= task.size) {
|
216
|
+
task.size = length;
|
217
|
+
writeStream.write(buf, (err) => {
|
218
|
+
if (err)
|
219
|
+
sub.error(err);
|
220
|
+
});
|
221
|
+
sub.next(task);
|
222
|
+
}
|
223
|
+
});
|
224
|
+
req.on('end', () => {
|
225
|
+
sub.complete();
|
226
|
+
writeStream.end();
|
227
|
+
});
|
228
|
+
});
|
229
|
+
return { listen: observable, filename };
|
230
|
+
}
|
231
|
+
;
|
232
|
+
const observable = new rxjs_1.Observable((sub) => {
|
233
|
+
let task = new entities_1.FkDownloadTaskEntity();
|
234
|
+
task.url = url;
|
235
|
+
const req = (0, request_1.get)(url);
|
236
|
+
const path = (0, path_1.join)(__dirname, 'dist', encodeURIComponent(filename));
|
237
|
+
const writeStream = (0, fs_1.createWriteStream)(path);
|
238
|
+
task.path = path;
|
239
|
+
let total = 0;
|
240
|
+
let length = 0;
|
241
|
+
task.filename = filename;
|
242
|
+
task.uploadSize = 0;
|
243
|
+
req.on('data', (buf) => {
|
244
|
+
length += buf.length;
|
245
|
+
task.size = length;
|
246
|
+
writeStream.write(buf, (err) => {
|
247
|
+
if (err)
|
248
|
+
sub.error(err);
|
249
|
+
});
|
250
|
+
sub.next(task);
|
251
|
+
});
|
252
|
+
req.on('end', () => {
|
253
|
+
sub.complete();
|
254
|
+
writeStream.end();
|
255
|
+
});
|
256
|
+
req.on('response', (resp) => {
|
257
|
+
const headers = resp.headers;
|
258
|
+
total = Number(Reflect.get(headers, 'content-length'));
|
259
|
+
task.totalSize = total;
|
260
|
+
task.size = 0;
|
261
|
+
task.status = 0;
|
262
|
+
sub.next(task);
|
263
|
+
});
|
264
|
+
});
|
265
|
+
return { listen: observable, filename };
|
266
|
+
}
|
267
|
+
};
|
268
|
+
UploadService = __decorate([
|
269
|
+
(0, core_1.Injectable)(),
|
270
|
+
__metadata("design:paramtypes", [typeorm_1.Db])
|
271
|
+
], UploadService);
|
272
|
+
exports.UploadService = UploadService;
|
273
|
+
function decode(base64Str) {
|
274
|
+
if (!base64Str)
|
275
|
+
return;
|
276
|
+
const t = base64Str.replace(/_/g, "/").replace(/-/g, "+");
|
277
|
+
const f = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
278
|
+
let l = 0;
|
279
|
+
let p = 0;
|
280
|
+
let h = [];
|
281
|
+
do {
|
282
|
+
const o = f.indexOf(t.charAt(l++));
|
283
|
+
const u = f.indexOf(t.charAt(l++));
|
284
|
+
const a = f.indexOf(t.charAt(l++));
|
285
|
+
const c = f.indexOf(t.charAt(l++));
|
286
|
+
const s = o << 18 | u << 12 | a << 6 | c;
|
287
|
+
const e = s >> 16 & 255;
|
288
|
+
const r = s >> 8 & 255;
|
289
|
+
const n = 255 & s;
|
290
|
+
h[p++] = 64 === a ? String.fromCharCode(e) : 64 === c ? String.fromCharCode(e, r) : String.fromCharCode(e, r, n);
|
291
|
+
} while (l < t.length);
|
292
|
+
return h.join('');
|
293
|
+
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@nger/fk-upload",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.7",
|
4
4
|
"description": "",
|
5
5
|
"main": "dist/core.js",
|
6
6
|
"types": "dist/core.d.ts",
|
@@ -11,14 +11,19 @@
|
|
11
11
|
"license": "ISC",
|
12
12
|
"dependencies": {
|
13
13
|
"@nger/core": "^1.0.0",
|
14
|
+
"@nger/api": "^1.0.0",
|
14
15
|
"@nger/http": "^4.0.0",
|
16
|
+
"@nger/typeorm": "^1.0.0",
|
15
17
|
"@nger/ws": "^1.0.0",
|
16
18
|
"@types/download": "^8.0.1",
|
17
19
|
"@types/request": "^2.48.8",
|
18
20
|
"axios": "^0.26.1",
|
21
|
+
"cids": "^1.1.9",
|
19
22
|
"download": "^8.0.0",
|
20
23
|
"form-data": "^4.0.0",
|
24
|
+
"fs-extra": "^10.1.0",
|
21
25
|
"md5-file": "^5.0.0",
|
26
|
+
"multihashing-async": "^2.1.4",
|
22
27
|
"request": "^2.88.2"
|
23
28
|
},
|
24
29
|
"scripts": {
|
package/pnpm-lock.yaml
CHANGED
@@ -1,31 +1,45 @@
|
|
1
1
|
lockfileVersion: 5.3
|
2
2
|
|
3
3
|
specifiers:
|
4
|
+
'@nger/api': workspace:^1.0.0
|
4
5
|
'@nger/core': workspace:^1.0.0
|
5
6
|
'@nger/http': workspace:^4.0.0
|
7
|
+
'@nger/typeorm': workspace:^1.0.0
|
6
8
|
'@nger/ws': workspace:^1.0.0
|
7
9
|
'@types/download': ^8.0.1
|
8
10
|
'@types/request': ^2.48.8
|
9
11
|
axios: ^0.26.1
|
12
|
+
cids: ^1.1.9
|
10
13
|
download: ^8.0.0
|
11
14
|
form-data: ^4.0.0
|
15
|
+
fs-extra: ^10.1.0
|
12
16
|
md5-file: ^5.0.0
|
17
|
+
multihashing-async: ^2.1.4
|
13
18
|
request: ^2.88.2
|
14
19
|
|
15
20
|
dependencies:
|
21
|
+
'@nger/api': link:../api
|
16
22
|
'@nger/core': link:../core
|
17
23
|
'@nger/http': link:../http
|
24
|
+
'@nger/typeorm': link:../typeorm
|
18
25
|
'@nger/ws': link:../ws
|
19
26
|
'@types/download': 8.0.1
|
20
27
|
'@types/request': 2.48.8
|
21
28
|
axios: 0.26.1
|
29
|
+
cids: 1.1.9
|
22
30
|
download: 8.0.0
|
23
31
|
form-data: 4.0.0
|
32
|
+
fs-extra: 10.1.0
|
24
33
|
md5-file: 5.0.0
|
34
|
+
multihashing-async: 2.1.4
|
25
35
|
request: 2.88.2
|
26
36
|
|
27
37
|
packages:
|
28
38
|
|
39
|
+
/@multiformats/base-x/4.0.1:
|
40
|
+
resolution: {integrity: sha512-eMk0b9ReBbV23xXU693TAIrLyeO5iTgBZGSJfpqriG8UkYvr/hC9u9pyMlAakDNHWmbhMZCDs6KQO0jzKD8OTw==}
|
41
|
+
dev: false
|
42
|
+
|
29
43
|
/@sindresorhus/is/0.7.0:
|
30
44
|
resolution: {integrity: sha512-ONhaKPIufzzrlNbqtWFFd+jlnemX6lJAgq9ZeiZtS7I1PIf/la7CW4m83rTXRnVnsMbW2k56pGYu7AUFJD9Pow==}
|
31
45
|
engines: {node: '>=4'}
|
@@ -136,6 +150,10 @@ packages:
|
|
136
150
|
safe-buffer: 5.2.1
|
137
151
|
dev: false
|
138
152
|
|
153
|
+
/blakejs/1.2.1:
|
154
|
+
resolution: {integrity: sha512-QXUSXI3QVc/gJME0dBpXrag1kbzOqCjCX8/b54ntNyW6sjtoqxqRk3LTmXzaJoh71zMsDCjM+47jS7XiwN/+fQ==}
|
155
|
+
dev: false
|
156
|
+
|
139
157
|
/buffer-alloc-unsafe/1.1.0:
|
140
158
|
resolution: {integrity: sha512-TEM2iMIEQdJ2yjPJoSIsldnleVaAk1oW3DBVUykyOLsEsFmEc9kn+SFFPz+gl54KQNxlDnAwCXosOS9Okx2xAg==}
|
141
159
|
dev: false
|
@@ -178,6 +196,17 @@ packages:
|
|
178
196
|
resolution: {integrity: sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=}
|
179
197
|
dev: false
|
180
198
|
|
199
|
+
/cids/1.1.9:
|
200
|
+
resolution: {integrity: sha512-l11hWRfugIcbGuTZwAM5PwpjPPjyb6UZOGwlHSnOBV5o07XhQ4gNpBN67FbODvpjyHtd+0Xs6KNvUcGBiDRsdg==}
|
201
|
+
engines: {node: '>=4.0.0', npm: '>=3.0.0'}
|
202
|
+
deprecated: This module has been superseded by the multiformats module
|
203
|
+
dependencies:
|
204
|
+
multibase: 4.0.6
|
205
|
+
multicodec: 3.2.1
|
206
|
+
multihashes: 4.0.3
|
207
|
+
uint8arrays: 3.0.0
|
208
|
+
dev: false
|
209
|
+
|
181
210
|
/clone-response/1.0.2:
|
182
211
|
resolution: {integrity: sha1-0dyXOSAxTfZ/vrlCI7TuNQI56Ws=}
|
183
212
|
dependencies:
|
@@ -317,6 +346,10 @@ packages:
|
|
317
346
|
once: 1.4.0
|
318
347
|
dev: false
|
319
348
|
|
349
|
+
/err-code/3.0.1:
|
350
|
+
resolution: {integrity: sha512-GiaH0KJUewYok+eeY05IIgjtAe4Yltygk9Wqp1V5yVWLdhf0hYZchRjNIT9bb0mSwRcIusT3cx7PJUf3zEIfUA==}
|
351
|
+
dev: false
|
352
|
+
|
320
353
|
/escape-string-regexp/1.0.5:
|
321
354
|
resolution: {integrity: sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=}
|
322
355
|
engines: {node: '>=0.8.0'}
|
@@ -451,6 +484,15 @@ packages:
|
|
451
484
|
resolution: {integrity: sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow==}
|
452
485
|
dev: false
|
453
486
|
|
487
|
+
/fs-extra/10.1.0:
|
488
|
+
resolution: {integrity: sha512-oRXApq54ETRj4eMiFzGnHWGy+zo5raudjuxN0b8H7s/RU2oW0Wvsx9O0ACRN/kRq9E8Vu/ReskGB5o3ji+FzHQ==}
|
489
|
+
engines: {node: '>=12'}
|
490
|
+
dependencies:
|
491
|
+
graceful-fs: 4.2.10
|
492
|
+
jsonfile: 6.1.0
|
493
|
+
universalify: 2.0.0
|
494
|
+
dev: false
|
495
|
+
|
454
496
|
/get-stream/2.3.1:
|
455
497
|
resolution: {integrity: sha1-Xzj5PzRgCWZu4BUKBUFn+Rvdld4=}
|
456
498
|
engines: {node: '>=0.10.0'}
|
@@ -600,6 +642,10 @@ packages:
|
|
600
642
|
is-object: 1.0.2
|
601
643
|
dev: false
|
602
644
|
|
645
|
+
/js-sha3/0.8.0:
|
646
|
+
resolution: {integrity: sha512-gF1cRrHhIzNfToc802P800N8PpXS+evLLXfsVpowqmAFR9uwbi89WvXg2QspOmXL8QL86J4T1EpFu+yUkwJY3Q==}
|
647
|
+
dev: false
|
648
|
+
|
603
649
|
/jsbn/0.1.1:
|
604
650
|
resolution: {integrity: sha1-peZUwuWi3rXyAdls77yoDA7y9RM=}
|
605
651
|
dev: false
|
@@ -620,6 +666,14 @@ packages:
|
|
620
666
|
resolution: {integrity: sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus=}
|
621
667
|
dev: false
|
622
668
|
|
669
|
+
/jsonfile/6.1.0:
|
670
|
+
resolution: {integrity: sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==}
|
671
|
+
dependencies:
|
672
|
+
universalify: 2.0.0
|
673
|
+
optionalDependencies:
|
674
|
+
graceful-fs: 4.2.10
|
675
|
+
dev: false
|
676
|
+
|
623
677
|
/jsprim/1.4.2:
|
624
678
|
resolution: {integrity: sha512-P2bSOMAc/ciLz6DzgjVlGJP9+BrJWu5UDGK70C2iweC5QBIeFf0ZXRvGjEj2uYgrY2MkAAhsSWHDWlFtEroZWw==}
|
625
679
|
engines: {node: '>=0.6.0'}
|
@@ -684,6 +738,52 @@ packages:
|
|
684
738
|
engines: {node: '>=4'}
|
685
739
|
dev: false
|
686
740
|
|
741
|
+
/multibase/4.0.6:
|
742
|
+
resolution: {integrity: sha512-x23pDe5+svdLz/k5JPGCVdfn7Q5mZVMBETiC+ORfO+sor9Sgs0smJzAjfTbM5tckeCqnaUuMYoz+k3RXMmJClQ==}
|
743
|
+
engines: {node: '>=12.0.0', npm: '>=6.0.0'}
|
744
|
+
deprecated: This module has been superseded by the multiformats module
|
745
|
+
dependencies:
|
746
|
+
'@multiformats/base-x': 4.0.1
|
747
|
+
dev: false
|
748
|
+
|
749
|
+
/multicodec/3.2.1:
|
750
|
+
resolution: {integrity: sha512-+expTPftro8VAW8kfvcuNNNBgb9gPeNYV9dn+z1kJRWF2vih+/S79f2RVeIwmrJBUJ6NT9IUPWnZDQvegEh5pw==}
|
751
|
+
deprecated: This module has been superseded by the multiformats module
|
752
|
+
dependencies:
|
753
|
+
uint8arrays: 3.0.0
|
754
|
+
varint: 6.0.0
|
755
|
+
dev: false
|
756
|
+
|
757
|
+
/multiformats/9.6.4:
|
758
|
+
resolution: {integrity: sha512-fCCB6XMrr6CqJiHNjfFNGT0v//dxOBMrOMqUIzpPc/mmITweLEyhvMpY9bF+jZ9z3vaMAau5E8B68DW77QMXkg==}
|
759
|
+
dev: false
|
760
|
+
|
761
|
+
/multihashes/4.0.3:
|
762
|
+
resolution: {integrity: sha512-0AhMH7Iu95XjDLxIeuCOOE4t9+vQZsACyKZ9Fxw2pcsRmlX4iCn1mby0hS0bb+nQOVpdQYWPpnyusw4da5RPhA==}
|
763
|
+
engines: {node: '>=12.0.0', npm: '>=6.0.0'}
|
764
|
+
dependencies:
|
765
|
+
multibase: 4.0.6
|
766
|
+
uint8arrays: 3.0.0
|
767
|
+
varint: 5.0.2
|
768
|
+
dev: false
|
769
|
+
|
770
|
+
/multihashing-async/2.1.4:
|
771
|
+
resolution: {integrity: sha512-sB1MiQXPSBTNRVSJc2zM157PXgDtud2nMFUEIvBrsq5Wv96sUclMRK/ecjoP1T/W61UJBqt4tCTwMkUpt2Gbzg==}
|
772
|
+
engines: {node: '>=12.0.0', npm: '>=6.0.0'}
|
773
|
+
dependencies:
|
774
|
+
blakejs: 1.2.1
|
775
|
+
err-code: 3.0.1
|
776
|
+
js-sha3: 0.8.0
|
777
|
+
multihashes: 4.0.3
|
778
|
+
murmurhash3js-revisited: 3.0.0
|
779
|
+
uint8arrays: 3.0.0
|
780
|
+
dev: false
|
781
|
+
|
782
|
+
/murmurhash3js-revisited/3.0.0:
|
783
|
+
resolution: {integrity: sha512-/sF3ee6zvScXMb1XFJ8gDsSnY+X8PbOyjIuBhtgis10W2Jx4ZjIhikUCIF9c4gpJxVnQIsPAFrSwTCuAjicP6g==}
|
784
|
+
engines: {node: '>=8.0.0'}
|
785
|
+
dev: false
|
786
|
+
|
687
787
|
/normalize-url/2.0.1:
|
688
788
|
resolution: {integrity: sha512-D6MUW4K/VzoJ4rJ01JFKxDrtY1v9wrgzCX5f2qj/lzH1m/lW6MhUZFKerVsnyjOhOsYzI9Kqqak+10l4LvLpMw==}
|
689
789
|
engines: {node: '>=4'}
|
@@ -992,6 +1092,12 @@ packages:
|
|
992
1092
|
resolution: {integrity: sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q=}
|
993
1093
|
dev: false
|
994
1094
|
|
1095
|
+
/uint8arrays/3.0.0:
|
1096
|
+
resolution: {integrity: sha512-HRCx0q6O9Bfbp+HHSfQQKD7wU70+lydKVt4EghkdOvlK/NlrF90z+eXV34mUd48rNvVJXwkrMSPpCATkct8fJA==}
|
1097
|
+
dependencies:
|
1098
|
+
multiformats: 9.6.4
|
1099
|
+
dev: false
|
1100
|
+
|
995
1101
|
/unbzip2-stream/1.4.3:
|
996
1102
|
resolution: {integrity: sha512-mlExGW4w71ebDJviH16lQLtZS32VKqsSfk80GCfUlwT/4/hNRFsoscrF/c++9xinkMzECL1uL9DDwXqFWkruPg==}
|
997
1103
|
dependencies:
|
@@ -999,6 +1105,11 @@ packages:
|
|
999
1105
|
through: 2.3.8
|
1000
1106
|
dev: false
|
1001
1107
|
|
1108
|
+
/universalify/2.0.0:
|
1109
|
+
resolution: {integrity: sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==}
|
1110
|
+
engines: {node: '>= 10.0.0'}
|
1111
|
+
dev: false
|
1112
|
+
|
1002
1113
|
/uri-js/4.4.1:
|
1003
1114
|
resolution: {integrity: sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==}
|
1004
1115
|
dependencies:
|
@@ -1027,6 +1138,14 @@ packages:
|
|
1027
1138
|
hasBin: true
|
1028
1139
|
dev: false
|
1029
1140
|
|
1141
|
+
/varint/5.0.2:
|
1142
|
+
resolution: {integrity: sha512-lKxKYG6H03yCZUpAGOPOsMcGxd1RHCu1iKvEHYDPmTyq2HueGhD73ssNBqqQWfvYs04G9iUFRvmAVLW20Jw6ow==}
|
1143
|
+
dev: false
|
1144
|
+
|
1145
|
+
/varint/6.0.0:
|
1146
|
+
resolution: {integrity: sha512-cXEIW6cfr15lFv563k4GuVuW/fiwjknytD37jIOLSdSWuOI6WnO/oKwmP2FQTU2l01LP8/M5TSAJpzUaGe3uWg==}
|
1147
|
+
dev: false
|
1148
|
+
|
1030
1149
|
/verror/1.10.0:
|
1031
1150
|
resolution: {integrity: sha1-OhBcoXBTr1XW4nDB+CiGguGNpAA=}
|
1032
1151
|
engines: {'0': node >=0.6.0}
|