cloud189-sdk 1.0.4 → 1.0.6-alpha.1

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 CHANGED
@@ -1,50 +1,51 @@
1
1
  # cloud189-sdk
2
2
 
3
- ## 安装依赖
4
- ``` console
5
- npm i cloud189-sdk
3
+ > 基于node.js的天翼网盘sdk
4
+
5
+ <div align="center">
6
+ <a href="https://github.com/wes-lin/cloud189-sdk/actions/workflows/publish.yml">
7
+ <img src="https://github.com/wes-lin/cloud189-sdk/actions/workflows/publish.yml/badge.svg">
8
+ </a>
9
+ <a href="https://www.npmjs.org/package/cloud189-sdk">
10
+ <img src="https://img.shields.io/npm/v/cloud189-sdk.svg">
11
+ </a>
12
+ <a href="https://packagephobia.com/result?p=cloud189-sdk">
13
+ <img src="https://packagephobia.com/badge?p=cloud189-sdk">
14
+ </a>
15
+ <a href="https://npmcharts.com/compare/cloud189-sdk?minimal=true">
16
+ <img src="http://img.shields.io/npm/dm/cloud189-sdk.svg">
17
+ </a>
18
+ <a href="LICENSE">
19
+ <img src="https://img.shields.io/badge/License-MIT-yellow.svg">
20
+ </a>
21
+ </div>
22
+
23
+ ## 使用方法
24
+
25
+ 1. 安装依赖
26
+
27
+ ```sh
28
+ npm install cloud189-sdk
6
29
  ```
7
- 或者
8
- ``` console
9
- yarn add cloud189-sdk
30
+
31
+ 2. 初始化
32
+
33
+ ```js
34
+ const { CloudClient } = require('cloud189-sdk')
35
+ // 使用账号密码初始化
36
+ const client = new CloudClient({
37
+ username: 'username',
38
+ password: 'password'
39
+ })
40
+
10
41
  ```
