cloud189-sdk 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Wes Lin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # cloud189-sdk
@@ -0,0 +1,74 @@
1
+ interface CacheQuery {
2
+ REQID: any;
3
+ lt: any;
4
+ }
5
+ interface FamilyListResponse {
6
+ familyInfoResp: [
7
+ {
8
+ familyId: any;
9
+ }
10
+ ];
11
+ }
12
+ interface APIResponse {
13
+ result: number;
14
+ msg: string;
15
+ }
16
+ interface UserBriefInfoResponse extends APIResponse {
17
+ sessionKey: string;
18
+ }
19
+ interface AccessTokenResponse extends APIResponse {
20
+ accessToken: string;
21
+ }
22
+ interface FamilyUserSignResponse extends APIResponse {
23
+ bonusSpace: number;
24
+ signFamilyId: number;
25
+ signStatus: number;
26
+ signTime: string;
27
+ userId: string;
28
+ }
29
+ interface UserSizeInfoResponse extends APIResponse {
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
+ declare class CloudClient {
46
+ #private;
47
+ username: string;
48
+ password: string;
49
+ cacheQuery: CacheQuery;
50
+ constructor(username: any, password: any);
51
+ getEncrypt: () => Promise<any>;
52
+ redirectURL: () => Promise<unknown>;
53
+ appConf: (query: any) => Promise<any>;
54
+ /**
55
+ * 登录流程
56
+ * 1.获取公钥
57
+ * 2.获取登录参数
58
+ * 3.获取登录地址
59
+ * 4.跳转到登录页
60
+ * */
61
+ login: () => Promise<any>;
62
+ fetchAPI: (task: any) => Promise<any>;
63
+ getUserSizeInfo: () => Promise<UserSizeInfoResponse>;
64
+ userSign: () => Promise<UserSignResponse>;
65
+ taskSign: () => Promise<TaskResponse>;
66
+ taskPhoto: () => Promise<TaskResponse>;
67
+ taskKJ: () => Promise<TaskResponse>;
68
+ getUserBriefInfo: () => Promise<UserBriefInfoResponse>;
69
+ getAccessTokenBySsKey: (sessionKey: any) => Promise<AccessTokenResponse>;
70
+ fetchFamilyAPI: (path: any) => Promise<any>;
71
+ getFamilyList: () => Promise<FamilyListResponse>;
72
+ familyUserSign: (familyId: string) => Promise<FamilyUserSignResponse>;
73
+ }
74
+ export default CloudClient;
@@ -0,0 +1,225 @@
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
+ .json();
155
+ };
156
+ this.userSign = () => {
157
+ return this.fetchAPI(`https://cloud.189.cn/mkt/userSign.action?rand=${new Date().getTime()}&clientType=TELEANDROID&version=${config.version}&model=${config.model}`);
158
+ };
159
+ this.taskSign = () => {
160
+ return this.fetchAPI("https://m.cloud.189.cn/v2/drawPrizeMarketDetails.action?taskId=TASK_SIGNIN&activityId=ACT_SIGNIN");
161
+ };
162
+ this.taskPhoto = () => {
163
+ return this.fetchAPI("https://m.cloud.189.cn/v2/drawPrizeMarketDetails.action?taskId=TASK_2022_FLDFS_KJ&activityId=ACT_SIGNIN");
164
+ };
165
+ this.taskKJ = () => {
166
+ return this.fetchAPI("https://m.cloud.189.cn/v2/drawPrizeMarketDetails.action?taskId=TASK_2022_FLDFS_KJ&activityId=ACT_SIGNIN");
167
+ };
168
+ this.getUserBriefInfo = () => got_1.default
169
+ .get("https://cloud.189.cn/api/portal/v2/getUserBriefInfo.action", {
170
+ cookieJar,
171
+ })
172
+ .json();
173
+ this.getAccessTokenBySsKey = (sessionKey) => {
174
+ const appkey = "600100422";
175
+ const time = String(Date.now());
176
+ const signature = __classPrivateFieldGet(this, _CloudClient_getSignature, "f").call(this, {
177
+ sessionKey,
178
+ Timestamp: time,
179
+ AppKey: appkey,
180
+ });
181
+ return got_1.default
182
+ .get(`https://cloud.189.cn/api/open/oauth2/getAccessTokenBySsKey.action?sessionKey=${sessionKey}`, {
183
+ headers: {
184
+ "Sign-Type": "1",
185
+ Signature: signature,
186
+ Timestamp: time,
187
+ Appkey: appkey,
188
+ },
189
+ cookieJar,
190
+ })
191
+ .json();
192
+ };
193
+ this.fetchFamilyAPI = async (path) => {
194
+ const { query } = url_1.default.parse(path, true);
195
+ const time = String(Date.now());
196
+ if (!__classPrivateFieldGet(this, _CloudClient_accessToken, "f")) {
197
+ const { sessionKey } = await this.getUserBriefInfo();
198
+ const { accessToken } = await this.getAccessTokenBySsKey(sessionKey);
199
+ __classPrivateFieldSet(this, _CloudClient_accessToken, accessToken, "f");
200
+ }
201
+ const signature = __classPrivateFieldGet(this, _CloudClient_getSignature, "f").call(this, Object.assign(Object.assign({}, query), { Timestamp: time, AccessToken: __classPrivateFieldGet(this, _CloudClient_accessToken, "f") }));
202
+ return got_1.default
203
+ .get(path, {
204
+ headers: {
205
+ "Sign-Type": "1",
206
+ Signature: signature,
207
+ Timestamp: time,
208
+ Accesstoken: __classPrivateFieldGet(this, _CloudClient_accessToken, "f"),
209
+ Accept: "application/json;charset=UTF-8",
210
+ },
211
+ cookieJar,
212
+ })
213
+ .json();
214
+ };
215
+ this.getFamilyList = () => this.fetchFamilyAPI("https://api.cloud.189.cn/open/family/manage/getFamilyList.action");
216
+ this.familyUserSign = (familyId) => {
217
+ const gturl = `https://api.cloud.189.cn/open/family/manage/exeFamilyUserSign.action?familyId=${familyId}`;
218
+ return this.fetchFamilyAPI(gturl);
219
+ };
220
+ this.username = username;
221
+ this.password = password;
222
+ }
223
+ }
224
+ _CloudClient_accessToken = new WeakMap(), _CloudClient_builLoginForm = new WeakMap(), _CloudClient_sortParameter = new WeakMap(), _CloudClient_getSignature = new WeakMap();
225
+ exports.default = CloudClient;
@@ -0,0 +1,2 @@
1
+ import CloudClient from "./CloudClient";
2
+ export { CloudClient };
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
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;
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "cloud189-sdk",
3
+ "version": "1.0.0",
4
+ "description": "cloud189-sdk",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "files": [
8
+ "dist/**/*.js",
9
+ "dist/**/*.d.ts",
10
+ "!__tests__"
11
+ ],
12
+ "scripts": {
13
+ "start": "node ./test/app.js",
14
+ "build": "tsc",
15
+ "test": "mocha",
16
+ "coverage": "nyc npm run test"
17
+ },
18
+ "author": "wes lin",
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "https://github.com/wes-lin/cloud189-sdk.git"
22
+ },
23
+ "keywords": [
24
+ "天翼网盘sdk"
25
+ ],
26
+ "license": "MIT",
27
+ "dependencies": {
28
+ "got": "11.8.2",
29
+ "node-jsencrypt": "^1.0.0",
30
+ "tough-cookie": "^4.1.4"
31
+ },
32
+ "engines": {
33
+ "node": ">=16"
34
+ },
35
+ "devDependencies": {
36
+ "@types/chai": "^4.3.16",
37
+ "@types/mocha": "^10.0.6",
38
+ "@types/node": "^20.12.13",
39
+ "chai": "4.4.1",
40
+ "mocha": "^10.4.0",
41
+ "nock": "14.0.0-beta.7",
42
+ "nyc": "^15.1.0",
43
+ "ts-node": "^10.9.2",
44
+ "typescript": "4.9.5"
45
+ }
46
+ }