cloud189-sdk 1.0.8 → 1.0.9-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/types.d.ts DELETED
@@ -1,510 +0,0 @@
1
- import { Store } from './store';
2
- /**
3
- * 账户家庭信息
4
- * @public
5
- */
6
- export interface FamilyListResponse {
7
- familyInfoResp: [
8
- {
9
- /**
10
- * 家庭id
11
- */
12
- familyId: string;
13
- /**
14
- * 家庭名称
15
- */
16
- remarkName: string;
17
- /**
18
- * 类型
19
- */
20
- type: number;
21
- /**
22
- * 用户角色 如果是1 表明当前账户是该账户的主家庭 否则当前账户是其他家庭的成员账户
23
- */
24
- userRole: number;
25
- }
26
- ];
27
- }
28
- /**
29
- * accessToken 结果
30
- * @public
31
- */
32
- export interface AccessTokenResponse {
33
- /**
34
- * accessToken
35
- */
36
- accessToken: string;
37
- /**
38
- * accessToken 的有效期 单位秒
39
- */
40
- expiresIn: number;
41
- }
42
- /**
43
- * 家庭签到任务结果
44
- * @public
45
- */
46
- export interface FamilyUserSignResponse {
47
- /**
48
- * 签到的奖励容量 单位MB
49
- */
50
- bonusSpace: number;
51
- /**
52
- * 签到的家庭id
53
- */
54
- signFamilyId: number;
55
- /**
56
- * 签到的状态
57
- */
58
- signStatus: number;
59
- /**
60
- * 签到的时间
61
- */
62
- signTime: string;
63
- /**
64
- * 签到的用户
65
- */
66
- userId: string;
67
- }
68
- /**
69
- * 文件类型
70
- * @public
71
- */
72
- export declare enum MediaType {
73
- ALL = 0,
74
- IMAGE = 1,
75
- MUSIC = 2,
76
- VIDEO = 3,
77
- TXT = 4
78
- }
79
- /**
80
- * 排序类型
81
- * @public
82
- */
83
- export declare enum OrderByType {
84
- NAME = 1,
85
- SIZE = 2,
86
- LAST_OP_TIME = 3
87
- }
88
- /**
89
- * 分页参数
90
- * @public
91
- */
92
- export interface PageQuery {
93
- /**
94
- * 分页大小 默认60
95
- */
96
- pageSize?: number;
97
- /**
98
- * 页码 默认1
99
- */
100
- pageNum?: number;
101
- /**
102
- * 文件类型
103
- * 0 全部 1 图片 2 视频 3 文档
104
- */
105
- mediaType?: MediaType;
106
- /**
107
- * 文件夹Id
108
- */
109
- folderId?: string;
110
- /**
111
- * 未知参数 5
112
- */
113
- iconOption?: number;
114
- /**
115
- * 排序类型
116
- * 1 文件名称 2 文件大小 3 文件修改时间
117
- */
118
- orderBy?: OrderByType;
119
- /**
120
- * 是否倒序
121
- */
122
- descending?: boolean;
123
- }
124
- /**
125
- * 文件列表API响应数据结构
126
- * @public
127
- */
128
- export interface FileListResponse {
129
- /** 文件列表数据对象 */
130
- fileListAO: FileListAO;
131
- /**
132
- * 最后修订版本号
133
- * 用于增量同步的时间戳或版本标识
134
- */
135
- lastRev: number;
136
- }
137
- /**
138
- * 文件列表数据对象
139
- * @public
140
- */
141
- export interface FileListAO {
142
- /** 文件总数 */
143
- count: number;
144
- /** 文件项列表 */
145
- fileList: FileItem[];
146
- /** 文件夹项列表 */
147
- folderList: FolderItem[];
148
- }
149
- /**
150
- * 文件项详细信息
151
- * @public
152
- */
153
- export interface FileItem {
154
- /** 文件创建时间,格式:YYYY-MM-DD HH:mm:ss */
155
- createDate: string;
156
- /**
157
- * 收藏标签
158
- * 0-未收藏 | 1-已收藏
159
- */
160
- favoriteLabel: number;
161
- /** 文件图标信息 */
162
- icon: {
163
- /** 大尺寸图标URL */
164
- largeUrl: string;
165
- /** 小尺寸图标URL */
166
- smallUrl: string;
167
- };
168
- /** 文件唯一标识ID */
169
- id: string;
170
- /** 最后操作时间,格式:YYYY-MM-DD HH:mm:ss */
171
- lastOpTime: string;
172
- /** 文件MD5哈希值,用于文件校验 */
173
- md5: string;
174
- /**
175
- * 媒体类型
176
- * 1-图片 | 2-视频 | 3-音频 | 4-文档
177
- */
178
- mediaType: number;
179
- /** 文件名 */
180
- name: string;
181
- /**
182
- * 图片方向
183
- * 0-正常 | 1-90° | 2-180° | 3-270°
184
- */
185
- orientation: number;
186
- /** 父目录ID */
187
- parentId: string;
188
- /** 文件版本标识,格式:YYYYMMDDHHmmss */
189
- rev: string;
190
- /** 文件大小(字节) */
191
- size: number;
192
- /**
193
- * 星标标签
194
- * 1-普通 | 2-标星
195
- */
196
- starLabel: number;
197
- }
198
- /**
199
- * 文件夹项详细信息
200
- * @public
201
- */
202
- export interface FolderItem {
203
- /** 文件夹创建时间,格式:YYYY-MM-DD HH:mm:ss */
204
- createDate: string;
205
- /** 文件夹内文件数量 */
206
- fileCount: number;
207
- /** 文件夹唯一标识ID */
208
- id: string;
209
- /** 最后操作时间,格式:YYYY-MM-DD HH:mm:ss */
210
- lastOpTime: string;
211
- /** 文件夹名称 */
212
- name: string;
213
- /** 父目录ID */
214
- parentId: string;
215
- /** 文件夹版本标识,格式:YYYYMMDDHHmmss */
216
- rev: string;
217
- /**
218
- * 星标标签
219
- * 1-普通 | 2-标星
220
- */
221
- starLabel: number;
222
- }
223
- /**
224
- * 家庭请求
225
- * @public
226
- */
227
- export interface FamilyRequest {
228
- familyId: string;
229
- }
230
- /**
231
- * 创建个人文件夹
232
- * @public
233
- */
234
- export interface CreateFolderRequest {
235
- parentFolderId: string;
236
- folderName: string;
237
- }
238
- /**
239
- * 创建家庭文件夹
240
- * @public
241
- */
242
- export interface CreateFamilyFolderRequest extends FamilyRequest, CreateFolderRequest {
243
- }
244
- /**
245
- * 创建个人文件夹
246
- * @public
247
- */
248
- export interface RenameFolderRequest {
249
- folderId: string;
250
- folderName: string;
251
- }
252
- /**
253
- * 创建家庭文件夹
254
- * @public
255
- */
256
- export interface RenameFamilyFolderRequest extends FamilyRequest, RenameFolderRequest {
257
- }
258
- /**
259
- * RsaKey响应
260
- * @public
261
- */
262
- export interface RsaKeyResponse extends RsaKey {
263
- res_code: number;
264
- res_message: string;
265
- }
266
- /**
267
- * 初始化个人上传请求
268
- * @public
269
- */
270
- export interface initMultiUploadRequest {
271
- parentFolderId: string;
272
- fileName: string;
273
- fileSize: number;
274
- sliceSize: number;
275
- fileMd5?: string;
276
- sliceMd5?: string;
277
- }
278
- /**
279
- * 初始化家庭上传请求
280
- * @public
281
- */
282
- export interface initMultiFamilyUploadRequest extends FamilyRequest, initMultiUploadRequest {
283
- }
284
- /**
285
- * 提交个人上传请求
286
- * @public
287
- */
288
- export interface CommitMultiUploadRequest {
289
- fileMd5: string;
290
- sliceMd5: string;
291
- uploadFileId: string;
292
- lazyCheck?: number;
293
- }
294
- /**
295
- * 提交家庭上传请求
296
- * @public
297
- */
298
- export interface CommitMultiFamilyUploadRequest extends FamilyRequest, CommitMultiUploadRequest {
299
- }
300
- /**
301
- * 容量信息
302
- * @public
303
- */
304
- export interface CapacityInfo {
305
- /**
306
- * 总空间 单位KB
307
- */
308
- totalSize: number;
309
- /**
310
- * 已使用空间 单位KB
311
- */
312
- usedSize: number;
313
- /**
314
- * 剩余空间 单位KB
315
- */
316
- freeSize: number;
317
- }
318
- /**
319
- * 账户容量信息
320
- * @public
321
- */
322
- export interface UserSizeInfoResponse {
323
- /**
324
- * 个人容量信息
325
- */
326
- cloudCapacityInfo: CapacityInfo;
327
- /**
328
- * 家庭容量信息
329
- */
330
- familyCapacityInfo: CapacityInfo;
331
- }
332
- /**
333
- * 个人签到结果
334
- * @public
335
- */
336
- export interface UserSignResponse {
337
- /**
338
- * 是否已经签到过
339
- */
340
- isSign: boolean;
341
- /**
342
- * 签到获取的容量奖励 单位MB
343
- */
344
- netdiskBonus: number;
345
- }
346
- /**
347
- * 个人任务执行结果
348
- * @public
349
- */
350
- export interface UserTaskResponse {
351
- /**
352
- * 错误码
353
- */
354
- errorCode: string;
355
- /**
356
- * 奖励容量 单位MB
357
- */
358
- prizeName: string;
359
- }
360
- /**
361
- * @public
362
- */
363
- export interface CacheQuery {
364
- captchaToken: string;
365
- reqId: string;
366
- lt: string;
367
- paramId: string;
368
- }
369
- /**
370
- * 客户端初始化参数
371
- * @public
372
- */
373
- export interface ConfigurationOptions {
374
- /** 登录名 */
375
- username?: string;
376
- /** 密码 */
377
- password?: string;
378
- /** token */
379
- token?: Store;
380
- ssonCookie?: string;
381
- }
382
- /**
383
- * @public
384
- * accessToken 有效期7天,可以通过refreshToken取新的accessToken
385
- */
386
- export interface TokenSession {
387
- res_code: number;
388
- res_message: string;
389
- accessToken: string;
390
- familySessionKey: string;
391
- familySessionSecret: string;
392
- refreshToken: string;
393
- loginName: string;
394
- sessionKey: string;
395
- }
396
- /**
397
- * @public
398
- */
399
- export interface RefreshTokenSession {
400
- expiresIn: number;
401
- accessToken: string;
402
- refreshToken: string;
403
- }
404
- /**
405
- * @public
406
- */
407
- export interface ClientSession {
408
- accessToken: string;
409
- sessionKey: string;
410
- }
411
- /**
412
- * @public
413
- */
414
- export interface RsaKey {
415
- expire: number;
416
- pkId: string;
417
- pubKey: string;
418
- ver: string;
419
- }
420
- /**
421
- * @public
422
- */
423
- export interface UploadResponse {
424
- code: string;
425
- }
426
- /**
427
- * @public
428
- */
429
- export interface UploadInitResponse extends UploadResponse {
430
- data: {
431
- uploadType: number;
432
- uploadHost: string;
433
- uploadFileId: string;
434
- fileDataExists: number;
435
- };
436
- }
437
- /**
438
- * @public
439
- */
440
- export interface UploadCommitResponse extends UploadResponse {
441
- file: {
442
- userFileId: string;
443
- fileName: string;
444
- fileSize: number;
445
- fileMd5: string;
446
- createDate: string;
447
- rev: number;
448
- userId: number;
449
- };
450
- /**
451
- * 是否快传
452
- */
453
- fileDataExists: number;
454
- }
455
- /**
456
- * @public
457
- */
458
- export interface UploadPartsInfoResponse extends UploadResponse {
459
- data: {
460
- uploadFileId: string;
461
- uploadedPartList: string;
462
- };
463
- }
464
- /**
465
- * @public
466
- */
467
- export type PartNumberKey = `partNumber_${number}`;
468
- /**
469
- * @public
470
- */
471
- export interface MultiUploadUrlsResponse extends UploadResponse {
472
- uploadUrls: {
473
- [key: PartNumberKey]: {
474
- requestURL: string;
475
- requestHeader: string;
476
- };
477
- };
478
- }
479
- /**
480
- * @public
481
- */
482
- export interface UploadCallbacks {
483
- onProgress?: (progress: number) => void;
484
- onComplete?: (response: any) => void;
485
- onError?: (error: Error) => void;
486
- }
487
- /**
488
- * @public
489
- */
490
- export type TaskType = 'DELETE' | 'MOVE' | 'COPY';
491
- /**
492
- * @public
493
- */
494
- export interface CreateBatchTaskRequest {
495
- type: TaskType;
496
- taskInfos: [
497
- {
498
- fileId: string;
499
- fileName?: string;
500
- isFolder: number;
501
- srcParentId?: string;
502
- }
503
- ];
504
- targetFolderId?: string;
505
- }
506
- /**
507
- * @public
508
- */
509
- export interface CreateFamilyBatchTaskRequest extends FamilyRequest, CreateBatchTaskRequest {
510
- }
package/dist/types.js DELETED
@@ -1,25 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.OrderByType = exports.MediaType = void 0;
4
- /**
5
- * 文件类型
6
- * @public
7
- */
8
- var MediaType;
9
- (function (MediaType) {
10
- MediaType[MediaType["ALL"] = 0] = "ALL";
11
- MediaType[MediaType["IMAGE"] = 1] = "IMAGE";
12
- MediaType[MediaType["MUSIC"] = 2] = "MUSIC";
13
- MediaType[MediaType["VIDEO"] = 3] = "VIDEO";
14
- MediaType[MediaType["TXT"] = 4] = "TXT";
15
- })(MediaType = exports.MediaType || (exports.MediaType = {}));
16
- /**
17
- * 排序类型
18
- * @public
19
- */
20
- var OrderByType;
21
- (function (OrderByType) {
22
- OrderByType[OrderByType["NAME"] = 1] = "NAME";
23
- OrderByType[OrderByType["SIZE"] = 2] = "SIZE";
24
- OrderByType[OrderByType["LAST_OP_TIME"] = 3] = "LAST_OP_TIME";
25
- })(OrderByType = exports.OrderByType || (exports.OrderByType = {}));
package/dist/util.d.ts DELETED
@@ -1,15 +0,0 @@
1
- import { BinaryToTextEncoding } from 'crypto';
2
- export declare const sortParameter: (data: any) => string;
3
- export declare const getSignature: (data: any) => string;
4
- export declare const rsaEncrypt: (publicKey: string, origData: string, encoding?: BinaryToTextEncoding) => string;
5
- export declare const aesECBEncrypt: (data: any, key: string) => string;
6
- export declare const hmacSha1: (data: any, key: any, encoding?: BinaryToTextEncoding) => string;
7
- export declare const hexToBase64: (data: any) => string;
8
- export declare const md5: (data: any) => string;
9
- export declare const randomString: (f: string) => string;
10
- export declare const partSize: (size: any) => number;
11
- export declare const calculateFileAndChunkMD5: (filePath: any, chunkSize?: number) => Promise<{
12
- fileMd5: string;
13
- chunkMd5s: string[];
14
- }>;
15
- export declare const asyncPool: (poolLimit: any, array: any, iteratorFn: any) => Promise<any[]>;
package/dist/util.js DELETED
@@ -1,119 +0,0 @@
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.asyncPool = exports.calculateFileAndChunkMD5 = exports.partSize = exports.randomString = exports.md5 = exports.hexToBase64 = exports.hmacSha1 = exports.aesECBEncrypt = exports.rsaEncrypt = exports.getSignature = exports.sortParameter = void 0;
7
- const crypto_1 = __importDefault(require("crypto"));
8
- const fs_1 = __importDefault(require("fs"));
9
- const sortParameter = (data) => {
10
- if (!data) {
11
- return '';
12
- }
13
- const e = Object.entries(data).map((t) => t.join('='));
14
- e.sort((a, b) => (a > b ? 1 : a < b ? -1 : 0));
15
- return e.join('&');
16
- };
17
- exports.sortParameter = sortParameter;
18
- const getSignature = (data) => {
19
- const parameter = (0, exports.sortParameter)(data);
20
- return crypto_1.default.createHash('md5').update(parameter).digest('hex');
21
- };
22
- exports.getSignature = getSignature;
23
- const rsaEncrypt = (publicKey, origData, encoding = 'hex') => {
24
- const key = `-----BEGIN PUBLIC KEY-----\n${publicKey}\n-----END PUBLIC KEY-----`;
25
- const encryptedData = crypto_1.default.publicEncrypt({
26
- key,
27
- padding: crypto_1.default.constants.RSA_PKCS1_PADDING
28
- }, Buffer.from(origData));
29
- return encryptedData.toString(encoding);
30
- };
31
- exports.rsaEncrypt = rsaEncrypt;
32
- const aesECBEncrypt = (data, key) => {
33
- const p = Object.entries(data)
34
- .map((t) => t.join('='))
35
- .join('&');
36
- const cipher = crypto_1.default.createCipheriv('aes-128-ecb', Buffer.from(key, 'utf8'), null);
37
- cipher.setAutoPadding(true);
38
- let encrypted = cipher.update(p, 'utf-8', 'hex');
39
- encrypted += cipher.final('hex');
40
- return encrypted;
41
- };
42
- exports.aesECBEncrypt = aesECBEncrypt;
43
- const hmacSha1 = (data, key, encoding = 'hex') => {
44
- const p = Object.entries(data)
45
- .map((t) => t.join('='))
46
- .join('&');
47
- const hmac = crypto_1.default.createHmac('sha1', key);
48
- hmac.update(p);
49
- return hmac.digest(encoding);
50
- };
51
- exports.hmacSha1 = hmacSha1;
52
- const hexToBase64 = (data) => {
53
- const buffer = Buffer.from(data, 'hex');
54
- return buffer.toString('base64');
55
- };
56
- exports.hexToBase64 = hexToBase64;
57
- const md5 = (data) => {
58
- return crypto_1.default.createHash('md5').update(data).digest('hex');
59
- };
60
- exports.md5 = md5;
61
- const randomString = (f) => {
62
- return f.replace(/[xy]/g, (e) => {
63
- var t = (16 * Math.random()) | 0, n = 'x' === e ? t : (3 & t) | 8;
64
- return n.toString(16);
65
- });
66
- };
67
- exports.randomString = randomString;
68
- const partSize = (size) => {
69
- const DEFAULT = 1024 * 1024 * 10; // 10 MiB
70
- if (size > DEFAULT * 2 * 999) {
71
- const chunkSize = size / 1999;
72
- const ratio = chunkSize / DEFAULT;
73
- const multiplier = Math.max(Math.ceil(ratio), 5);
74
- return multiplier * DEFAULT;
75
- }
76
- if (size > DEFAULT * 999) {
77
- return DEFAULT * 2; // 20 MiB
78
- }
79
- return DEFAULT;
80
- };
81
- exports.partSize = partSize;
82
- const calculateFileAndChunkMD5 = (filePath, chunkSize = 1024 * 1024) => {
83
- return new Promise((resolve, reject) => {
84
- const stream = fs_1.default.createReadStream(filePath, { highWaterMark: chunkSize });
85
- const fileHash = crypto_1.default.createHash('md5');
86
- const chunkMd5s = [];
87
- stream.on('data', (chunk) => {
88
- fileHash.update(chunk);
89
- const chunkHash = (0, exports.md5)(chunk);
90
- chunkMd5s.push(chunkHash.toUpperCase());
91
- });
92
- stream.on('end', () => {
93
- const fileMd5 = fileHash.digest('hex');
94
- stream.close();
95
- resolve({ fileMd5, chunkMd5s });
96
- });
97
- stream.on('error', (err) => {
98
- reject(err);
99
- });
100
- });
101
- };
102
- exports.calculateFileAndChunkMD5 = calculateFileAndChunkMD5;
103
- const asyncPool = async (poolLimit, array, iteratorFn) => {
104
- const ret = []; // 存储所有异步任务
105
- const executing = []; // 存储正在执行的异步任务
106
- for (const item of array) {
107
- const p = Promise.resolve().then(() => iteratorFn(item, array));
108
- ret.push(p);
109
- if (poolLimit <= array.length) {
110
- const e = p.then(() => executing.splice(executing.indexOf(e), 1));
111
- executing.push(e);
112
- if (executing.length >= poolLimit) {
113
- await Promise.race(executing);
114
- }
115
- }
116
- }
117
- return Promise.all(ret);
118
- };
119
- exports.asyncPool = asyncPool;