cloud189-sdk 1.0.8 → 1.0.9-beta.0
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/package.json +1 -1
- package/dist/CloudAuthClient.d.ts +0 -41
- package/dist/CloudAuthClient.js +0 -165
- package/dist/CloudClient.d.ts +0 -163
- package/dist/CloudClient.js +0 -701
- package/dist/const.d.ts +0 -15
- package/dist/const.js +0 -20
- package/dist/error.d.ts +0 -5
- package/dist/error.js +0 -30
- package/dist/hook/checkErrorHook.d.ts +0 -2
- package/dist/hook/checkErrorHook.js +0 -9
- package/dist/hook/index.d.ts +0 -3
- package/dist/hook/index.js +0 -7
- package/dist/hook/logHook.d.ts +0 -2
- package/dist/hook/logHook.js +0 -9
- package/dist/index.d.ts +0 -5
- package/dist/index.js +0 -21
- package/dist/log.d.ts +0 -7
- package/dist/log.js +0 -10
- package/dist/signature.d.ts +0 -7
- package/dist/signature.js +0 -55
- package/dist/store/file-token-store.d.ts +0 -15
- package/dist/store/file-token-store.js +0 -89
- package/dist/store/index.d.ts +0 -3
- package/dist/store/index.js +0 -19
- package/dist/store/memstore.d.ts +0 -22
- package/dist/store/memstore.js +0 -29
- package/dist/store/store.d.ts +0 -20
- package/dist/store/store.js +0 -10
- package/dist/types.d.ts +0 -510
- package/dist/types.js +0 -25
- package/dist/util.d.ts +0 -15
- package/dist/util.js +0 -119
package/package.json
CHANGED
|
@@ -1,41 +0,0 @@
|
|
|
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
|
-
}
|
package/dist/CloudAuthClient.js
DELETED
|
@@ -1,165 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
import { Got } from 'got';
|
|
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';
|
|
4
|
-
import { Store } from './store';
|
|
5
|
-
/**
|
|
6
|
-
* 天翼网盘客户端
|
|
7
|
-
* @public
|
|
8
|
-
*/
|
|
9
|
-
export declare class CloudClient {
|
|
10
|
-
#private;
|
|
11
|
-
username: string;
|
|
12
|
-
password: string;
|
|
13
|
-
ssonCookie: string;
|
|
14
|
-
tokenStore: Store;
|
|
15
|
-
readonly request: Got;
|
|
16
|
-
readonly authClient: CloudAuthClient;
|
|
17
|
-
readonly session: ClientSession;
|
|
18
|
-
private rsaKey;
|
|
19
|
-
private sessionKeyPromise;
|
|
20
|
-
private accessTokenPromise;
|
|
21
|
-
private generateRsaKeyPromise;
|
|
22
|
-
constructor(_options: ConfigurationOptions);
|
|
23
|
-
getSession(): Promise<import("./types").TokenSession>;
|
|
24
|
-
/**
|
|
25
|
-
* 获取 sessionKey
|
|
26
|
-
* @returns sessionKey
|
|
27
|
-
*/
|
|
28
|
-
getSessionKey(): Promise<string>;
|
|
29
|
-
/**
|
|
30
|
-
* 获取 accessToken
|
|
31
|
-
* @returns accessToken
|
|
32
|
-
*/
|
|
33
|
-
getAccessToken(): Promise<string>;
|
|
34
|
-
/**
|
|
35
|
-
* 获取 RSA key
|
|
36
|
-
* @returns RSAKey
|
|
37
|
-
*/
|
|
38
|
-
generateRsaKey(): Promise<RsaKey>;
|
|
39
|
-
/**
|
|
40
|
-
* 获取用户网盘存储容量信息
|
|
41
|
-
* @returns 账号容量结果
|
|
42
|
-
*/
|
|
43
|
-
getUserSizeInfo(): Promise<UserSizeInfoResponse>;
|
|
44
|
-
/**
|
|
45
|
-
* 个人签到任务
|
|
46
|
-
* @returns 签到结果
|
|
47
|
-
*/
|
|
48
|
-
userSign(): Promise<UserSignResponse>;
|
|
49
|
-
/**
|
|
50
|
-
* 获取家庭信息
|
|
51
|
-
* @returns 家庭列表信息
|
|
52
|
-
*/
|
|
53
|
-
getFamilyList(): Promise<FamilyListResponse>;
|
|
54
|
-
/**
|
|
55
|
-
* 家庭签到任务
|
|
56
|
-
* @param familyId - 家庭id
|
|
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
|
|
111
|
-
*/
|
|
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
|
-
}>;
|
|
163
|
-
}
|