@nger/fk-upload 1.0.39 → 1.0.42

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.
@@ -5,7 +5,7 @@ export declare class LoginController {
5
5
  cookies: Map<string, Map<string, string>>;
6
6
  constructor(db: Db);
7
7
  login(loginId: string, ctx: Context): Promise<any>;
8
- relogin(token: string, loginId: string, ctx: Context): Promise<"login fail : username or password error" | undefined>;
8
+ relogin(token: string, loginId: string, ctx: Context): Promise<string>;
9
9
  private tryLogin;
10
10
  logDog(arg0: number, arg1: number): void;
11
11
  private loginSuccess;
package/dist/main.js CHANGED
@@ -5,7 +5,6 @@ const tslib_1 = require("tslib");
5
5
  require("reflect-metadata");
6
6
  require('dotenv').config();
7
7
  const core_1 = require("@nger/core");
8
- const core_2 = require("@nger/core");
9
8
  const fk_upload_module_1 = require("./fk-upload.module");
10
9
  const http_1 = require("@nger/http");
11
10
  const typeorm_1 = require("@nger/typeorm");
@@ -19,7 +18,7 @@ const w7_1 = require("@nger/w7");
19
18
  let AppModule = class AppModule {
20
19
  };
21
20
  AppModule = tslib_1.__decorate([
22
- (0, core_2.Module)({
21
+ (0, core_1.Module)({
23
22
  providers: [{
24
23
  provide: core_1.APP_ROOT,
25
24
  useValue: process.cwd()
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  const url = new URL(window.location.href);
3
2
  const WS_PORT = Reflect.get(window, 'WS_PORT');
4
3
  const socket = new WebSocket(`ws://${url.hostname}:${WS_PORT}`);
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { Db } from '@nger/typeorm';
2
3
  import { Context } from 'koa';
3
4
  import { CryptoService } from '@nger/utils';
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { Db } from '@nger/typeorm';
2
3
  import { Context } from 'koa';
3
4
  import { TaskService } from './tasks/task.service';
@@ -24,6 +24,14 @@ let AddTaskController = class AddTaskController {
24
24
  const loginEntity = await this.db.manager.findOne(entities_1.FkLoginEntity, { where: { w7Username: we7Username } });
25
25
  if (loginEntity) {
26
26
  const task = await this.taskService.createDownLoadTask(url, loginEntity.fkLoginId, 0);
27
+ const download = task.data;
28
+ const fkdownloadTask = new entities_1.FkDownloadTaskEntity();
29
+ fkdownloadTask.filename = download.filename;
30
+ fkdownloadTask.loginId = download.loginId;
31
+ fkdownloadTask.path = download.path;
32
+ fkdownloadTask.url = download.url;
33
+ fkdownloadTask.topicId = download.topicId;
34
+ await this.db.manager.save(entities_1.FkDownloadTaskEntity, fkdownloadTask);
27
35
  await this.task.send(task);
28
36
  }
29
37
  ctx.redirect('/@nger/fk-upload/task-manage');
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  export declare class FkUploadCodeController {
2
3
  upload(loginId: string): JSX.Element;
3
4
  }
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  export interface Nav {
2
3
  title: string;
3
4
  link: string;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  export declare class ErrorController {
2
3
  error(msg: string): JSX.Element;
3
4
  }
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { Db } from '@nger/typeorm';
2
3
  export declare class HelpController {
3
4
  private db;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  export declare class Player {
2
3
  player(): JSX.Element;
3
4
  }
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { TaskService } from './tasks/task.service';
2
3
  import { Client } from '@nger/redis';
3
4
  import { Context } from 'koa';
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { Config } from '@nger/core';
2
3
  import { Db } from '@nger/typeorm';
3
4
  import { Context } from 'koa';
@@ -12,6 +12,8 @@ const fs_extra_1 = require("fs-extra");
12
12
  const path_1 = require("path");
13
13
  const typeorm_1 = require("@nger/typeorm");
14
14
  const entities_1 = require("../../entities");
15
+ const rxjs_1 = require("rxjs");
16
+ const operators_1 = require("rxjs/operators");
15
17
  /**
16
18
  * upload and task
17
19
  */
@@ -20,6 +22,7 @@ class DownloadTask extends rabbitmq_1.Task {
20
22
  super(actions_1.DOWNLOAD_ACTION);
21
23
  }
22
24
  async handle(injector, next) {
25
+ const db = injector.get(typeorm_1.Db);
23
26
  const task = injector.get(rabbitmq_1.DATA);
24
27
  const complete = injector.get(rabbitmq_1.COMPLETE);
25
28
  const fail = injector.get(rabbitmq_1.FAIL);
@@ -32,12 +35,19 @@ class DownloadTask extends rabbitmq_1.Task {
32
35
  'Content-Type': 'application/octet-stream'
33
36
  }
34
37
  });
35
- let length = 0;
36
38
  let total = 0;
39
+ let length = 0;
37
40
  let md5 = ``;
41
+ console.log(`download ${url}`);
42
+ const sub = new rxjs_1.Subject();
43
+ sub.pipe((0, operators_1.throttleTime)(1000), (0, operators_1.switchMap)((size) => {
44
+ console.log(`download ${task.filename}: ${length}`);
45
+ return db.manager.update(entities_1.FkDownloadTaskEntity, task.filename, { size });
46
+ })).subscribe();
38
47
  // get split size
39
48
  req.on('data', (buf) => {
40
49
  length += buf.length;
50
+ sub.next(length);
41
51
  writeStream.write(buf, (err) => {
42
52
  if (err)
43
53
  fail();
@@ -45,6 +55,7 @@ class DownloadTask extends rabbitmq_1.Task {
45
55
  });
46
56
  req.on('end', async () => {
47
57
  writeStream.end();
58
+ sub.complete();
48
59
  const fileMd5 = await (0, md5_file_1.default)(task.path);
49
60
  const isEqual = md5 === fileMd5;
50
61
  console.log(`file download success ${task.filename}, check result is ${isEqual}`);
@@ -17,8 +17,8 @@ class EffectTask extends rabbitmq_1.Task {
17
17
  const fail = injector.get(rabbitmq_1.FAIL);
18
18
  const w7 = injector.get(w7_1.W7DataSource);
19
19
  const db = injector.get(typeorm_1.Db);
20
+ await db.manager.update(entities_1.FkDownloadTaskEntity, task.filename, { status: 3, uploadUrl: task.uploadUrl });
20
21
  if (task.topicId) {
21
- await db.manager.update(entities_1.FkDownloadTaskEntity, task.filename, { status: 3, uploadUrl: task.uploadUrl });
22
22
  await (0, fs_extra_1.unlink)(task.path);
23
23
  await w7.manager.update(w7_1.W7ChatTopicEntity, task.topicId, { thirdUrl: task.uploadUrl }).then(() => complete()).catch(() => fail());
24
24
  }
@@ -163,6 +163,7 @@ let FkService = class FkService {
163
163
  task.uploadUrl = fullUrl;
164
164
  }
165
165
  }
166
+ console.log(`uploading ${index / task.totalChunks}`);
166
167
  index = index + 1;
167
168
  } while (!complete);
168
169
  // upload complete
@@ -26,13 +26,18 @@ class ScheduleTask extends rabbitmq_1.Task {
26
26
  const run = async () => {
27
27
  const accounts = await db.manager.find(entities_1.FkLoginEntity, {});
28
28
  const w7Usernames = accounts.map(account => account.w7Username);
29
+ console.log(`accounts`, accounts);
29
30
  const users = await w7.manager.find(w7_1.W7UsersEntity, { where: { username: (0, typeorm_2.In)(w7Usernames) } });
30
31
  const uids = users.map(user => user.uid);
31
32
  const uniAccounts = await w7.manager.find(w7_1.W7UniAccountEntity, { where: { createUid: (0, typeorm_2.In)(uids) } });
32
33
  const uniacids = uniAccounts.map(a => a.uniacid);
34
+ console.log(`uniacids`, uniacids);
33
35
  const tasks = await db.manager.find(entities_1.FkDownloadTaskEntity, { select: ['topicId'] });
34
36
  const ids = tasks.map(task => task.topicId);
35
- const topics = await w7.manager.find(w7_1.W7ChatTopicEntity, { where: { uniacid: (0, typeorm_2.In)(uniacids), id: (0, typeorm_2.Not)((0, typeorm_2.In)(ids)) } });
37
+ console.log(`topic ids`, ids);
38
+ const date = new Date('2022-05-14');
39
+ const topics = await w7.manager.find(w7_1.W7ChatTopicEntity, { where: { uniacid: (0, typeorm_2.In)(uniacids), id: (0, typeorm_2.Not)((0, typeorm_2.In)(ids)), createTime: Math.floor(date.getTime() / 1000) } });
40
+ console.log(`topics`, topics);
36
41
  topics.map(async (topic) => {
37
42
  if (topic.thirdUrl) {
38
43
  const uniacid = topic.uniacid;
@@ -43,7 +43,18 @@ let TaskService = class TaskService {
43
43
  const _url = new URL(url);
44
44
  const filePath = _url.pathname;
45
45
  let ext = (0, path_1.extname)(filePath);
46
- filename += ext === '.' ? '.mp4' : ext;
46
+ if (ext.length < 5) {
47
+ filename += ext === '.' ? '.mp4' : ext;
48
+ }
49
+ else if (filename.indexOf('.jpg')) {
50
+ filename += '.jpg';
51
+ }
52
+ else if (filename.indexOf('.png')) {
53
+ filename += '.png';
54
+ }
55
+ else if (filename.indexOf('.mp4')) {
56
+ filename += '.mp4';
57
+ }
47
58
  const root = this.injector.get(core_1.APP_ROOT);
48
59
  (0, fs_extra_1.ensureDirSync)((0, path_1.join)(root, 'attachments/fk-upload'));
49
60
  const path = (0, path_1.join)(root, 'attachments/fk-upload', filename);
@@ -5,5 +5,5 @@ export declare class UploadTaskController {
5
5
  constructor(db: Db);
6
6
  uploadTask(filename: string): Promise<{
7
7
  msg: string;
8
- } | undefined>;
8
+ }>;
9
9
  }
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { Db } from '@nger/typeorm';
2
3
  import { Context } from 'koa';
3
4
  export declare class UploadController {
@@ -4,7 +4,6 @@ exports.UploadController = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const core_1 = require("@nger/core");
6
6
  const http_1 = require("@nger/http");
7
- const react_1 = tslib_1.__importDefault(require("react"));
8
7
  const form_data_1 = tslib_1.__importDefault(require("form-data"));
9
8
  const axios_1 = tslib_1.__importDefault(require("axios"));
10
9
  const typeorm_1 = require("@nger/typeorm");
@@ -15,6 +14,7 @@ const url_1 = require("url");
15
14
  const fs_extra_1 = require("fs-extra");
16
15
  const request_1 = tslib_1.__importDefault(require("request"));
17
16
  const component_1 = require("./component");
17
+ const react_1 = tslib_1.__importDefault(require("react"));
18
18
  let UploadController = class UploadController {
19
19
  db;
20
20
  constructor(db) {
package/docs.md CHANGED
@@ -32,3 +32,4 @@ RABBITMQ_USERNAME=imeepos
32
32
  RABBITMQ_PASSWORD=123qwe
33
33
  ```
34
34
 
35
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nger/fk-upload",
3
- "version": "1.0.39",
3
+ "version": "1.0.42",
4
4
  "description": "",
5
5
  "main": "dist/core.js",
6
6
  "types": "dist/core.d.ts",
@@ -20,7 +20,7 @@
20
20
  "@nger/w7": "^1.0.0",
21
21
  "@nger/ws": "^1.0.0",
22
22
  "@types/download": "^8.0.1",
23
- "@types/react": "^18.0.5",
23
+ "@types/react": "^18.0.8",
24
24
  "@types/request": "^2.48.8",
25
25
  "axios": "^0.26.1",
26
26
  "cids": "^1.1.9",
@@ -29,7 +29,7 @@
29
29
  "fs-extra": "^10.1.0",
30
30
  "md5-file": "^5.0.0",
31
31
  "multihashing-async": "^2.1.4",
32
- "react": "^18.0.0",
32
+ "react": "^18.1.0",
33
33
  "request": "^2.88.2"
34
34
  },
35
35
  "scripts": {
package/pnpm-lock.yaml CHANGED
@@ -11,7 +11,7 @@ specifiers:
11
11
  '@nger/w7': workspace:^1.0.0
12
12
  '@nger/ws': workspace:^1.0.0
13
13
  '@types/download': ^8.0.1
14
- '@types/react': ^18.0.5
14
+ '@types/react': ^18.0.8
15
15
  '@types/request': ^2.48.8
16
16
  axios: ^0.26.1
17
17
  cids: ^1.1.9
@@ -20,7 +20,7 @@ specifiers:
20
20
  fs-extra: ^10.1.0
21
21
  md5-file: ^5.0.0
22
22
  multihashing-async: ^2.1.4
23
- react: ^18.0.0
23
+ react: ^18.1.0
24
24
  request: ^2.88.2
25
25
 
26
26
  dependencies:
@@ -30,7 +30,7 @@ dependencies:
30
30
  '@nger/rabbitmq': link:../rabbitmq
31
31
  '@nger/redis': link:../redis
32
32
  '@nger/schedule': link:../schedule
33
- '@nger/typeorm': link:../package
33
+ '@nger/typeorm': link:../typeorm
34
34
  '@nger/w7': link:../w7
35
35
  '@nger/ws': link:../ws
36
36
  '@types/download': 8.0.1