@freelog/tools-lib 0.1.154 → 0.1.156

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.
@@ -100,35 +100,53 @@ interface ResourceInfoParamsType {
100
100
  }
101
101
 
102
102
  export function resourceInfo({resourceID}: ResourceInfoParamsType): TReturnType {
103
- return `/resource/info/${resourceID}`;
103
+ return `/resource/sidebar/info/${resourceID}`;
104
104
  }
105
105
 
106
- // 资源授权
107
- interface ResourceAuthParamsType {
106
+ // 资源授权策略
107
+ interface ResourcePolicyParamsType {
108
108
  resourceID: string;
109
109
  }
110
110
 
111
- export function resourceAuth({resourceID}: ResourceAuthParamsType): TReturnType {
112
- return `/resource/auth/${resourceID}`;
111
+ export function resourcePolicy({resourceID}: ResourcePolicyParamsType): TReturnType {
112
+ return `/resource/sidebar/policy/${resourceID}`;
113
113
  }
114
114
 
115
- // 资源创建版本
116
- interface ResourceCreateVersionParamsType {
115
+ // 资源授权合约
116
+ interface ResourceContractParamsType {
117
117
  resourceID: string;
118
118
  }
119
119
 
120
- export function resourceCreateVersion({resourceID}: ResourceCreateVersionParamsType): TReturnType {
121
- return `/resource/version/creator/${resourceID}`;
120
+ export function resourceContract({resourceID}: ResourceContractParamsType): TReturnType {
121
+ return `/resource/sidebar/contract/${resourceID}`;
122
+ }
123
+
124
+ // 资源被授权管理
125
+ interface ResourceDependencyParamsType {
126
+ resourceID: string;
127
+ }
128
+
129
+ export function resourceDependency({resourceID}: ResourceDependencyParamsType): TReturnType {
130
+ return `/resource/sidebar/dependency/${resourceID}`;
131
+ }
132
+
133
+ // 资源版本创建
134
+ interface ResourceVersionCreatorParamsType {
135
+ resourceID: string;
136
+ }
137
+
138
+ export function resourceVersionCreator({resourceID}: ResourceVersionCreatorParamsType): TReturnType {
139
+ return `/resource/versionCreator/${resourceID}`;
122
140
  }
123
141
 
124
142
  // 资源版本信息
125
- interface ResourceVersionParamsType {
143
+ interface ResourceVersionInfoParamsType {
126
144
  resourceID: string;
127
- version: string;
145
+ version?: string;
128
146
  }
129
147
 
130
- export function resourceVersion({resourceID, version}: ResourceVersionParamsType): TReturnType {
131
- return `/resource/version/info/${resourceID}/${version}`;
148
+ export function resourceVersionInfo({resourceID, version = ''}: ResourceVersionInfoParamsType): TReturnType {
149
+ return `/resource/sidebar/versionInfo/${resourceID}${handleQuery({version})}`;
132
150
  }
133
151
 
134
152
  // 节点创建
@@ -143,7 +161,7 @@ export function nodeCreator({}: NodeCreatorParamsType = {}): TReturnType {
143
161
  // 节点管理
144
162
  interface NodeManagementParamsType {
145
163
  nodeID: number;
146
- showPage?: 'exhibit' | 'theme' | 'mappingRule';
164
+ showPage?: 'exhibit' | 'theme' | 'contract' | 'setting';
147
165
  }
148
166
 
149
167
  export function nodeManagement({nodeID, showPage = 'exhibit', ...params}: NodeManagementParamsType): TReturnType {
@@ -1,93 +1,102 @@
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
-
86
- /**
87
- * 获取用户头像URL
88
- * @param userID
89
- */
90
- export function getAvatarUrl(userID: number = 0): string {
91
- // return `${completeUrlByDomain('image')}/headImage/${userID || getUserIDByCookies()}?t=${Date.now()}`;
92
- return `https://image.freelog.com/headImage/${userID || getUserIDByCookies()}?t=${Date.now()}`;
93
- }
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.readAsArrayBuffer(file);
12
+ reader.onload = async () => {
13
+ if (!reader.result) {
14
+ resolve('');
15
+ return '';
16
+ }
17
+ if (typeof reader.result === 'string') {
18
+ resolve('');
19
+ return '';
20
+ }
21
+ const sha1 = await self.crypto.subtle.digest('SHA-1', reader.result).then(a => Array.from(new Uint8Array(a)).map(a => a.toString(16).padStart(2, '0')).join(''));
22
+ resolve(sha1);
23
+ return '';
24
+ };
25
+
26
+ });
27
+ }
28
+
29
+ /**
30
+ * 生成随机码
31
+ */
32
+ export function generateRandomCode(strLen: number = 5): string {
33
+ const allStr: string = 'ABCDEFGHIJKLMNPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890';
34
+ const newStrArr: string[] = [];
35
+ for (let i = 0; i < strLen; i++) {
36
+ newStrArr.push(allStr[Math.floor(Math.random() * 61)]);
37
+ }
38
+ return newStrArr.join('');
39
+ }
40
+
41
+ /**
42
+ * 通过读取 cookies 获取用户 ID
43
+ */
44
+ export function getUserIDByCookies(): number {
45
+ const uid: string | undefined = document.cookie.split('; ').find((co) => co.startsWith('uid='));
46
+ if (!uid) {
47
+ return -1;
48
+ }
49
+ return Number(uid.replace('uid=', ''));
50
+ }
51
+
52
+
53
+ /**
54
+ * 将服务端的合约状态转换成前端需要的状态
55
+ */
56
+ interface TransformServerAPIContractStateParams {
57
+ status: 0 | 1 | 2; // 合同综合状态: 0:正常 1:已终止(不接受任何事件,也不给授权,事实上无效的合约) 2:异常
58
+ authStatus: 1 | 2 | 128 | number; // 合同授权状态 1:正式授权 2:测试授权 128:未获得授权
59
+ }
60
+
61
+ export function transformServerAPIContractState({
62
+ status,
63
+ authStatus,
64
+ }: TransformServerAPIContractStateParams): 'active' | 'testActive' | 'inactive' | 'terminal' | 'exception' {
65
+ if (status === 0) {
66
+ if (authStatus === 1 || authStatus === 3) {
67
+ return 'active';
68
+ }
69
+ if (authStatus === 2) {
70
+ return 'testActive';
71
+ }
72
+ if (authStatus === 128) {
73
+ return 'inactive';
74
+ }
75
+ }
76
+
77
+ if (status === 1) {
78
+ return 'terminal';
79
+ }
80
+ return 'exception';
81
+ }
82
+
83
+ /**
84
+ * 暂时休眠
85
+ * @param ms 休眠时常(毫秒)
86
+ */
87
+ export function promiseSleep(ms: number = 300): Promise<void> {
88
+ return new Promise((resolve) => {
89
+ setTimeout(() => {
90
+ resolve();
91
+ }, ms);
92
+ });
93
+ }
94
+
95
+ /**
96
+ * 获取用户头像URL
97
+ * @param userID
98
+ */
99
+ export function getAvatarUrl(userID: number = 0): string {
100
+ // return `${completeUrlByDomain('image')}/avatar/${userID || getUserIDByCookies()}?t=${Date.now()}`;
101
+ return `https://image.freelog.com/avatar/${userID || getUserIDByCookies()}?t=${Date.now()}`;
102
+ }