cloud189-sdk 1.0.6-alpha.6 → 1.0.8
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/README.md +7 -0
- package/dist/CloudAuthClient.d.ts +41 -0
- package/dist/CloudAuthClient.js +165 -0
- package/dist/CloudClient.d.ts +116 -42
- package/dist/CloudClient.js +514 -219
- package/dist/const.d.ts +1 -0
- package/dist/const.js +2 -1
- package/dist/hook/checkErrorHook.d.ts +2 -0
- package/dist/hook/checkErrorHook.js +9 -0
- package/dist/hook/index.d.ts +3 -0
- package/dist/hook/index.js +7 -0
- package/dist/hook/logHook.d.ts +2 -0
- package/dist/hook/logHook.js +9 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3 -5
- package/dist/log.d.ts +7 -22
- package/dist/log.js +8 -99
- package/dist/signature.d.ts +7 -0
- package/dist/signature.js +55 -0
- package/dist/store/file-token-store.d.ts +1 -0
- package/dist/store/file-token-store.js +11 -0
- package/dist/types.d.ts +333 -1
- package/dist/types.js +23 -0
- package/dist/util.d.ts +14 -1
- package/dist/util.js +96 -5
- package/package.json +10 -6
package/README.md
CHANGED
|
@@ -14,6 +14,9 @@
|
|
|
14
14
|
<a href="https://npmcharts.com/compare/cloud189-sdk?minimal=true">
|
|
15
15
|
<img src="http://img.shields.io/npm/dm/cloud189-sdk.svg">
|
|
16
16
|
</a>
|
|
17
|
+
<a href="https://coveralls.io/github/wes-lin/cloud189-sdk">
|
|
18
|
+
<img src="https://coveralls.io/repos/github/wes-lin/cloud189-sdk/badge.svg?branch=dev">
|
|
19
|
+
</a>
|
|
17
20
|
<a href="LICENSE">
|
|
18
21
|
<img src="https://img.shields.io/badge/License-MIT-yellow.svg">
|
|
19
22
|
</a>
|
|
@@ -46,3 +49,7 @@ console.log(info)
|
|
|
46
49
|
```
|
|
47
50
|
|
|
48
51
|
## [API 文档](https://cloud.189.whaledev.cn/)
|
|
52
|
+
|
|
53
|
+
## Star History
|
|
54
|
+
|
|
55
|
+
[](https://www.star-history.com/#wes-lin/cloud189-sdk&Date)
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Got } from 'got';
|
|
2
|
+
import { RefreshTokenSession, TokenSession, CacheQuery } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export declare class CloudAuthClient {
|
|
7
|
+
#private;
|
|
8
|
+
readonly authRequest: Got;
|
|
9
|
+
constructor();
|
|
10
|
+
/**
|
|
11
|
+
* 获取加密参数
|
|
12
|
+
* @returns
|
|
13
|
+
*/
|
|
14
|
+
getEncrypt(): Promise<{
|
|
15
|
+
data: {
|
|
16
|
+
pubKey: string;
|
|
17
|
+
pre: string;
|
|
18
|
+
};
|
|
19
|
+
}>;
|
|
20
|
+
getLoginForm(): Promise<CacheQuery>;
|
|
21
|
+
getSessionForPC(param: {
|
|
22
|
+
redirectURL?: string;
|
|
23
|
+
accessToken?: string;
|
|
24
|
+
}): Promise<TokenSession>;
|
|
25
|
+
/**
|
|
26
|
+
* 用户名密码登录
|
|
27
|
+
* */
|
|
28
|
+
loginByPassword(username: string, password: string): Promise<TokenSession>;
|
|
29
|
+
/**
|
|
30
|
+
* token登录
|
|
31
|
+
*/
|
|
32
|
+
loginByAccessToken(accessToken: string): Promise<TokenSession>;
|
|
33
|
+
/**
|
|
34
|
+
* sso登录
|
|
35
|
+
*/
|
|
36
|
+
loginBySsoCooike(cookie: string): Promise<TokenSession>;
|
|
37
|
+
/**
|
|
38
|
+
* 刷新token
|
|
39
|
+
*/
|
|
40
|
+
refreshToken(refreshToken: string): Promise<RefreshTokenSession>;
|
|
41
|
+
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
5
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
6
|
+
};
|
|
7
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
8
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
9
|
+
};
|
|
10
|
+
var _CloudAuthClient_builLoginForm;
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.CloudAuthClient = void 0;
|
|
13
|
+
const got_1 = __importDefault(require("got"));
|
|
14
|
+
const log_1 = require("./log");
|
|
15
|
+
const const_1 = require("./const");
|
|
16
|
+
const util_1 = require("./util");
|
|
17
|
+
const hook_1 = require("./hook");
|
|
18
|
+
/**
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
21
|
+
class CloudAuthClient {
|
|
22
|
+
constructor() {
|
|
23
|
+
_CloudAuthClient_builLoginForm.set(this, (encrypt, appConf, username, password) => {
|
|
24
|
+
const usernameEncrypt = (0, util_1.rsaEncrypt)(encrypt.pubKey, username);
|
|
25
|
+
const passwordEncrypt = (0, util_1.rsaEncrypt)(encrypt.pubKey, password);
|
|
26
|
+
const data = {
|
|
27
|
+
appKey: const_1.AppID,
|
|
28
|
+
accountType: const_1.AccountType,
|
|
29
|
+
// mailSuffix: '@189.cn',
|
|
30
|
+
validateCode: '',
|
|
31
|
+
captchaToken: appConf.captchaToken,
|
|
32
|
+
dynamicCheck: 'FALSE',
|
|
33
|
+
clientType: '1',
|
|
34
|
+
cb_SaveName: '3',
|
|
35
|
+
isOauth2: false,
|
|
36
|
+
returnUrl: const_1.ReturnURL,
|
|
37
|
+
paramId: appConf.paramId,
|
|
38
|
+
userName: `${encrypt.pre}${usernameEncrypt}`,
|
|
39
|
+
password: `${encrypt.pre}${passwordEncrypt}`
|
|
40
|
+
};
|
|
41
|
+
return data;
|
|
42
|
+
});
|
|
43
|
+
this.authRequest = got_1.default.extend({
|
|
44
|
+
headers: {
|
|
45
|
+
'User-Agent': const_1.UserAgent,
|
|
46
|
+
Accept: 'application/json;charset=UTF-8'
|
|
47
|
+
},
|
|
48
|
+
hooks: {
|
|
49
|
+
afterResponse: [hook_1.logHook, hook_1.checkErrorHook]
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* 获取加密参数
|
|
55
|
+
* @returns
|
|
56
|
+
*/
|
|
57
|
+
getEncrypt() {
|
|
58
|
+
return this.authRequest.post(`${const_1.AUTH_URL}/api/logbox/config/encryptConf.do`).json();
|
|
59
|
+
}
|
|
60
|
+
async getLoginForm() {
|
|
61
|
+
const res = await this.authRequest
|
|
62
|
+
.get(`${const_1.WEB_URL}/api/portal/unifyLoginForPC.action`, {
|
|
63
|
+
searchParams: {
|
|
64
|
+
appId: const_1.AppID,
|
|
65
|
+
clientType: const_1.ClientType,
|
|
66
|
+
returnURL: const_1.ReturnURL,
|
|
67
|
+
timeStamp: Date.now()
|
|
68
|
+
}
|
|
69
|
+
})
|
|
70
|
+
.text();
|
|
71
|
+
if (res) {
|
|
72
|
+
const captchaToken = res.match(`'captchaToken' value='(.+?)'`)[1];
|
|
73
|
+
const lt = res.match(`lt = "(.+?)"`)[1];
|
|
74
|
+
const paramId = res.match(`paramId = "(.+?)"`)[1];
|
|
75
|
+
const reqId = res.match(`reqId = "(.+?)"`)[1];
|
|
76
|
+
return { captchaToken, lt, paramId, reqId };
|
|
77
|
+
}
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
async getSessionForPC(param) {
|
|
81
|
+
const params = Object.assign(Object.assign({ appId: const_1.AppID }, (0, const_1.clientSuffix)()), param);
|
|
82
|
+
const res = await this.authRequest
|
|
83
|
+
.post(`${const_1.API_URL}/getSessionForPC.action`, {
|
|
84
|
+
searchParams: params
|
|
85
|
+
})
|
|
86
|
+
.json();
|
|
87
|
+
return res;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* 用户名密码登录
|
|
91
|
+
* */
|
|
92
|
+
async loginByPassword(username, password) {
|
|
93
|
+
log_1.logger.debug('loginByPassword...');
|
|
94
|
+
try {
|
|
95
|
+
const res = await Promise.all([
|
|
96
|
+
//1.获取公钥
|
|
97
|
+
this.getEncrypt(),
|
|
98
|
+
//2.获取登录参数
|
|
99
|
+
this.getLoginForm()
|
|
100
|
+
]);
|
|
101
|
+
const encrypt = res[0].data;
|
|
102
|
+
const appConf = res[1];
|
|
103
|
+
const data = __classPrivateFieldGet(this, _CloudAuthClient_builLoginForm, "f").call(this, encrypt, appConf, username, password);
|
|
104
|
+
const loginRes = await this.authRequest
|
|
105
|
+
.post(`${const_1.AUTH_URL}/api/logbox/oauth2/loginSubmit.do`, {
|
|
106
|
+
headers: {
|
|
107
|
+
Referer: const_1.AUTH_URL,
|
|
108
|
+
lt: appConf.lt,
|
|
109
|
+
REQID: appConf.reqId
|
|
110
|
+
},
|
|
111
|
+
form: data
|
|
112
|
+
})
|
|
113
|
+
.json();
|
|
114
|
+
return await this.getSessionForPC({ redirectURL: loginRes.toUrl });
|
|
115
|
+
}
|
|
116
|
+
catch (e) {
|
|
117
|
+
log_1.logger.error(e);
|
|
118
|
+
throw e;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* token登录
|
|
123
|
+
*/
|
|
124
|
+
async loginByAccessToken(accessToken) {
|
|
125
|
+
log_1.logger.debug('loginByAccessToken...');
|
|
126
|
+
return await this.getSessionForPC({ accessToken });
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* sso登录
|
|
130
|
+
*/
|
|
131
|
+
async loginBySsoCooike(cookie) {
|
|
132
|
+
log_1.logger.debug('loginBySsoCooike...');
|
|
133
|
+
const res = await this.authRequest.get(`${const_1.WEB_URL}/api/portal/unifyLoginForPC.action`, {
|
|
134
|
+
searchParams: {
|
|
135
|
+
appId: const_1.AppID,
|
|
136
|
+
clientType: const_1.ClientType,
|
|
137
|
+
returnURL: const_1.ReturnURL,
|
|
138
|
+
timeStamp: Date.now()
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
const redirect = await this.authRequest(res.url, {
|
|
142
|
+
headers: {
|
|
143
|
+
Cookie: `SSON=${cookie}`
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
return await this.getSessionForPC({ redirectURL: redirect.url });
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* 刷新token
|
|
150
|
+
*/
|
|
151
|
+
refreshToken(refreshToken) {
|
|
152
|
+
return this.authRequest
|
|
153
|
+
.post(`${const_1.AUTH_URL}/api/oauth2/refreshToken.do`, {
|
|
154
|
+
form: {
|
|
155
|
+
clientId: const_1.AppID,
|
|
156
|
+
refreshToken,
|
|
157
|
+
grantType: 'refresh_token',
|
|
158
|
+
format: 'json'
|
|
159
|
+
}
|
|
160
|
+
})
|
|
161
|
+
.json();
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
exports.CloudAuthClient = CloudAuthClient;
|
|
165
|
+
_CloudAuthClient_builLoginForm = new WeakMap();
|
package/dist/CloudClient.d.ts
CHANGED
|
@@ -1,45 +1,7 @@
|
|
|
1
1
|
import { Got } from 'got';
|
|
2
|
-
import { UserSignResponse, UserSizeInfoResponse, FamilyListResponse, FamilyUserSignResponse, ConfigurationOptions, ClientSession,
|
|
2
|
+
import { UserSignResponse, UserSizeInfoResponse, FamilyListResponse, FamilyUserSignResponse, ConfigurationOptions, ClientSession, PageQuery, FileListResponse, RsaKey, UploadInitResponse, UploadCommitResponse, CreateFolderRequest, UploadCallbacks, RenameFolderRequest, CreateBatchTaskRequest, CreateFamilyBatchTaskRequest, CreateFamilyFolderRequest, RenameFamilyFolderRequest, CommitMultiFamilyUploadRequest, CommitMultiUploadRequest, initMultiUploadRequest, initMultiFamilyUploadRequest } from './types';
|
|
3
|
+
import { CloudAuthClient } from './CloudAuthClient';
|
|
3
4
|
import { Store } from './store';
|
|
4
|
-
/**
|
|
5
|
-
* @public
|
|
6
|
-
*/
|
|
7
|
-
export declare class CloudAuthClient {
|
|
8
|
-
#private;
|
|
9
|
-
readonly request: Got;
|
|
10
|
-
constructor();
|
|
11
|
-
/**
|
|
12
|
-
* 获取加密参数
|
|
13
|
-
* @returns
|
|
14
|
-
*/
|
|
15
|
-
getEncrypt(): Promise<{
|
|
16
|
-
data: {
|
|
17
|
-
pubKey: string;
|
|
18
|
-
pre: string;
|
|
19
|
-
};
|
|
20
|
-
}>;
|
|
21
|
-
getLoginForm(): Promise<CacheQuery>;
|
|
22
|
-
getSessionForPC(param: {
|
|
23
|
-
redirectURL?: string;
|
|
24
|
-
accessToken?: string;
|
|
25
|
-
}): Promise<TokenSession>;
|
|
26
|
-
/**
|
|
27
|
-
* 用户名密码登录
|
|
28
|
-
* */
|
|
29
|
-
loginByPassword(username: string, password: string): Promise<TokenSession>;
|
|
30
|
-
/**
|
|
31
|
-
* token登录
|
|
32
|
-
*/
|
|
33
|
-
loginByAccessToken(accessToken: string): Promise<TokenSession>;
|
|
34
|
-
/**
|
|
35
|
-
* sso登录
|
|
36
|
-
*/
|
|
37
|
-
loginBySsoCooike(cookie: string): Promise<TokenSession>;
|
|
38
|
-
/**
|
|
39
|
-
* 刷新token
|
|
40
|
-
*/
|
|
41
|
-
refreshToken(refreshToken: string): Promise<RefreshTokenSession>;
|
|
42
|
-
}
|
|
43
5
|
/**
|
|
44
6
|
* 天翼网盘客户端
|
|
45
7
|
* @public
|
|
@@ -53,8 +15,12 @@ export declare class CloudClient {
|
|
|
53
15
|
readonly request: Got;
|
|
54
16
|
readonly authClient: CloudAuthClient;
|
|
55
17
|
readonly session: ClientSession;
|
|
18
|
+
private rsaKey;
|
|
19
|
+
private sessionKeyPromise;
|
|
20
|
+
private accessTokenPromise;
|
|
21
|
+
private generateRsaKeyPromise;
|
|
56
22
|
constructor(_options: ConfigurationOptions);
|
|
57
|
-
getSession(): Promise<TokenSession>;
|
|
23
|
+
getSession(): Promise<import("./types").TokenSession>;
|
|
58
24
|
/**
|
|
59
25
|
* 获取 sessionKey
|
|
60
26
|
* @returns sessionKey
|
|
@@ -65,6 +31,11 @@ export declare class CloudClient {
|
|
|
65
31
|
* @returns accessToken
|
|
66
32
|
*/
|
|
67
33
|
getAccessToken(): Promise<string>;
|
|
34
|
+
/**
|
|
35
|
+
* 获取 RSA key
|
|
36
|
+
* @returns RSAKey
|
|
37
|
+
*/
|
|
38
|
+
generateRsaKey(): Promise<RsaKey>;
|
|
68
39
|
/**
|
|
69
40
|
* 获取用户网盘存储容量信息
|
|
70
41
|
* @returns 账号容量结果
|
|
@@ -84,6 +55,109 @@ export declare class CloudClient {
|
|
|
84
55
|
* 家庭签到任务
|
|
85
56
|
* @param familyId - 家庭id
|
|
86
57
|
* @returns 签到结果
|
|
58
|
+
* @deprecated 已无效
|
|
59
|
+
*/
|
|
60
|
+
familyUserSign(familyId: string): Promise<FamilyUserSignResponse>;
|
|
61
|
+
/**
|
|
62
|
+
* 获取文件列表
|
|
63
|
+
* @param pageQuery - 查询参数
|
|
64
|
+
* @returns
|
|
65
|
+
*/
|
|
66
|
+
getListFiles(pageQuery?: PageQuery, familyId?: string): Promise<FileListResponse>;
|
|
67
|
+
/**
|
|
68
|
+
* 创建文件夹
|
|
69
|
+
* @param createFolderRequest - 创建文件夹请求
|
|
70
|
+
* @returns
|
|
71
|
+
*/
|
|
72
|
+
createFolder(createFolderRequest: CreateFolderRequest | CreateFamilyFolderRequest): Promise<{
|
|
73
|
+
id: string;
|
|
74
|
+
name: string;
|
|
75
|
+
parentId: string;
|
|
76
|
+
}>;
|
|
77
|
+
/**
|
|
78
|
+
* 重命名文件夹
|
|
79
|
+
* @param renameFolderRequest - 重名文件夹请求
|
|
80
|
+
* @returns
|
|
81
|
+
*/
|
|
82
|
+
renameFolder(renameFolderRequest: RenameFolderRequest | RenameFamilyFolderRequest): import("got").CancelableRequest<unknown>;
|
|
83
|
+
/**
|
|
84
|
+
* 初始化上传
|
|
85
|
+
* @param initMultiUploadRequest - 初始化请求
|
|
86
|
+
* @returns
|
|
87
|
+
*/
|
|
88
|
+
initMultiUpload(initMultiUploadRequest: initMultiUploadRequest | initMultiFamilyUploadRequest): Promise<UploadInitResponse>;
|
|
89
|
+
/**
|
|
90
|
+
* 提交上传
|
|
91
|
+
* @param commitMultiUploadRequest - 提交请求
|
|
92
|
+
* @returns
|
|
93
|
+
*/
|
|
94
|
+
commitMultiUpload(commitMultiUploadRequest: CommitMultiUploadRequest | CommitMultiFamilyUploadRequest): import("got").CancelableRequest<UploadCommitResponse>;
|
|
95
|
+
/**
|
|
96
|
+
* 检测秒传
|
|
97
|
+
* @param params - 检查参数
|
|
98
|
+
* @returns
|
|
99
|
+
*/
|
|
100
|
+
checkTransSecond(params: {
|
|
101
|
+
fileMd5: string;
|
|
102
|
+
sliceMd5: string;
|
|
103
|
+
uploadFileId: string;
|
|
104
|
+
familyId?: number;
|
|
105
|
+
}): import("got").CancelableRequest<UploadInitResponse>;
|
|
106
|
+
/**
|
|
107
|
+
* 文件上传
|
|
108
|
+
* @param param - 上传参数
|
|
109
|
+
* @param callbacks - 上传回调
|
|
110
|
+
* @returns
|
|
87
111
|
*/
|
|
88
|
-
|
|
112
|
+
upload(param: {
|
|
113
|
+
parentFolderId: string;
|
|
114
|
+
filePath: string;
|
|
115
|
+
familyId?: string;
|
|
116
|
+
}, callbacks?: UploadCallbacks): Promise<{
|
|
117
|
+
fileDataExists: number;
|
|
118
|
+
file: {
|
|
119
|
+
userFileId: string;
|
|
120
|
+
fileName: string;
|
|
121
|
+
fileSize: number;
|
|
122
|
+
fileMd5: string;
|
|
123
|
+
createDate: string;
|
|
124
|
+
rev: number;
|
|
125
|
+
userId: number;
|
|
126
|
+
};
|
|
127
|
+
code: string;
|
|
128
|
+
}>;
|
|
129
|
+
/**
|
|
130
|
+
* 检测任务状态
|
|
131
|
+
* @param type - 任务类型
|
|
132
|
+
* @param taskId - 任务Id
|
|
133
|
+
* @param maxAttempts - 重试次数
|
|
134
|
+
* @param interval - 重试间隔
|
|
135
|
+
* @returns
|
|
136
|
+
*/
|
|
137
|
+
checkTaskStatus(type: string, taskId: string, maxAttempts?: number, interval?: number): Promise<{
|
|
138
|
+
successedFileIdList?: number[];
|
|
139
|
+
taskId: string;
|
|
140
|
+
taskStatus: number;
|
|
141
|
+
}>;
|
|
142
|
+
/**
|
|
143
|
+
* 创建任务
|
|
144
|
+
* @param createBatchTaskRequest - 创建任务参数
|
|
145
|
+
* @returns
|
|
146
|
+
*/
|
|
147
|
+
createBatchTask(createBatchTaskRequest: CreateBatchTaskRequest | CreateFamilyBatchTaskRequest): Promise<{
|
|
148
|
+
successedFileIdList?: number[];
|
|
149
|
+
taskId: string;
|
|
150
|
+
taskStatus: number;
|
|
151
|
+
}>;
|
|
152
|
+
/**
|
|
153
|
+
* 获取文件下载路径
|
|
154
|
+
* @param params - 文件参数
|
|
155
|
+
* @returns
|
|
156
|
+
*/
|
|
157
|
+
getFileDownloadUrl(params: {
|
|
158
|
+
fileId: string;
|
|
159
|
+
familyId?: string;
|
|
160
|
+
}): import("got").CancelableRequest<{
|
|
161
|
+
fileDownloadUrl: string;
|
|
162
|
+
}>;
|
|
89
163
|
}
|