11
- ## 测试代码
12
- ``` javascript
13
- const { CloudClient } = require("cloud189-sdk");
14
-
15
- const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
16
- (async () => {
17
- const client = new CloudClient(
18
- 'your username',
19
- 'your password'
20
- );
21
- await client.login();
22
- const t1 = await client.userSign();
23
- console.log(t1);
24
- await delay(5000);
25
- const t2 = await client.taskSign();
26
- console.log(t2);
27
- await delay(5000);
28
- const t3 = await client.taskPhoto();
29
- console.log(t3);
30
- await delay(5000);
31
- const t4 = await client.taskKJ();
32
- await delay(5000);
33
- console.log(t4);
34
- const { familyInfoResp } = await client.getFamilyList();
35
- console.log(familyInfoResp);
36
- if (familyInfoResp) {
37
- for (let index = 0; index < familyInfoResp.length; index += 1) {
38
- const { familyId } = familyInfoResp[index];
39
- try {
40
- const res = await client.familyUserSign(familyId);
41
- console.log(res);
42
- } catch (e) {
43
- console.error(e);
44
- }
45
- }
46
- }
47
- const info = await client.getUserSizeInfo();
48
- console.log(info);
49
- })();
42
+
43
+ 3. 使用
44
+
45
+ ```js
46
+ const info = await client.getUserSizeInfo()
47
+ console.log(info)
48
+
50
49
  ```
50
+
51
+ ## [API 文档](https://cloud.189.whaledev.cn/)
@@ -1,92 +1,87 @@
1
- interface CacheQuery {
2
- appId: string;
3
- reqId: string;
4
- lt: string;
5
- }
6
- interface FamilyListResponse {
7
- familyInfoResp: [
8
- {
9
- familyId: number;
10
- remarkName: string;
11
- type: number;
12
- userRole: number;
13
- }
14
- ];
15
- }
16
- interface UserBriefInfoResponse {
17
- sessionKey: string;
18
- }
19
- interface AccessTokenResponse {
20
- accessToken: string;
21
- }
22
- interface FamilyUserSignResponse {
23
- bonusSpace: number;
24
- signFamilyId: number;
25
- signStatus: number;
26
- signTime: string;
27
- userId: string;
28
- }
29
- interface UserSizeInfoResponse {
30
- cloudCapacityInfo: {
31
- totalSize: number;
32
- };
33
- familyCapacityInfo: {
34
- totalSize: number;
35
- };
36
- }
37
- interface UserSignResponse {
38
- isSign: boolean;
39
- netdiskBonus: number;
40
- }
41
- interface TaskResponse {
42
- errorCode: string;
43
- prizeName: string;
44
- }
45
- interface UserSizeInfoResponse {
46
- account: string;
47
- cloudCapacityInfo: {
48
- totalSize: number;
49
- };
50
- familyCapacityInfo: {
51
- totalSize: number;
52
- };
53
- }
54
- declare class CloudClient {
55
- #private;
56
- username: string;
57
- password: string;
58
- cacheQuery: CacheQuery;
59
- constructor(username: string, password: string);
60
- getEncrypt: () => Promise<any>;
61
- redirectURL: () => Promise<unknown>;
62
- appConf: (query: CacheQuery) => Promise<any>;
63
- /**
64
- * 登录流程
65
- * 1.获取公钥
66
- * 2.获取登录参数
67
- * 3.获取登录地址
68
- * 4.跳转到登录页
69
- * */
70
- login: () => Promise<any>;
71
- fetchAPI: (task: string) => Promise<any>;
72
- getUserSizeInfo: () => Promise<UserSizeInfoResponse>;
73
- userSign: () => Promise<UserSignResponse>;
74
- /**
75
- * @deprecated 任务无效, 1.0.4版本废弃
76
- */
77
- taskSign: () => Promise<TaskResponse>;
78
- /**
79
- * @deprecated 任务无效, 1.0.4版本废弃
80
- */
81
- taskPhoto: () => Promise<TaskResponse>;
82
- /**
83
- * @deprecated 任务无效, 1.0.3版本废弃
84
- */
85
- taskKJ: () => Promise<TaskResponse>;
86
- getUserBriefInfo: () => Promise<UserBriefInfoResponse>;
87
- getAccessTokenBySsKey: (sessionKey: string) => Promise<AccessTokenResponse>;
88
- fetchFamilyAPI: (path: string) => Promise<any>;
89
- getFamilyList: () => Promise<FamilyListResponse>;
90
- familyUserSign: (familyId: number) => Promise<FamilyUserSignResponse>;
91
- }
92
- export default CloudClient;
1
+ import { Got } from 'got';
2
+ import { CookieJar } from 'tough-cookie';
3
+ import { UserSignResponse, UserSizeInfoResponse, UserTaskResponse, FamilyListResponse, FamilyUserSignResponse, ConfigurationOptions } from './types';
4
+ /**
5
+ * 天翼网盘客户端
6
+ * @public
7
+ */
8
+ export default class CloudClient {
9
+ #private;
10
+ username: string;
11
+ password: string;
12
+ cookie: CookieJar;
13
+ readonly request: Got;
14
+ constructor(_options: ConfigurationOptions);
15
+ /**
16
+ * 获取加密参数
17
+ * @returns
18
+ */
19
+ getEncrypt(): Promise<{
20
+ data: {
21
+ pubKey: string;
22
+ pre: string;
23
+ };
24
+ }>;
25
+ /**
26
+ * 跳转到登录页面
27
+ * @returns 登录的参数
28
+ */
29
+ redirectURL(): Promise<any>;
30
+ /**
31
+ * 用户名密码登录
32
+ * */
33
+ login(): Promise<any>;
34
+ /**
35
+ * 是否存在登录信息
36
+ * @returns
37
+ */
38
+ isLoggedSession(): boolean;
39
+ /**
40
+ * 获取 sessionKey
41
+ * @param needRefresh - 是否重新获取
42
+ * @returns sessionKey
43
+ */
44
+ getSessionKey(needRefresh?: boolean): Promise<string>;
45
+ /**
46
+ * 获取 accessToken
47
+ * @param needRefresh - 是否重新获取
48
+ * @returns accessToken
49
+ */
50
+ getAccessToken(needRefresh?: boolean): Promise<string>;
51
+ /**
52
+ * 获取用户网盘存储容量信息
53
+ * @returns 账号容量结果
54
+ */
55
+ getUserSizeInfo(): Promise<UserSizeInfoResponse>;
56
+ /**
57
+ * 个人签到任务
58
+ * @returns 签到结果
59
+ */
60
+ userSign(): Promise<UserSignResponse>;
61
+ /**
62
+ * 任务无效, 1.0.4版本废弃
63
+ * @deprecated 任务过期
64
+ */
65
+ taskSign(): Promise<UserTaskResponse>;
66
+ /**
67
+ * 任务无效, 1.0.4版本废弃
68
+ * @deprecated 任务过期
69
+ */
70
+ taskPhoto(): Promise<UserTaskResponse>;
71
+ /**
72
+ * 任务无效, 1.0.3版本废弃
73
+ * @deprecated 任务过期
74
+ */
75
+ taskKJ(): Promise<UserTaskResponse>;
76
+ /**
77
+ * 获取家庭信息
78
+ * @returns 家庭列表信息
79
+ */
80
+ getFamilyList(): Promise<FamilyListResponse>;
81
+ /**
82
+ * 家庭签到任务
83
+ * @param familyId - 家庭id
84
+ * @returns 签到结果
85
+ */
86
+ familyUserSign(familyId: number): Promise<FamilyUserSignResponse>;
87
+ }
@@ -1,239 +1,354 @@
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 __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
8
- if (kind === "m") throw new TypeError("Private method is not writable");
9
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
10
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
11
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
12
- };
13
- var __importDefault = (this && this.__importDefault) || function (mod) {
14
- return (mod && mod.__esModule) ? mod : { "default": mod };
15
- };
16
- var _CloudClient_accessToken, _CloudClient_builLoginForm, _CloudClient_sortParameter, _CloudClient_getSignature;
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- const url_1 = __importDefault(require("url"));
19
- const node_jsencrypt_1 = __importDefault(require("node-jsencrypt"));
20
- const crypto_1 = __importDefault(require("crypto"));
21
- const got_1 = __importDefault(require("got"));
22
- const tough_cookie_1 = require("tough-cookie");
23
- const cookieJar = new tough_cookie_1.CookieJar();
24
- const config = {
25
- clientId: "538135150693412",
26
- model: "KB2000",
27
- version: "9.0.6",
28
- };
29
- const headers = {
30
- "User-Agent": `Mozilla/5.0 (Linux; U; Android 11; ${config.model} Build/RP1A.201005.001) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/74.0.3729.136 Mobile Safari/537.36 Ecloud/${config.version} Android/30 clientId/${config.clientId} clientModel/${config.model} clientChannelId/qq proVersion/1.0.6`,
31
- Referer: "https://m.cloud.189.cn/zhuanti/2016/sign/index.jsp?albumBackupOpened=1",
32
- "Accept-Encoding": "gzip, deflate",
33
- Host: "cloud.189.cn",
34
- };
35
- class CloudClient {
36
- constructor(username, password) {
37
- _CloudClient_accessToken.set(this, "");
38
- this.getEncrypt = () => got_1.default.post("https://open.e.189.cn/api/logbox/config/encryptConf.do").json();
39
- this.redirectURL = () => new Promise((resolve, reject) => {
40
- got_1.default
41
- .get("https://cloud.189.cn/api/portal/loginUrl.action?redirectURL=https://cloud.189.cn/web/redirect.html?returnURL=/main.action")
42
- .then((res) => {
43
- const { query } = url_1.default.parse(res.url, true);
44
- resolve(query);
45
- })
46
- .catch((e) => reject(e));
47
- });
48
- this.appConf = (query) => got_1.default
49
- .post("https://open.e.189.cn/api/logbox/oauth2/appConf.do", {
50
- headers: {
51
- "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:74.0) Gecko/20100101 Firefox/76.0",
52
- Referer: "https://open.e.189.cn/",
53
- lt: query.lt,
54
- REQID: query.reqId,
55
- },
56
- form: { version: "2.0", appKey: query.appId },
57
- })
58
- .json();
59
- _CloudClient_builLoginForm.set(this, (encrypt, appConf) => {
60
- const jsencrypt = new node_jsencrypt_1.default();
61
- const keyData = `-----BEGIN PUBLIC KEY-----\n${encrypt.pubKey}\n-----END PUBLIC KEY-----`;
62
- jsencrypt.setPublicKey(keyData);
63
- const usernameEncrypt = Buffer.from(jsencrypt.encrypt(this.username), "base64").toString("hex");
64
- const passwordEncrypt = Buffer.from(jsencrypt.encrypt(this.password), "base64").toString("hex");
65
- const data = {
66
- appKey: "cloud",
67
- version: "2.0",
68
- accountType: "01",
69
- mailSuffix: "@189.cn",
70
- validateCode: "",
71
- captchaToken: "",
72
- dynamicCheck: "FALSE",
73
- clientType: "1",
74
- cb_SaveName: "0",
75
- isOauth2: false,
76
- returnUrl: appConf.returnUrl,
77
- paramId: appConf.paramId,
78
- userName: `${encrypt.pre}${usernameEncrypt}`,
79
- password: `${encrypt.pre}${passwordEncrypt}`,
80
- };
81
- return data;
82
- });
83
- _CloudClient_sortParameter.set(this, (data) => {
84
- if (!data) {
85
- return "";
86
- }
87
- const e = Object.entries(data).map((t) => t.join("="));
88
- e.sort((a, b) => (a > b ? 1 : a < b ? -1 : 0));
89
- return e.join("&");
90
- });
91
- _CloudClient_getSignature.set(this, (data) => {
92
- const parameter = __classPrivateFieldGet(this, _CloudClient_sortParameter, "f").call(this, data);
93
- return crypto_1.default.createHash("md5").update(parameter).digest("hex");
94
- });
95
- /**
96
- * 登录流程
97
- * 1.获取公钥
98
- * 2.获取登录参数
99
- * 3.获取登录地址
100
- * 4.跳转到登录页
101
- * */
102
- this.login = () => new Promise((resolve, reject) => {
103
- Promise.all([
104
- //1.获取公钥
105
- this.getEncrypt(),
106
- //2.获取登录参数
107
- this.redirectURL().then((query) => {
108
- this.cacheQuery = query;
109
- return this.appConf(query);
110
- }),
111
- ])
112
- .then((res) => {
113
- const encrypt = res[0].data;
114
- const appConf = res[1].data;
115
- const data = __classPrivateFieldGet(this, _CloudClient_builLoginForm, "f").call(this, encrypt, appConf);
116
- //3.获取登录地址
117
- return got_1.default
118
- .post("https://open.e.189.cn/api/logbox/oauth2/loginSubmit.do", {
119
- headers: {
120
- "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:74.0) Gecko/20100101 Firefox/76.0",
121
- Referer: "https://open.e.189.cn/",
122
- REQID: this.cacheQuery.reqId,
123
- lt: this.cacheQuery.lt,
124
- },
125
- form: data,
126
- })
127
- .json();
128
- })
129
- .then((res) => {
130
- // 4.跳转到登录页
131
- if (res.result !== 0) {
132
- reject(res.msg);
133
- }
134
- else {
135
- return got_1.default
136
- .get(res.toUrl, { headers, cookieJar })
137
- .then((r) => resolve(r.statusCode));
138
- }
139
- })
140
- .catch((e) => reject(e));
141
- });
142
- this.fetchAPI = (task) => {
143
- const q = url_1.default.parse(task, true);
144
- return got_1.default
145
- .get(task, {
146
- headers: Object.assign(Object.assign({}, headers), { Host: q.host }),
147
- cookieJar,
148
- })
149
- .json();
150
- };
151
- this.getUserSizeInfo = () => {
152
- return got_1.default
153
- .get("https://cloud.189.cn/api/portal/getUserSizeInfo.action", {
154
- headers: {
155
- Accept: "application/json;charset=UTF-8",
156
- },
157
- cookieJar,
158
- })
159
- .json();
160
- };
161
- this.userSign = () => {
162
- return this.fetchAPI(`https://cloud.189.cn/mkt/userSign.action?rand=${new Date().getTime()}&clientType=TELEANDROID&version=${config.version}&model=${config.model}`);
163
- };
164
- /**
165
- * @deprecated 任务无效, 1.0.4版本废弃
166
- */
167
- this.taskSign = () => {
168
- return this.fetchAPI("https://m.cloud.189.cn/v2/drawPrizeMarketDetails.action?taskId=TASK_SIGNIN&activityId=ACT_SIGNIN");
169
- };
170
- /**
171
- * @deprecated 任务无效, 1.0.4版本废弃
172
- */
173
- this.taskPhoto = () => {
174
- return this.fetchAPI("https://m.cloud.189.cn/v2/drawPrizeMarketDetails.action?taskId=TASK_SIGNIN_PHOTOS&activityId=ACT_SIGNIN");
175
- };
176
- /**
177
- * @deprecated 任务无效, 1.0.3版本废弃
178
- */
179
- this.taskKJ = () => {
180
- return this.fetchAPI("https://m.cloud.189.cn/v2/drawPrizeMarketDetails.action?taskId=TASK_2022_FLDFS_KJ&activityId=ACT_SIGNIN");
181
- };
182
- this.getUserBriefInfo = () => got_1.default
183
- .get("https://cloud.189.cn/api/portal/v2/getUserBriefInfo.action", {
184
- cookieJar,
185
- })
186
- .json();
187
- this.getAccessTokenBySsKey = (sessionKey) => {
188
- const appkey = "600100422";
189
- const time = String(Date.now());
190
- const signature = __classPrivateFieldGet(this, _CloudClient_getSignature, "f").call(this, {
191
- sessionKey,
192
- Timestamp: time,
193
- AppKey: appkey,
194
- });
195
- return got_1.default
196
- .get(`https://cloud.189.cn/api/open/oauth2/getAccessTokenBySsKey.action?sessionKey=${sessionKey}`, {
197
- headers: {
198
- "Sign-Type": "1",
199
- Signature: signature,
200
- Timestamp: time,
201
- Appkey: appkey,
202
- },
203
- cookieJar,
204
- })
205
- .json();
206
- };
207
- this.fetchFamilyAPI = async (path) => {
208
- const { query } = url_1.default.parse(path, true);
209
- const time = String(Date.now());
210
- if (!__classPrivateFieldGet(this, _CloudClient_accessToken, "f")) {
211
- const { sessionKey } = await this.getUserBriefInfo();
212
- const { accessToken } = await this.getAccessTokenBySsKey(sessionKey);
213
- __classPrivateFieldSet(this, _CloudClient_accessToken, accessToken, "f");
214
- }
215
- const signature = __classPrivateFieldGet(this, _CloudClient_getSignature, "f").call(this, Object.assign(Object.assign({}, query), { Timestamp: time, AccessToken: __classPrivateFieldGet(this, _CloudClient_accessToken, "f") }));
216
- return got_1.default
217
- .get(path, {
218
- headers: {
219
- "Sign-Type": "1",
220
- Signature: signature,
221
- Timestamp: time,
222
- Accesstoken: __classPrivateFieldGet(this, _CloudClient_accessToken, "f"),
223
- Accept: "application/json;charset=UTF-8",
224
- },
225
- cookieJar,
226
- })
227
- .json();
228
- };
229
- this.getFamilyList = () => this.fetchFamilyAPI("https://api.cloud.189.cn/open/family/manage/getFamilyList.action");
230
- this.familyUserSign = (familyId) => {
231
- const gturl = `https://api.cloud.189.cn/open/family/manage/exeFamilyUserSign.action?familyId=${familyId}`;
232
- return this.fetchFamilyAPI(gturl);
233
- };
234
- this.username = username;
235
- this.password = password;
236
- }
237
- }
238
- _CloudClient_accessToken = new WeakMap(), _CloudClient_builLoginForm = new WeakMap(), _CloudClient_sortParameter = new WeakMap(), _CloudClient_getSignature = new WeakMap();
239
- exports.default = CloudClient;
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 __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
8
+ if (kind === "m") throw new TypeError("Private method is not writable");
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
10
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
11
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
12
+ };
13
+ var __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
16
+ var _CloudClient_instances, _CloudClient_accessToken, _CloudClient_sessionKey, _CloudClient_cacheQuery, _CloudClient_valid, _CloudClient_appConf, _CloudClient_builLoginForm, _CloudClient_getUserBriefInfo, _CloudClient_getAccessTokenBySsKey;
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ const url_1 = __importDefault(require("url"));
19
+ const node_jsencrypt_1 = __importDefault(require("node-jsencrypt"));
20
+ const got_1 = __importDefault(require("got"));
21
+ const tough_cookie_1 = require("tough-cookie");
22
+ const log_1 = require("./log");
23
+ const util_1 = require("./util");
24
+ const config = {
25
+ clientId: '538135150693412',
26
+ model: 'KB2000',
27
+ version: '9.0.6'
28
+ };
29
+ /**
30
+ * 天翼网盘客户端
31
+ * @public
32
+ */
33
+ class CloudClient {
34
+ constructor(_options) {
35
+ _CloudClient_instances.add(this);
36
+ _CloudClient_accessToken.set(this, '');
37
+ _CloudClient_sessionKey.set(this, '');
38
+ _CloudClient_cacheQuery.set(this, void 0);
39
+ _CloudClient_valid.set(this, (options) => {
40
+ if (!options.cookie && (!options.username || !options.password)) {
41
+ log_1.log.error('valid');
42
+ throw new Error('Please provide username and password or Cookie!');
43
+ }
44
+ }
45
+ /**
46
+ * 获取加密参数
47
+ * @returns
48
+ */
49
+ );
50
+ _CloudClient_builLoginForm.set(this, (encrypt, appConf) => {
51
+ const jsencrypt = new node_jsencrypt_1.default();
52
+ const keyData = `-----BEGIN PUBLIC KEY-----\n${encrypt.pubKey}\n-----END PUBLIC KEY-----`;
53
+ jsencrypt.setPublicKey(keyData);
54
+ const usernameEncrypt = Buffer.from(jsencrypt.encrypt(this.username), 'base64').toString('hex');
55
+ const passwordEncrypt = Buffer.from(jsencrypt.encrypt(this.password), 'base64').toString('hex');
56
+ const data = {
57
+ appKey: 'cloud',
58
+ version: '2.0',
59
+ accountType: '01',
60
+ mailSuffix: '@189.cn',
61
+ validateCode: '',
62
+ captchaToken: '',
63
+ dynamicCheck: 'FALSE',
64
+ clientType: '1',
65
+ cb_SaveName: '3',
66
+ isOauth2: false,
67
+ returnUrl: appConf.returnUrl,
68
+ paramId: appConf.paramId,
69
+ userName: `${encrypt.pre}${usernameEncrypt}`,
70
+ epd: `${encrypt.pre}${passwordEncrypt}`
71
+ };
72
+ return data;
73
+ }
74
+ /**
75
+ * 用户名密码登录
76
+ * */
77
+ );
78
+ __classPrivateFieldGet(this, _CloudClient_valid, "f").call(this, _options);
79
+ this.username = _options.username;
80
+ this.password = _options.password;
81
+ if (_options.cookie) {
82
+ this.cookie = _options.cookie;
83
+ }
84
+ else {
85
+ this.cookie = new tough_cookie_1.CookieJar();
86
+ }
87
+ this.request = got_1.default.extend({
88
+ cookieJar: this.cookie,
89
+ retry: {
90
+ limit: 5
91
+ },
92
+ headers: {
93
+ 'User-Agent': `Mozilla/5.0 (Linux; U; Android 11; ${config.model} Build/RP1A.201005.001) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/74.0.3729.136 Mobile Safari/537.36 Ecloud/${config.version} Android/30 clientId/${config.clientId} clientModel/${config.model} clientChannelId/qq proVersion/1.0.6`,
94
+ Referer: 'https://cloud.189.cn/web/main/'
95
+ },
96
+ hooks: {
97
+ beforeRequest: [
98
+ async (options) => {
99
+ log_1.log.debug(`Request url: ${options.url}`);
100
+ if (options.url.host === 'api.cloud.189.cn') {
101
+ const accessToken = await this.getAccessToken();
102
+ const { query } = url_1.default.parse(options.url.toString(), true);
103
+ const time = String(Date.now());
104
+ const signature = (0, util_1.getSignature)(Object.assign(Object.assign({}, (options.method === 'GET' ? query : options.json)), { Timestamp: time, AccessToken: accessToken }));
105
+ options.headers['Sign-Type'] = '1';
106
+ options.headers['Signature'] = signature;
107
+ options.headers['Timestamp'] = time;
108
+ options.headers['Accesstoken'] = accessToken;
109
+ options.headers['Accept'] = 'application/json;charset=UTF-8';
110
+ }
111
+ }
112
+ ],
113
+ afterResponse: [
114
+ async (response, retryWithMergedOptions) => {
115
+ if (response.statusCode === 400) {
116
+ const { errorCode, errorMsg } = JSON.parse(response.body.toString());
117
+ log_1.log.debug(`url: ${response.requestUrl}, errorCode: ${errorCode}, errorMsg : ${errorMsg}`);
118
+ if (errorCode === 'InvalidAccessToken') {
119
+ log_1.log.warn('InvalidAccessToken retry...');
120
+ log_1.log.warn('Refresh AccessToken');
121
+ await this.getAccessToken(true);
122
+ return retryWithMergedOptions({});
123
+ }
124
+ else if (errorCode === 'InvalidSessionKey') {
125
+ log_1.log.warn('InvalidSessionKey retry...');
126
+ log_1.log.warn('Refresh InvalidSessionKey');
127
+ const sessionKey = await this.getSessionKey(true);
128
+ const urlObj = new URL(response.requestUrl);
129
+ if (urlObj.searchParams.has('sessionKey')) {
130
+ urlObj.searchParams.set('sessionKey', sessionKey);
131
+ }
132
+ return retryWithMergedOptions({
133
+ url: urlObj.toString()
134
+ });
135
+ }
136
+ }
137
+ return response;
138
+ }
139
+ ]
140
+ }
141
+ });
142
+ }
143
+ /**
144
+ * 获取加密参数
145
+ * @returns
146
+ */
147
+ getEncrypt() {
148
+ return this.request.post('https://open.e.189.cn/api/logbox/config/encryptConf.do').json();
149
+ }
150
+ /**
151
+ * 跳转到登录页面
152
+ * @returns 登录的参数
153
+ */
154
+ redirectURL() {
155
+ return new Promise((resolve, reject) => {
156
+ this.request
157
+ .get('https://cloud.189.cn/api/portal/loginUrl.action?redirectURL=https://cloud.189.cn/web/redirect.html?returnURL=/main.action')
158
+ .then((res) => {
159
+ const { query } = url_1.default.parse(res.url, true);
160
+ resolve(query);
161
+ })
162
+ .catch((e) => reject(e));
163
+ });
164
+ }
165
+ /**
166
+ * 用户名密码登录
167
+ * */
168
+ login() {
169
+ /**
170
+ * 1.获取公钥
171
+ * 2.获取登录参数
172
+ * 3.获取登录地址
173
+ * 4.跳转到登录页
174
+ */
175
+ return new Promise((resolve, reject) => {
176
+ if (!this.username || !this.password) {
177
+ throw new Error('Please provide username and password!');
178
+ }
179
+ log_1.log.debug('login...');
180
+ this.cookie.removeAllCookiesSync();
181
+ Promise.all([
182
+ //1.获取公钥
183
+ this.getEncrypt(),
184
+ //2.获取登录参数
185
+ this.redirectURL().then((query) => {
186
+ __classPrivateFieldSet(this, _CloudClient_cacheQuery, query, "f");
187
+ return __classPrivateFieldGet(this, _CloudClient_instances, "m", _CloudClient_appConf).call(this);
188
+ })
189
+ ])
190
+ .then((res) => {
191
+ const encrypt = res[0].data;
192
+ const appConf = res[1].data;
193
+ const data = __classPrivateFieldGet(this, _CloudClient_builLoginForm, "f").call(this, encrypt, appConf);
194
+ //3.获取登录地址
195
+ return this.request
196
+ .post('https://open.e.189.cn/api/logbox/oauth2/loginSubmit.do', {
197
+ headers: {
198
+ Referer: 'https://open.e.189.cn/',
199
+ lt: __classPrivateFieldGet(this, _CloudClient_cacheQuery, "f").lt,
200
+ REQID: __classPrivateFieldGet(this, _CloudClient_cacheQuery, "f").reqId
201
+ },
202
+ form: data
203
+ })
204
+ .json();
205
+ })
206
+ .then((res) => {
207
+ // 4.跳转到登录页
208
+ if (res.result !== 0) {
209
+ reject(res.msg);
210
+ }
211
+ else {
212
+ return this.request.get(res.toUrl).then((r) => resolve(r.statusCode));
213
+ }
214
+ })
215
+ .catch((e) => reject(e));
216
+ });
217
+ }
218
+ /**
219
+ * 是否存在登录信息
220
+ * @returns
221
+ */
222
+ isLoggedSession() {
223
+ var _a;
224
+ const loginUserCookie = (_a = this.cookie
225
+ .getCookiesSync('https://cloud.189.cn')) === null || _a === void 0 ? void 0 : _a.find((cookie) => cookie.key === 'COOKIE_LOGIN_USER' && cookie.value);
226
+ if (loginUserCookie) {
227
+ return true;
228
+ }
229
+ return false;
230
+ }
231
+ /**
232
+ * 获取 sessionKey
233
+ * @param needRefresh - 是否重新获取
234
+ * @returns sessionKey
235
+ */
236
+ async getSessionKey(needRefresh = false) {
237
+ if (!__classPrivateFieldGet(this, _CloudClient_sessionKey, "f") || needRefresh) {
238
+ if (!this.isLoggedSession()) {
239
+ await this.login();
240
+ }
241
+ const { sessionKey } = await __classPrivateFieldGet(this, _CloudClient_instances, "m", _CloudClient_getUserBriefInfo).call(this);
242
+ __classPrivateFieldSet(this, _CloudClient_sessionKey, sessionKey, "f");
243
+ }
244
+ return __classPrivateFieldGet(this, _CloudClient_sessionKey, "f");
245
+ }
246
+ /**
247
+ * 获取 accessToken
248
+ * @param needRefresh - 是否重新获取
249
+ * @returns accessToken
250
+ */
251
+ async getAccessToken(needRefresh = false) {
252
+ if (!__classPrivateFieldGet(this, _CloudClient_accessToken, "f") || needRefresh) {
253
+ const sessionKey = await this.getSessionKey();
254
+ const { accessToken } = await __classPrivateFieldGet(this, _CloudClient_instances, "m", _CloudClient_getAccessTokenBySsKey).call(this, sessionKey);
255
+ __classPrivateFieldSet(this, _CloudClient_accessToken, accessToken, "f");
256
+ }
257
+ return __classPrivateFieldGet(this, _CloudClient_accessToken, "f");
258
+ }
259
+ /**
260
+ * 获取用户网盘存储容量信息
261
+ * @returns 账号容量结果
262
+ */
263
+ getUserSizeInfo() {
264
+ return this.request
265
+ .get('https://cloud.189.cn/api/portal/getUserSizeInfo.action', {
266
+ headers: { Accept: 'application/json;charset=UTF-8' }
267
+ })
268
+ .json();
269
+ }
270
+ /**
271
+ * 个人签到任务
272
+ * @returns 签到结果
273
+ */
274
+ userSign() {
275
+ return this.request
276
+ .get(`https://cloud.189.cn/mkt/userSign.action?rand=${new Date().getTime()}&clientType=TELEANDROID&version=${config.version}&model=${config.model}`)
277
+ .json();
278
+ }
279
+ /**
280
+ * 任务无效, 1.0.4版本废弃
281
+ * @deprecated 任务过期
282
+ */
283
+ taskSign() {
284
+ return this.request('https://m.cloud.189.cn/v2/drawPrizeMarketDetails.action?taskId=TASK_SIGNIN&activityId=ACT_SIGNIN').json();
285
+ }
286
+ /**
287
+ * 任务无效, 1.0.4版本废弃
288
+ * @deprecated 任务过期
289
+ */
290
+ taskPhoto() {
291
+ return this.request('https://m.cloud.189.cn/v2/drawPrizeMarketDetails.action?taskId=TASK_SIGNIN_PHOTOS&activityId=ACT_SIGNIN').json();
292
+ }
293
+ /**
294
+ * 任务无效, 1.0.3版本废弃
295
+ * @deprecated 任务过期
296
+ */
297
+ taskKJ() {
298
+ return this.request
299
+ .get('https://m.cloud.189.cn/v2/drawPrizeMarketDetails.action?taskId=TASK_2022_FLDFS_KJ&activityId=ACT_SIGNIN')
300
+ .json();
301
+ }
302
+ /**
303
+ * 获取家庭信息
304
+ * @returns 家庭列表信息
305
+ */
306
+ getFamilyList() {
307
+ return this.request
308
+ .get('https://api.cloud.189.cn/open/family/manage/getFamilyList.action')
309
+ .json();
310
+ }
311
+ /**
312
+ * 家庭签到任务
313
+ * @param familyId - 家庭id
314
+ * @returns 签到结果
315
+ */
316
+ familyUserSign(familyId) {
317
+ return this.request
318
+ .get(`https://api.cloud.189.cn/open/family/manage/exeFamilyUserSign.action?familyId=${familyId}`)
319
+ .json();
320
+ }
321
+ }
322
+ exports.default = CloudClient;
323
+ _CloudClient_accessToken = new WeakMap(), _CloudClient_sessionKey = new WeakMap(), _CloudClient_cacheQuery = new WeakMap(), _CloudClient_valid = new WeakMap(), _CloudClient_builLoginForm = new WeakMap(), _CloudClient_instances = new WeakSet(), _CloudClient_appConf = function _CloudClient_appConf() {
324
+ return this.request
325
+ .post('https://open.e.189.cn/api/logbox/oauth2/appConf.do', {
326
+ headers: {
327
+ Referer: 'https://open.e.189.cn/',
328
+ lt: __classPrivateFieldGet(this, _CloudClient_cacheQuery, "f").lt,
329
+ REQID: __classPrivateFieldGet(this, _CloudClient_cacheQuery, "f").reqId
330
+ },
331
+ form: { version: '2.0', appKey: __classPrivateFieldGet(this, _CloudClient_cacheQuery, "f").appId }
332
+ })
333
+ .json();
334
+ }, _CloudClient_getUserBriefInfo = function _CloudClient_getUserBriefInfo() {
335
+ return this.request.get('https://cloud.189.cn/api/portal/v2/getUserBriefInfo.action').json();
336
+ }, _CloudClient_getAccessTokenBySsKey = function _CloudClient_getAccessTokenBySsKey(sessionKey) {
337
+ const appkey = '600100422';
338
+ const time = String(Date.now());
339
+ const signature = (0, util_1.getSignature)({
340
+ sessionKey,
341
+ Timestamp: time,
342
+ AppKey: appkey
343
+ });
344
+ return this.request
345
+ .get(`https://cloud.189.cn/api/open/oauth2/getAccessTokenBySsKey.action?sessionKey=${sessionKey}`, {
346
+ headers: {
347
+ 'Sign-Type': '1',
348
+ Signature: signature,
349
+ Timestamp: time,
350
+ Appkey: appkey
351
+ }
352
+ })
353
+ .json();
354
+ };
package/dist/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
- import CloudClient from "./CloudClient";
2
- export { CloudClient };
1
+ import CloudClient from './CloudClient';
2
+ export { CloudClient };
3
+ export * from './types';
package/dist/index.js CHANGED
@@ -1,8 +1,23 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.CloudClient = void 0;
7
- const CloudClient_1 = __importDefault(require("./CloudClient"));
8
- exports.CloudClient = CloudClient_1.default;
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ var __importDefault = (this && this.__importDefault) || function (mod) {
17
+ return (mod && mod.__esModule) ? mod : { "default": mod };
18
+ };
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.CloudClient = void 0;
21
+ const CloudClient_1 = __importDefault(require("./CloudClient"));
22
+ exports.CloudClient = CloudClient_1.default;
23
+ __exportStar(require("./types"), exports);
package/dist/log.d.ts ADDED
@@ -0,0 +1,24 @@
1
+ /// <reference types="node" />
2
+ import _debug from 'debug';
3
+ import WritableStream = NodeJS.WritableStream;
4
+ export declare const debug: _debug.Debugger;
5
+ export interface Fields {
6
+ [index: string]: any;
7
+ }
8
+ export type LogLevel = 'info' | 'warn' | 'debug' | 'notice' | 'error';
9
+ export declare const PADDING = 2;
10
+ export declare class Logger {
11
+ protected readonly stream: WritableStream;
12
+ constructor(stream: WritableStream);
13
+ messageTransformer: (message: string, level: LogLevel) => string;
14
+ get isDebugEnabled(): boolean;
15
+ info(messageOrFields: Fields | null | string, message?: string): void;
16
+ error(messageOrFields: Fields | null | string, message?: string): void;
17
+ warn(messageOrFields: Fields | null | string, message?: string): void;
18
+ debug(messageOrFields: Fields | null | string, message?: string): void;
19
+ private doLog;
20
+ private _doLog;
21
+ static createMessage(message: string, fields: Fields | null, level: LogLevel, color: (it: string) => string, messagePadding?: number): string;
22
+ log(message: string): void;
23
+ }
24
+ export declare const log: Logger;
package/dist/log.js ADDED
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.log = exports.Logger = exports.PADDING = exports.debug = void 0;
7
+ const chalk_1 = __importDefault(require("chalk"));
8
+ const debug_1 = __importDefault(require("debug"));
9
+ let printer = null;
10
+ exports.debug = (0, debug_1.default)('cloud189-sdk');
11
+ exports.PADDING = 2;
12
+ class Logger {
13
+ constructor(stream) {
14
+ this.stream = stream;
15
+ this.messageTransformer = (it) => it;
16
+ }
17
+ get isDebugEnabled() {
18
+ return exports.debug.enabled;
19
+ }
20
+ info(messageOrFields, message) {
21
+ this.doLog(message, messageOrFields, 'info');
22
+ }
23
+ error(messageOrFields, message) {
24
+ this.doLog(message, messageOrFields, 'error');
25
+ }
26
+ warn(messageOrFields, message) {
27
+ this.doLog(message, messageOrFields, 'warn');
28
+ }
29
+ debug(messageOrFields, message) {
30
+ if (exports.debug.enabled) {
31
+ this.doLog(message, messageOrFields, 'debug');
32
+ }
33
+ }
34
+ doLog(message, messageOrFields, level) {
35
+ if (message === undefined) {
36
+ this._doLog(messageOrFields, null, level);
37
+ }
38
+ else {
39
+ this._doLog(message, messageOrFields, level);
40
+ }
41
+ }
42
+ _doLog(message, fields, level) {
43
+ // noinspection SuspiciousInstanceOfGuard
44
+ if (message instanceof Error) {
45
+ message = message.stack || message.toString();
46
+ }
47
+ else {
48
+ message = message.toString();
49
+ }
50
+ const levelIndicator = level === 'error' ? '⨯' : '•';
51
+ const color = LEVEL_TO_COLOR[level];
52
+ this.stream.write(`${' '.repeat(exports.PADDING)}${color(levelIndicator)} `);
53
+ this.stream.write(Logger.createMessage(this.messageTransformer(message, level), fields, level, color, exports.PADDING + 2 /* level indicator and space */));
54
+ this.stream.write('\n');
55
+ }
56
+ static createMessage(message, fields, level, color, messagePadding = 0) {
57
+ if (fields == null) {
58
+ return message;
59
+ }
60
+ const fieldPadding = ' '.repeat(Math.max(2, 16 - message.length));
61
+ let text = (level === 'error' ? color(message) : message) + fieldPadding;
62
+ const fieldNames = Object.keys(fields);
63
+ let counter = 0;
64
+ for (const name of fieldNames) {
65
+ let fieldValue = fields[name];
66
+ let valuePadding = null;
67
+ // Remove unnecessary line breaks
68
+ if (fieldValue != null && typeof fieldValue === 'string' && fieldValue.includes('\n')) {
69
+ valuePadding = ' '.repeat(messagePadding + message.length + fieldPadding.length + 2);
70
+ fieldValue = fieldValue.replace(/\n\s*\n/g, `\n${valuePadding}`);
71
+ }
72
+ else if (Array.isArray(fieldValue)) {
73
+ fieldValue = JSON.stringify(fieldValue);
74
+ }
75
+ text += `${color(name)}=${fieldValue}`;
76
+ if (++counter !== fieldNames.length) {
77
+ if (valuePadding == null) {
78
+ text += ' ';
79
+ }
80
+ else {
81
+ text += '\n' + valuePadding;
82
+ }
83
+ }
84
+ }
85
+ return text;
86
+ }
87
+ log(message) {
88
+ if (printer == null) {
89
+ this.stream.write(`${message}\n`);
90
+ }
91
+ else {
92
+ printer(message);
93
+ }
94
+ }
95
+ }
96
+ exports.Logger = Logger;
97
+ const LEVEL_TO_COLOR = {
98
+ info: chalk_1.default.blue,
99
+ warn: chalk_1.default.yellow,
100
+ error: chalk_1.default.red,
101
+ debug: chalk_1.default.white
102
+ };
103
+ exports.log = new Logger(process.stdout);
@@ -0,0 +1,146 @@
1
+ import { CookieJar } from 'tough-cookie';
2
+ /**
3
+ * 账户家庭信息
4
+ * @public
5
+ */
6
+ export interface FamilyListResponse {
7
+ familyInfoResp: [
8
+ {
9
+ /**
10
+ * 家庭id
11
+ */
12
+ familyId: number;
13
+ /**
14
+ * 家庭名称
15
+ */
16
+ remarkName: string;
17
+ /**
18
+ * 类型
19
+ */
20
+ type: number;
21
+ /**
22
+ * 用户角色 如果是1 表明当前账户是该账户的主家庭 否则当前账户是其他家庭的成员账户
23
+ */
24
+ userRole: number;
25
+ }
26
+ ];
27
+ }
28
+ /**
29
+ * sessionKey结果
30
+ * @public
31
+ */
32
+ export interface UserBriefInfoResponse {
33
+ sessionKey: string;
34
+ }
35
+ /**
36
+ * accessToken 结果
37
+ * @public
38
+ */
39
+ export interface AccessTokenResponse {
40
+ /**
41
+ * accessToken
42
+ */
43
+ accessToken: string;
44
+ /**
45
+ * accessToken 的有效期 单位秒
46
+ */
47
+ expiresIn: number;
48
+ }
49
+ /**
50
+ * 家庭签到任务结果
51
+ * @public
52
+ */
53
+ export interface FamilyUserSignResponse {
54
+ /**
55
+ * 签到的奖励容量 单位MB
56
+ */
57
+ bonusSpace: number;
58
+ /**
59
+ * 签到的家庭id
60
+ */
61
+ signFamilyId: number;
62
+ /**
63
+ * 签到的状态
64
+ */
65
+ signStatus: number;
66
+ /**
67
+ * 签到的时间
68
+ */
69
+ signTime: string;
70
+ /**
71
+ * 签到的用户
72
+ */
73
+ userId: string;
74
+ }
75
+ /**
76
+ * 容量信息
77
+ * @public
78
+ */
79
+ export interface CapacityInfo {
80
+ /**
81
+ * 总空间 单位KB
82
+ */
83
+ totalSize: number;
84
+ /**
85
+ * 已使用空间 单位KB
86
+ */
87
+ usedSize: number;
88
+ /**
89
+ * 剩余空间 单位KB
90
+ */
91
+ freeSize: number;
92
+ }
93
+ /**
94
+ * 账户容量信息
95
+ * @public
96
+ */
97
+ export interface UserSizeInfoResponse {
98
+ /**
99
+ * 个人容量信息
100
+ */
101
+ cloudCapacityInfo: CapacityInfo;
102
+ /**
103
+ * 家庭容量信息
104
+ */
105
+ familyCapacityInfo: CapacityInfo;
106
+ }
107
+ /**
108
+ * 个人签到结果
109
+ * @public
110
+ */
111
+ export interface UserSignResponse {
112
+ /**
113
+ * 是否已经签到过
114
+ */
115
+ isSign: boolean;
116
+ /**
117
+ * 签到获取的容量奖励 单位MB
118
+ */
119
+ netdiskBonus: number;
120
+ }
121
+ /**
122
+ * 个人任务执行结果
123
+ * @public
124
+ */
125
+ export interface UserTaskResponse {
126
+ /**
127
+ * 错误码
128
+ */
129
+ errorCode: string;
130
+ /**
131
+ * 奖励容量 单位MB
132
+ */
133
+ prizeName: string;
134
+ }
135
+ /**
136
+ * 客户端初始化参数
137
+ * @public
138
+ */
139
+ export interface ConfigurationOptions {
140
+ /** 登录名 */
141
+ username?: string;
142
+ /** 密码 */
143
+ password?: string;
144
+ /** 登录的cookie,如不传用户名和密码时需要传入 */
145
+ cookie?: CookieJar;
146
+ }
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/dist/util.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ declare const getSignature: (data: any) => string;
2
+ export { getSignature };
package/dist/util.js ADDED
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getSignature = void 0;
7
+ const crypto_1 = __importDefault(require("crypto"));
8
+ const sortParameter = (data) => {
9
+ if (!data) {
10
+ return '';
11
+ }
12
+ const e = Object.entries(data).map((t) => t.join('='));
13
+ e.sort((a, b) => (a > b ? 1 : a < b ? -1 : 0));
14
+ return e.join('&');
15
+ };
16
+ const getSignature = (data) => {
17
+ const parameter = sortParameter(data);
18
+ return crypto_1.default.createHash('md5').update(parameter).digest('hex');
19
+ };
20
+ exports.getSignature = getSignature;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "cloud189-sdk",
3
- "version": "1.0.4",
4
- "description": "cloud189-sdk",
3
+ "version": "1.0.6-alpha.1",
4
+ "description": "基于node.js的第三方天翼云盘SDK",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "files": [
@@ -11,7 +11,13 @@
11
11
  ],
