@freelog/tools-lib 0.1.108 → 0.1.109

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.
@@ -20,4 +20,9 @@ interface TransformServerAPIContractStateParams {
20
20
  authStatus: 1 | 2 | 128 | number;
21
21
  }
22
22
  export declare function transformServerAPIContractState({ status, authStatus, }: TransformServerAPIContractStateParams): 'active' | 'testActive' | 'inactive' | 'terminal' | 'exception';
23
+ /**
24
+ * 暂时休眠
25
+ * @param ms 休眠时常(毫秒)
26
+ */
27
+ export declare function promiseSleep(ms?: number): Promise<void>;
23
28
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@freelog/tools-lib",
3
- "version": "0.1.108",
3
+ "version": "0.1.109",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -1,27 +1,65 @@
1
+ import * as FUtil from '../../utils/tools';
1
2
  import * as Storage from '../storages';
2
3
 
3
4
  interface FileInfo {
4
5
  sha1: string;
5
6
  state: 'success' | 'fail' | 'nonentity';
6
- dataSource: {
7
+ info: {
7
8
  [key: string]: any;
8
9
  }
9
10
  }
10
11
 
11
12
  interface GetFileInfosBySha1Params {
12
13
  sha1: string[];
13
- cdPartiallySuccess?: (s: any[]) => void;
14
- cdPartiallyFail?: (f: any[]) => void;
15
14
  }
16
15
 
17
- export async function getFilesSha1Info({sha1, cdPartiallySuccess, cdPartiallyFail}: GetFileInfosBySha1Params) {
18
- const {data} = await Storage.filesListInfo({
19
- sha1: sha1,
20
- });
16
+ export async function getFilesSha1Info({sha1}: GetFileInfosBySha1Params, cdPartially: (s: any[]) => void = () => undefined): Promise<FileInfo[]> {
17
+ if (sha1.length === 0) {
18
+ return [];
19
+ }
20
+
21
+ let needHandleSha1: string[] = [...sha1];
21
22
 
22
- const all: FileInfo[] = [];
23
- const success: any = [];
24
- const fail: any = [];
23
+ let allData: FileInfo[] = [];
25
24
 
26
- console.log(data, all, success, fail, cdPartiallySuccess, cdPartiallyFail, '093oijsdlkfsjdl')
25
+ while (true) {
26
+ const {data} = await Storage.filesListInfo({
27
+ sha1: needHandleSha1,
28
+ });
29
+ needHandleSha1 = data
30
+ .filter((d: any) => {
31
+ return d.metaAnalyzeStatus && d.metaAnalyzeStatus === 1;
32
+ })
33
+ .map((d: any) => {
34
+ return d.sha1;
35
+ });
36
+ const finishedInfo: FileInfo[] = data
37
+ .filter((d: any) => {
38
+ return !d.metaAnalyzeStatus || d.metaAnalyzeStatus !== 1;
39
+ })
40
+ .map((d: any) => {
41
+ let state: 'success' | 'fail' | 'nonentity' = 'fail';
42
+ if (!d.metaAnalyzeStatus) {
43
+ state = 'nonentity';
44
+ } else if (d.metaAnalyzeStatus === 2) {
45
+ state = 'success';
46
+ }
47
+ return {
48
+ sha1: d.sha1,
49
+ state,
50
+ info: d,
51
+ };
52
+ });
53
+ cdPartially && cdPartially(finishedInfo);
54
+ allData = [
55
+ ...allData,
56
+ ...finishedInfo,
57
+ ];
58
+
59
+ if (needHandleSha1.length === 0) {
60
+ break;
61
+ }
62
+ await FUtil.promiseSleep(3000)
63
+ }
64
+ return allData;
27
65
  }
@@ -13,7 +13,7 @@ import * as Activity from './activities';
13
13
  import * as TestQualification from './testQualifications';
14
14
  import * as Statistic from './statistics';
15
15
  import * as I18n from './i18n';
16
- import * as C from './combinations';
16
+ import * as combination from './combinations';
17
17
 
18
18
  const FServiceAPI = {
19
19
  Node,
@@ -31,7 +31,7 @@ const FServiceAPI = {
31
31
  TestQualification,
32
32
  Statistic,
33
33
  I18n,
34
- C,
34
+ combination,
35
35
  };
36
36
 
37
37
  export default FServiceAPI;
@@ -201,5 +201,5 @@ export function registerOrBind(params: RegisterOrBindParamsType) {
201
201
  method: 'POST',
202
202
  url: `/v2/thirdParty/registerOrBind`,
203
203
  data: params,
204
- });
204
+ }, {noRedirect: true});
205
205
  }
