@freelog/tools-lib 0.1.157 → 0.1.160
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/service-API/contracts.d.ts +10 -0
- package/dist/service-API/resources.d.ts +65 -0
- package/dist/service-API/storages.d.ts +10 -0
- package/dist/tools-lib.cjs.development.js +186 -120
- package/dist/tools-lib.cjs.development.js.map +1 -1
- package/dist/tools-lib.cjs.production.min.js +1 -1
- package/dist/tools-lib.cjs.production.min.js.map +1 -1
- package/dist/tools-lib.esm.js +186 -120
- package/dist/tools-lib.esm.js.map +1 -1
- package/dist/utils/linkTo.d.ts +10 -1
- package/package.json +1 -1
- package/src/service-API/contracts.ts +20 -1
- package/src/service-API/presentables.ts +293 -293
- package/src/service-API/resources.ts +746 -645
- package/src/service-API/storages.ts +391 -362
- package/src/utils/axios.ts +1 -1
- package/src/utils/format.ts +1 -1
- package/src/utils/linkTo.ts +23 -2
- package/src/utils/tools.ts +102 -102
package/src/utils/axios.ts
CHANGED
|
@@ -30,7 +30,7 @@ if (window.location.hostname.includes('.com')) {
|
|
|
30
30
|
// apiHost = `${window.location.protocol}//qi.${(window.location.host.match(/(?<=\.).*/) || [''])[0]}`;
|
|
31
31
|
// apiHost = window.location.origin.replace('console', 'qi');
|
|
32
32
|
axios.defaults.withCredentials = true;
|
|
33
|
-
axios.defaults.baseURL = completeUrlByDomain('
|
|
33
|
+
axios.defaults.baseURL = completeUrlByDomain('api');
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
/**
|
package/src/utils/format.ts
CHANGED
|
@@ -32,7 +32,7 @@ export function formatDateTime(date: string, showTime: boolean = false) {
|
|
|
32
32
|
* @param domain 要组合的三级域名
|
|
33
33
|
*/
|
|
34
34
|
export function completeUrlByDomain(domain: string): string {
|
|
35
|
-
let origin: string = `
|
|
35
|
+
let origin: string = `https://${domain}.testfreelog.com`;
|
|
36
36
|
|
|
37
37
|
if (window.location.origin.includes('.freelog.com')) {
|
|
38
38
|
origin = `https://${domain}.freelog.com`;
|
package/src/utils/linkTo.ts
CHANGED
|
@@ -70,6 +70,14 @@ export function resourceDetails({resourceID, ...params}: ResourceDetailsParamsTy
|
|
|
70
70
|
return `/resource/details/${resourceID}${handleQuery(params)}`;
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
+
// 资源创建入口
|
|
74
|
+
interface ResourceCreatorParamsType {
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function resourceCreatorEntry({}: ResourceCreatorParamsType = {}): TReturnType {
|
|
78
|
+
return `/resource/creatorEntry`;
|
|
79
|
+
}
|
|
80
|
+
|
|
73
81
|
// 资源创建
|
|
74
82
|
interface ResourceCreatorParamsType {
|
|
75
83
|
}
|
|
@@ -78,6 +86,14 @@ export function resourceCreator({}: ResourceCreatorParamsType = {}): TReturnType
|
|
|
78
86
|
return `/resource/creator`;
|
|
79
87
|
}
|
|
80
88
|
|
|
89
|
+
// 资源批量创建
|
|
90
|
+
interface ResourceCreatorParamsType {
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function resourceCreatorBatch({}: ResourceCreatorParamsType = {}): TReturnType {
|
|
94
|
+
return `/resource/creatorBatch`;
|
|
95
|
+
}
|
|
96
|
+
|
|
81
97
|
// 我的资源
|
|
82
98
|
interface MyResourcesParamsType {
|
|
83
99
|
}
|
|
@@ -409,10 +425,15 @@ export function reward({}: RewardParamsType = {}) {
|
|
|
409
425
|
|
|
410
426
|
// 我的合约
|
|
411
427
|
interface ContractParamsType {
|
|
428
|
+
identityType?: 1 | 2;
|
|
429
|
+
licensorName?: string;
|
|
430
|
+
licenseeName?: string;
|
|
412
431
|
}
|
|
413
432
|
|
|
414
|
-
export function contract({}: ContractParamsType = {}) {
|
|
415
|
-
return `/logged/contract
|
|
433
|
+
export function contract({...params}: ContractParamsType = {}) {
|
|
434
|
+
return `/logged/contract${handleQuery({
|
|
435
|
+
...params
|
|
436
|
+
})}`;
|
|
416
437
|
}
|
|
417
438
|
|
|
418
439
|
// 个人设置
|
package/src/utils/tools.ts
CHANGED
|
@@ -1,102 +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.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: string = 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
|
-
}
|
|
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: string = 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
|
+
}
|