12
12
  "scripts": {
13
13
  "start": "node ./test/app.js",
14
+ "debug": "DEBUG=* node ./test/app.js",
14
15
  "build": "tsc",
16
+ "api-extractor": "api-extractor run",
17
+ "api-documenter": "api-documenter markdown -i temp -o docs/api",
18
+ "doc:preare": "npm run api-extractor && npm run api-documenter",
19
+ "doc:dev": "npm run doc:preare && vuepress dev docs",
20
+ "doc:build": "npm run build && npm run doc:preare && vuepress build docs",
15
21
  "test": "mocha",
16
22
  "coverage": "nyc npm run test"
17
23
  },
@@ -25,22 +31,36 @@
25
31
  ],
26
32
  "license": "MIT",
27
33
  "dependencies": {
34
+ "chalk": "^4.1.2",
35
+ "debug": "^4.4.0",
28
36
  "got": "11.8.2",
29
37
  "node-jsencrypt": "^1.0.0",
30
- "tough-cookie": "^4.1.4"
38
+ "tough-cookie": "^4.1.4",
39
+ "tough-cookie-file-store": "^2.0.3"
31
40
  },
32
41
  "engines": {
33
42
  "node": ">=16"
34
43
  },
35
44
  "devDependencies": {
45
+ "@microsoft/api-documenter": "^7.26.9",
46
+ "@microsoft/api-extractor": "^7.50.0",
36
47
  "@types/chai": "^4.3.16",
37
48
  "@types/mocha": "^10.0.6",
38
49
  "@types/node": "^20.12.13",
50
+ "@types/tough-cookie": "^4.0.5",
51
+ "@types/tough-cookie-file-store": "^2.0.4",
52
+ "@typescript-eslint/parser": "^6.17.0",
53
+ "@vuepress/bundler-vite": "^2.0.0-rc.19",
54
+ "@vuepress/theme-default": "^2.0.0-rc.78",
39
55
  "chai": "4.4.1",
40
56
  "mocha": "^10.4.0",
41
57
  "nock": "14.0.0-beta.7",
42
58
  "nyc": "^15.1.0",
59
+ "prettier": "^3.3.2",
60
+ "sass-embedded": "^1.85.0",
43
61
  "ts-node": "^10.9.2",
44
- "typescript": "4.9.5"
62
+ "typescript": "4.9.5",
63
+ "vue": "^3.5.13",
64
+ "vuepress": "^2.0.0-rc.19"
45
65
  }
46
66
  }