@@ -1,72 +1,85 @@
1
- import * as CryptoJS from 'crypto-js';
2
-
3
- /**
4
- * 根据 File 获取 SHA1 Hash 字符串
5
- * @param file
6
- * @return {Promise<string>}
7
- */
8
- export function getSHA1Hash(file: File): Promise<string> {
9
- return new Promise((resolve) => {
10
- const reader: FileReader = new FileReader();
11
- reader.onload = function () {
12
- const wordArray = CryptoJS.lib.WordArray.create(reader.result as any);
13
- const hash = CryptoJS.SHA1(wordArray).toString();
14
- resolve(hash);
15
- };
16
- reader.readAsArrayBuffer(file);
17
- });
18
- }
19
-
20
- /**
21
- * 生成随机码
22
- */
23
- export function generateRandomCode(strLen: number = 5): string {
24
- const allStr: string = 'ABCDEFGHIJKLMNPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890';
25
- const newStrArr: string[] = [];
26
- for (let i = 0; i < strLen; i++) {
27
- newStrArr.push(allStr[Math.floor(Math.random() * 61)]);
28
- }
29
- return newStrArr.join('');
30
- }
31
-
32
- /**
33
- * 通过读取 cookies 获取用户 ID
34
- */
35
- export function getUserIDByCookies(): number {
36
- const uid: string | undefined = document.cookie.split('; ').find((co) => co.startsWith('uid='));
37
- if (!uid) {
38
- return -1;
39
- }
40
- return Number(uid.replace('uid=', ''));
41
- }
42
-
43
-
44
- /**
45
- * 将服务端的合约状态转换成前端需要的状态
46
- */
47
- interface TransformServerAPIContractStateParams {
48
- status: 0 | 1 | 2; // 合同综合状态: 0:正常 1:已终止(不接受任何事件,也不给授权,事实上无效的合约) 2:异常
49
- authStatus: 1 | 2 | 128 | number; // 合同授权状态 1:正式授权 2:测试授权 128:未获得授权
50
- }
51
-
52
- export function transformServerAPIContractState({
53
- status,
54
- authStatus,
55
- }: TransformServerAPIContractStateParams): 'active' | 'testActive' | 'inactive' | 'terminal' | 'exception' {
56
- if (status === 0) {
57
- if (authStatus === 1 || authStatus === 3) {
58
- return 'active';
59
- }
60
- if (authStatus === 2) {
61
- return 'testActive';
62
- }
63
- if (authStatus === 128) {
64
- return 'inactive';
65
- }
66
- }
67
-
68
- if (status === 1) {
69
- return 'terminal';
70
- }
71
- return 'exception';
72
- }
1
+ import * as CryptoJS from 'crypto-js';
2
+
3
+ /**
4
+ * 根据 File 获取 SHA1 Hash 字符串
5
+ * @param file
6
+ * @return {Promise<string>}
7
+ */
8
+ export function getSHA1Hash(file: File): Promise<string> {
9
+ return new Promise((resolve) => {
10
+ const reader: FileReader = new FileReader();
11
+ reader.onload = function () {
12
+ const wordArray = CryptoJS.lib.WordArray.create(reader.result as any);
13
+ const hash = CryptoJS.SHA1(wordArray).toString();
14
+ resolve(hash);
15
+ };
16
+ reader.readAsArrayBuffer(file);
17
+ });
18
+ }
19
+
20
+ /**
21
+ * 生成随机码
22
+ */
23
+ export function generateRandomCode(strLen: number = 5): string {
24
+ const allStr: string = 'ABCDEFGHIJKLMNPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890';
25
+ const newStrArr: string[] = [];
26
+ for (let i = 0; i < strLen; i++) {
27
+ newStrArr.push(allStr[Math.floor(Math.random() * 61)]);
28
+ }
29
+ return newStrArr.join('');
30
+ }
31
+
32
+ /**
33
+ * 通过读取 cookies 获取用户 ID
34
+ */
35
+ export function getUserIDByCookies(): number {
36
+ const uid: string | undefined = document.cookie.split('; ').find((co) => co.startsWith('uid='));
37
+ if (!uid) {
38
+ return -1;
39
+ }
40
+ return Number(uid.replace('uid=', ''));
41
+ }
42
+
43
+
44
+ /**
45
+ * 将服务端的合约状态转换成前端需要的状态
46
+ */
47
+ interface TransformServerAPIContractStateParams {
48
+ status: 0 | 1 | 2; // 合同综合状态: 0:正常 1:已终止(不接受任何事件,也不给授权,事实上无效的合约) 2:异常
49
+ authStatus: 1 | 2 | 128 | number; // 合同授权状态 1:正式授权 2:测试授权 128:未获得授权
50
+ }
51
+
52
+ export function transformServerAPIContractState({
53
+ status,
54
+ authStatus,
55
+ }: TransformServerAPIContractStateParams): 'active' | 'testActive' | 'inactive' | 'terminal' | 'exception' {
56
+ if (status === 0) {
57
+ if (authStatus === 1 || authStatus === 3) {
58
+ return 'active';
59
+ }
60
+ if (authStatus === 2) {
61
+ return 'testActive';
62
+ }
63
+ if (authStatus === 128) {
64
+ return 'inactive';
65
+ }
66
+ }
67
+
68
+ if (status === 1) {
69
+ return 'terminal';
70
+ }
71
+ return 'exception';
72
+ }
73
+
74
+ /**
75
+ * 暂时休眠
76
+ * @param ms 休眠时常(毫秒)
77
+ */
78
+ export function promiseSleep(ms: number = 300): Promise<void> {
79
+ return new Promise((resolve) => {
80
+ setTimeout(() => {
81
+ resolve();
82
+ }, ms);
83
+ });
84
+ }
85
+