cloud189-sdk 1.0.5 → 1.0.6-alpha.2

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