ddan-js 2.9.3 → 2.9.5

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.
Files changed (133) hide show
  1. package/bin/ddan-js.browser.js +1 -1
  2. package/bin/ddan-js.esm.js +1 -1
  3. package/bin/ddan-js.js +1 -1
  4. package/bin/types/browser.d.ts +3 -3
  5. package/bin/types/index.d.ts +4 -3
  6. package/bin/types/modules/fetch.d.ts +1 -1
  7. package/bin/types/modules/node/index.d.ts +2 -0
  8. package/package.json +18 -13
  9. package/bin/lib/browser.js +0 -111
  10. package/bin/lib/class/event.js +0 -104
  11. package/bin/lib/class/getset.js +0 -12
  12. package/bin/lib/class/icon.js +0 -94
  13. package/bin/lib/class/joker.js +0 -121
  14. package/bin/lib/class/kvalue.js +0 -29
  15. package/bin/lib/class/mapping.js +0 -82
  16. package/bin/lib/class/persist.js +0 -65
  17. package/bin/lib/class/pipeTask.js +0 -42
  18. package/bin/lib/class/pipeparallel.js +0 -24
  19. package/bin/lib/class/store.js +0 -87
  20. package/bin/lib/class/tracker.js +0 -125
  21. package/bin/lib/class/watermark.js +0 -63
  22. package/bin/lib/common/_Symbol.js +0 -5
  23. package/bin/lib/common/_freeGlobal.js +0 -5
  24. package/bin/lib/common/_object.js +0 -40
  25. package/bin/lib/common/_root.js +0 -10
  26. package/bin/lib/common/internal/asciiToArray.js +0 -13
  27. package/bin/lib/common/internal/castSlice.js +0 -18
  28. package/bin/lib/common/internal/createCaseFirst.js +0 -30
  29. package/bin/lib/common/internal/hasUnicode.js +0 -26
  30. package/bin/lib/common/internal/nodeTypes.js +0 -26
  31. package/bin/lib/common/internal/slice.js +0 -46
  32. package/bin/lib/common/internal/stringToArray.js +0 -18
  33. package/bin/lib/common/internal/unicodeToArray.js +0 -40
  34. package/bin/lib/common/internal/unicodeWords.js +0 -67
  35. package/bin/lib/index.js +0 -114
  36. package/bin/lib/modules/browser/ecdh.js +0 -124
  37. package/bin/lib/modules/browser/index.js +0 -4
  38. package/bin/lib/modules/cdn.js +0 -62
  39. package/bin/lib/modules/convert/base.js +0 -125
  40. package/bin/lib/modules/convert/base64.js +0 -114
  41. package/bin/lib/modules/convert/index.js +0 -99
  42. package/bin/lib/modules/convert/md5.js +0 -222
  43. package/bin/lib/modules/convert/pkcs.js +0 -16
  44. package/bin/lib/modules/convert/utf8.js +0 -106
  45. package/bin/lib/modules/crypto/base64.js +0 -14
  46. package/bin/lib/modules/crypto/const.js +0 -7
  47. package/bin/lib/modules/crypto/index.js +0 -30
  48. package/bin/lib/modules/crypto/rsa.js +0 -143
  49. package/bin/lib/modules/crypto/tea.js +0 -79
  50. package/bin/lib/modules/crypto/uuid.js +0 -34
  51. package/bin/lib/modules/css.js +0 -137
  52. package/bin/lib/modules/decorator.js +0 -14
  53. package/bin/lib/modules/fetch.js +0 -82
  54. package/bin/lib/modules/gbk.js +0 -46
  55. package/bin/lib/modules/hook/base.js +0 -60
  56. package/bin/lib/modules/hook/hooker.js +0 -39
  57. package/bin/lib/modules/hook/index.js +0 -49
  58. package/bin/lib/modules/hook/log.js +0 -54
  59. package/bin/lib/modules/hook/modules/bezier.js +0 -121
  60. package/bin/lib/modules/hook/modules/debounce.js +0 -127
  61. package/bin/lib/modules/hook/modules/mutex.js +0 -22
  62. package/bin/lib/modules/hook/modules/pipeline.js +0 -59
  63. package/bin/lib/modules/hook/modules/polling.js +0 -20
  64. package/bin/lib/modules/hook/modules/safeTask.js +0 -25
  65. package/bin/lib/modules/hook/modules/throttle.js +0 -30
  66. package/bin/lib/modules/html.js +0 -293
  67. package/bin/lib/modules/http/index.js +0 -171
  68. package/bin/lib/modules/http/interceptor.js +0 -22
  69. package/bin/lib/modules/list/base.js +0 -37
  70. package/bin/lib/modules/list/index.js +0 -90
  71. package/bin/lib/modules/logger.js +0 -55
  72. package/bin/lib/modules/math/index.js +0 -118
  73. package/bin/lib/modules/mini/diff.js +0 -97
  74. package/bin/lib/modules/mini/http/index.js +0 -155
  75. package/bin/lib/modules/mini/index.js +0 -71
  76. package/bin/lib/modules/node/aliyun.js +0 -156
  77. package/bin/lib/modules/node/brotli.js +0 -46
  78. package/bin/lib/modules/node/child.js +0 -18
  79. package/bin/lib/modules/node/ecdh-web.js +0 -11
  80. package/bin/lib/modules/node/ecdh.js +0 -115
  81. package/bin/lib/modules/node/file.js +0 -25
  82. package/bin/lib/modules/node/index.js +0 -11
  83. package/bin/lib/modules/node/proxy.js +0 -147
  84. package/bin/lib/modules/node/rsa-web.js +0 -19
  85. package/bin/lib/modules/node/socks5.js +0 -424
  86. package/bin/lib/modules/obj/index.js +0 -184
  87. package/bin/lib/modules/qs/base.js +0 -5
  88. package/bin/lib/modules/qs/decode.js +0 -45
  89. package/bin/lib/modules/qs/encode.js +0 -53
  90. package/bin/lib/modules/qs/index.js +0 -114
  91. package/bin/lib/modules/regex.js +0 -16
  92. package/bin/lib/modules/rsa.js +0 -18
  93. package/bin/lib/modules/rule/async-validator/index.js +0 -306
  94. package/bin/lib/modules/rule/async-validator/interface.js +0 -2
  95. package/bin/lib/modules/rule/async-validator/messages.js +0 -59
  96. package/bin/lib/modules/rule/async-validator/rule/enum.js +0 -13
  97. package/bin/lib/modules/rule/async-validator/rule/index.js +0 -16
  98. package/bin/lib/modules/rule/async-validator/rule/pattern.js +0 -27
  99. package/bin/lib/modules/rule/async-validator/rule/range.js +0 -54
  100. package/bin/lib/modules/rule/async-validator/rule/required.js +0 -12
  101. package/bin/lib/modules/rule/async-validator/rule/type.js +0 -98
  102. package/bin/lib/modules/rule/async-validator/rule/url.js +0 -55
  103. package/bin/lib/modules/rule/async-validator/rule/whitespace.js +0 -20
  104. package/bin/lib/modules/rule/async-validator/util.js +0 -255
  105. package/bin/lib/modules/rule/async-validator/validator/any.js +0 -16
  106. package/bin/lib/modules/rule/async-validator/validator/array.js +0 -19
  107. package/bin/lib/modules/rule/async-validator/validator/boolean.js +0 -20
  108. package/bin/lib/modules/rule/async-validator/validator/date.js +0 -31
  109. package/bin/lib/modules/rule/async-validator/validator/enum.js +0 -20
  110. package/bin/lib/modules/rule/async-validator/validator/float.js +0 -20
  111. package/bin/lib/modules/rule/async-validator/validator/index.js +0 -36
  112. package/bin/lib/modules/rule/async-validator/validator/integer.js +0 -20
  113. package/bin/lib/modules/rule/async-validator/validator/method.js +0 -19
  114. package/bin/lib/modules/rule/async-validator/validator/number.js +0 -23
  115. package/bin/lib/modules/rule/async-validator/validator/object.js +0 -19
  116. package/bin/lib/modules/rule/async-validator/validator/pattern.js +0 -19
  117. package/bin/lib/modules/rule/async-validator/validator/regexp.js +0 -19
  118. package/bin/lib/modules/rule/async-validator/validator/required.js +0 -10
  119. package/bin/lib/modules/rule/async-validator/validator/string.js +0 -24
  120. package/bin/lib/modules/rule/async-validator/validator/type.js +0 -20
  121. package/bin/lib/modules/rule/index.js +0 -67
  122. package/bin/lib/modules/string/index.js +0 -121
  123. package/bin/lib/modules/string/words.js +0 -33
  124. package/bin/lib/modules/time/const.js +0 -11
  125. package/bin/lib/modules/time/dtime.js +0 -132
  126. package/bin/lib/modules/time/frame.js +0 -49
  127. package/bin/lib/modules/time/index.js +0 -84
  128. package/bin/lib/typings/index.js +0 -2
  129. package/bin/lib/util/function.js +0 -33
  130. package/bin/lib/util/includes.js +0 -96
  131. package/bin/lib/util/index.js +0 -26
  132. package/bin/lib/util/is.js +0 -148
  133. package/bin/lib/util/to.js +0 -47
@@ -1,118 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- /**
4
- * 随机取值[0, max)
5
- * @param max 最大值
6
- */
7
- function random(max) {
8
- return Math.floor(Math.random() * max);
9
- }
10
- function randoms(max, count = 1, repeat = false) {
11
- const result = [];
12
- do {
13
- if (result.length >= count)
14
- break;
15
- if (!repeat && result.length >= max)
16
- break;
17
- const idx = random(max);
18
- if (!repeat) {
19
- if (!result.includes(idx)) {
20
- result.push(idx);
21
- }
22
- }
23
- else {
24
- result.push(idx);
25
- }
26
- } while (true);
27
- return result;
28
- }
29
- /**
30
- * 范围随机取值[min, max]
31
- * @param min 最小值
32
- * @param max 最大值
33
- */
34
- function randomRange(min, max) {
35
- return Math.floor(Math.random() * (max - min + 1) + min);
36
- }
37
- /**
38
- * 插值
39
- * @param start
40
- * @param end
41
- * @param t
42
- */
43
- function lerp(start, end, t) {
44
- return start * (1 - t) + end * t;
45
- }
46
- function strip(num, digits = 10) {
47
- return +parseFloat(Number(num).toExponential(digits));
48
- }
49
- function float(num, { digits = 2, fixed = false } = {}) {
50
- const str = strip(num).toFixed(digits);
51
- if (fixed || !digits)
52
- return +str;
53
- return +str.replace(/(\.[1-9]?)0+$/, '$1').replace(/\.$/, '');
54
- }
55
- const radiansToAngles = 180 / Math.PI;
56
- /**
57
- * 弧度转成角度
58
- * @param radians
59
- * @returns
60
- */
61
- function radian2degree(radians) {
62
- return radians * radiansToAngles;
63
- }
64
- /**
65
- * 角度转成弧度
66
- * @param degrees
67
- * @returns
68
- */
69
- function degree2radian(degrees) {
70
- return degrees / radiansToAngles;
71
- }
72
- function calcDataSize(data) {
73
- const result = {
74
- gb: 0,
75
- mb: 0,
76
- kb: 0,
77
- b: 0,
78
- total: data,
79
- desc: '',
80
- };
81
- const units = [
82
- { name: 'gb', divisor: 1 << 30 },
83
- { name: 'mb', divisor: 1 << 20 },
84
- { name: 'kb', divisor: 1 << 10 },
85
- { name: 'b', divisor: 1 },
86
- ];
87
- // 计算每个单位的数量
88
- for (const unit of units) {
89
- const value = Math.floor(data / unit.divisor);
90
- result[unit.name] = value;
91
- data -= value * unit.divisor;
92
- }
93
- // 计算简洁的描述
94
- if (result.gb > 0) {
95
- result.desc = (result.gb + result.mb / 1024).toFixed(2) + 'GB';
96
- }
97
- else if (result.mb > 0) {
98
- result.desc = (result.mb + result.kb / 1024).toFixed(2) + 'MB';
99
- }
100
- else if (result.kb > 0) {
101
- result.desc = (result.kb + result.b / 1024).toFixed(2) + 'KB';
102
- }
103
- else {
104
- result.desc = result.b + 'B';
105
- }
106
- return result;
107
- }
108
- exports.default = {
109
- random,
110
- randomRange,
111
- lerp,
112
- randoms,
113
- strip,
114
- float,
115
- radian2degree,
116
- degree2radian,
117
- calcDataSize,
118
- };
@@ -1,97 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const OBJECT_TYPE = "[object Object]";
4
- const ARRAY_TYPE = "[object Array]";
5
- const getType = (obj) => Object.prototype.toString.call(obj);
6
- const initPath = (data) => {
7
- if (getType(data) !== OBJECT_TYPE)
8
- return;
9
- for (let item in data) {
10
- if (/\w+\.\w+/g.test(item) && item.indexOf("[") === -1) {
11
- const arr = item.split(".");
12
- let result = data, len = arr.length;
13
- for (let i = 0; i < len - 1; i++) {
14
- const arrItem = arr[i];
15
- if (getType(result[arrItem]) !== OBJECT_TYPE) {
16
- result[arrItem] = {};
17
- }
18
- result = result[arrItem];
19
- }
20
- result[arr[len - 1]] = data[item];
21
- delete data[item];
22
- }
23
- }
24
- };
25
- const initData = (cur, pre, root = false) => {
26
- if (cur === pre)
27
- return;
28
- const curType = getType(cur), preType = getType(pre);
29
- if (curType !== preType)
30
- return;
31
- if (curType === ARRAY_TYPE && cur.length >= pre.length) {
32
- for (let i = 0; i < pre.length; i++) {
33
- initData(cur[i], pre[i]);
34
- }
35
- }
36
- else if (curType === OBJECT_TYPE && Object.keys(cur).length >= Object.keys(pre).length) {
37
- for (let key in pre) {
38
- if (!root && cur[key] === undefined) {
39
- cur[key] = null;
40
- }
41
- else {
42
- initData(cur[key], pre[key]);
43
- }
44
- }
45
- }
46
- };
47
- const doDiff = (cur, pre, target, path = "", root = false) => {
48
- if (cur === pre)
49
- return;
50
- const curRootType = getType(cur), preRootType = getType(pre);
51
- if (curRootType === ARRAY_TYPE && preRootType === curRootType && cur.length >= pre.length) {
52
- for (let i = 0; i < cur.length; i++) {
53
- doDiff(cur[i], pre[i], target, `${path}[${i}]`);
54
- }
55
- return;
56
- }
57
- if (curRootType === OBJECT_TYPE &&
58
- preRootType === curRootType &&
59
- (root || Object.keys(cur).length >= Object.keys(pre).length)) {
60
- const keys = Object.keys(cur);
61
- for (let key of keys) {
62
- const curVal = cur[key], preVal = pre[key];
63
- const curType = getType(curVal), preType = getType(preVal);
64
- if (curVal === preVal)
65
- continue;
66
- if (curType === ARRAY_TYPE && preType === curType && curVal.length >= preVal.length) {
67
- for (let i = 0; i < curVal.length; i++) {
68
- doDiff(curVal[i], preVal[i], target, `${path ? path + "." : ""}${key}[${i}]`);
69
- }
70
- continue;
71
- }
72
- if (curType === OBJECT_TYPE && preType === curType && Object.keys(curVal).length >= Object.keys(preVal).length) {
73
- for (let sKey in curVal) {
74
- doDiff(curVal[sKey], preVal[sKey], target, `${path ? path + "." : ""}${key}.${sKey}`);
75
- }
76
- continue;
77
- }
78
- target[`${path ? path + "." : ""}${key}`] = curVal;
79
- }
80
- return;
81
- }
82
- target[path] = cur;
83
- };
84
- /**
85
- * 计算并格式化差异值
86
- * @param data
87
- * @param prevData
88
- * @returns
89
- */
90
- function diff(data, prevData) {
91
- const target = {};
92
- initPath(data);
93
- initData(data, prevData, true);
94
- doDiff(data, prevData, target, "", true);
95
- return target;
96
- }
97
- exports.default = diff;
@@ -1,155 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const obj_1 = require("../../obj");
4
- const interceptor_1 = require("../../http/interceptor");
5
- class MiniHttp {
6
- // 接口配置
7
- reqConfig = {};
8
- handleRequest;
9
- handleEncrypt;
10
- handleDecrypt;
11
- handleError;
12
- // 拦截器
13
- interceptors = {
14
- request: new interceptor_1.default(),
15
- response: new interceptor_1.default(),
16
- };
17
- constructor(options) {
18
- const { reqConfig = {}, requestEncrypt, responseDecrypt, handleError, api } = options;
19
- this.reqConfig = reqConfig;
20
- this.handleEncrypt = requestEncrypt;
21
- this.handleDecrypt = responseDecrypt;
22
- this.handleError = handleError;
23
- this.handleRequest = api;
24
- }
25
- // 阻塞请求的锁id
26
- static blockId = "blockid";
27
- // 请求锁字典
28
- static requestLock = {};
29
- /**
30
- * 加锁
31
- * @param {string} id
32
- * @param {function} func
33
- */
34
- lockR(id, func) {
35
- MiniHttp.requestLock[id] = {
36
- lock: true,
37
- request: func(),
38
- };
39
- }
40
- /**
41
- * 解锁
42
- * @param {string} id
43
- */
44
- unlockR(id) {
45
- delete MiniHttp.requestLock[id];
46
- }
47
- /**
48
- * 根据URL和请求参数构造唯一标识符
49
- * @param {object} req
50
- */
51
- getIdFromReq(req) {
52
- const { url, data = {} } = req;
53
- return url + JSON.stringify(data);
54
- }
55
- /**
56
- * 根据URL构造唯一标识符
57
- * @param {object} req
58
- */
59
- getIdFromReqUrl(req) {
60
- return req.url || "";
61
- }
62
- /**
63
- * 请求函数
64
- * @param {object} _payload 小程序 wx.request 可用参数
65
- * @param {boolean} hasEncrypt 是否需要加密
66
- */
67
- _fetch(_payload, hasEncrypt) {
68
- let payload = _payload;
69
- if (hasEncrypt && this.handleEncrypt) {
70
- payload = this.handleEncrypt(_payload);
71
- }
72
- return new Promise((resolve, reject) => {
73
- this.handleRequest({
74
- ...payload,
75
- success: (_res) => {
76
- let res = _res;
77
- if (hasEncrypt && this.handleDecrypt) {
78
- res = this.handleDecrypt(_res);
79
- }
80
- resolve(res);
81
- },
82
- fail: (err) => {
83
- reject(err);
84
- },
85
- });
86
- });
87
- }
88
- /**
89
- * 请求{name}接口
90
- * @param {string} name
91
- * @param {object} payload
92
- */
93
- async request(name, payload) {
94
- const config = obj_1.default.copy(this.reqConfig[name]); // JSON.parse(JSON.stringify();
95
- // 进行请求参数的处理
96
- const { config: _, ...req } = await this.interceptors.request.invoke({
97
- url: config.url,
98
- data: payload || {},
99
- header: { "content-type": "application/json" },
100
- method: config.method ? config.method : "POST",
101
- responseType: "text",
102
- config,
103
- });
104
- let result;
105
- try {
106
- // 处理阻塞/去抖/普通请求
107
- if (_.model === "block") {
108
- this.lockR(MiniHttp.blockId, () => this._fetch(req, _.hasEncrypt));
109
- result = await MiniHttp.requestLock[MiniHttp.blockId].request;
110
- // note: 在具体的回调函数中主动 unlock
111
- }
112
- else {
113
- if (MiniHttp.requestLock[MiniHttp.blockId] &&
114
- MiniHttp.requestLock[MiniHttp.blockId].lock) {
115
- await MiniHttp.requestLock[MiniHttp.blockId].request;
116
- }
117
- //去抖模式
118
- if (_.model === "debounce" || _.model === "debounceUrl") {
119
- let id;
120
- if (_.model === "debounceUrl") {
121
- // 仅针对url去抖的临时方案
122
- id = this.getIdFromReqUrl(req);
123
- }
124
- else {
125
- id = this.getIdFromReq(req);
126
- }
127
- if (!MiniHttp.requestLock[id]) {
128
- this.lockR(id, () => this._fetch(req, _.hasEncrypt));
129
- }
130
- result = await MiniHttp.requestLock[id].request;
131
- this.unlockR(id);
132
- }
133
- else {
134
- result = await this._fetch(req, _.hasEncrypt);
135
- }
136
- }
137
- }
138
- catch (error) {
139
- this.handleError && this.handleError(error);
140
- }
141
- // 抛出response 拦截器 (由原来的直接抛出result改为抛出包含res、reqId、refetch的对象)
142
- // const res = this.interceptors.response.invoke(result);
143
- const res = this.interceptors.response.invoke({
144
- res: result,
145
- config,
146
- reqId: this.getIdFromReq(req),
147
- refetch: () => {
148
- // 重新请求
149
- return { sig: "REFETCH", result: this.request(name, payload || {}) };
150
- },
151
- });
152
- return res;
153
- }
154
- }
155
- exports.default = MiniHttp;
@@ -1,71 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const diff_1 = require("./diff");
4
- const hook_1 = require("../hook");
5
- const http_1 = require("./http");
6
- const obj_1 = require("../obj");
7
- /**
8
- * promise 化 wx 异步函数
9
- * @param miniapi
10
- * @returns
11
- */
12
- const promixify = (miniapi) => {
13
- if (typeof miniapi !== "function")
14
- return miniapi;
15
- return (args = {}) => new Promise((resolve, reject) => {
16
- miniapi(Object.assign(args, { success: resolve, fail: reject }));
17
- });
18
- };
19
- /**
20
- * 执行 wx 异步函数
21
- * @param func
22
- * @param args
23
- * @returns
24
- */
25
- const run = (func, args = {}) => {
26
- if (!func)
27
- return hook_1.default.run(func);
28
- return hook_1.default.run(promixify(func)(args));
29
- };
30
- /**
31
- * 格式化列表
32
- * @param lists
33
- * @param start
34
- * @param name
35
- * @returns
36
- */
37
- const formatList = (lists, start, name) => {
38
- return (lists || []).reduce((res, val, index) => ({ ...res, [`${name}[${start + index}]`]: val }), {});
39
- };
40
- /**
41
- * 字段简易规则
42
- * @param _
43
- * @param value
44
- * @returns
45
- */
46
- const ruleValidator = (_, value) => {
47
- if (!value)
48
- return false;
49
- if (Array.isArray(value)) {
50
- if (value.length <= 0)
51
- return false;
52
- return value.every((e) => !!e);
53
- }
54
- return true;
55
- };
56
- const setWatcher = (page) => {
57
- let data = page.data;
58
- let watch = page.watch;
59
- Object.keys(watch).forEach((item) => {
60
- let targetData = data;
61
- let keys = item.split(".");
62
- for (let i = 0; i < keys.length - 1; i++) {
63
- targetData = targetData[keys[i]];
64
- }
65
- let targetKey = keys[keys.length - 1];
66
- let watchFun = watch[item].handler || watch[item];
67
- let deep = watch[item].deep;
68
- obj_1.default.observe(targetData, targetKey, watchFun, page, deep);
69
- });
70
- };
71
- exports.default = { diff: diff_1.default, promixify, run, formatList, ruleValidator, Http: http_1.default, setWatcher };
@@ -1,156 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const ali_oss_1 = require("ali-oss");
4
- const pop_core_1 = require("@alicloud/pop-core");
5
- class Aliyun {
6
- bucket;
7
- accessKeyId;
8
- accessKeySecret;
9
- region;
10
- __oss;
11
- __cdn;
12
- constructor({ bucket, accessKeyId, accessKeySecret, region }) {
13
- this.bucket = bucket;
14
- this.accessKeyId = accessKeyId;
15
- this.accessKeySecret = accessKeySecret;
16
- this.region = region;
17
- this.__oss = this._getOSS();
18
- }
19
- get client() {
20
- if (!this.__oss) {
21
- this.__oss = this._getOSS();
22
- }
23
- return this.__oss;
24
- }
25
- _getOSS() {
26
- return new ali_oss_1.default({
27
- region: this.region,
28
- accessKeyId: this.accessKeyId,
29
- accessKeySecret: this.accessKeySecret,
30
- bucket: this.bucket,
31
- });
32
- }
33
- async read(name) {
34
- try {
35
- if (!(await this.exist(name)))
36
- return '';
37
- const result = await this.client.get(name);
38
- return result.content?.toString() || '';
39
- }
40
- catch (err) {
41
- console.log(`aliyun read ${name} error`, err);
42
- return undefined;
43
- }
44
- }
45
- async delete(name) {
46
- try {
47
- await this.client.delete(name);
48
- return true;
49
- }
50
- catch (err) {
51
- console.log(`aliyun delete ${name} error`, err);
52
- return false;
53
- }
54
- }
55
- async exist(name, options = {}) {
56
- try {
57
- await this.client.head(name, options);
58
- return true;
59
- }
60
- catch (err) {
61
- return false;
62
- }
63
- }
64
- async upload(name, localname) {
65
- try {
66
- if (!name || !localname)
67
- return false;
68
- await this.client.put(name, localname);
69
- return true;
70
- }
71
- catch (err) {
72
- console.log(`aliyun upload ${localname} error`, err);
73
- return false;
74
- }
75
- }
76
- async put(name, content) {
77
- try {
78
- if (!name || !content)
79
- return false;
80
- await this.client.put(name, Buffer.from(content));
81
- return true;
82
- }
83
- catch (err) {
84
- console.log(`aliyun put content ${name} error`, err);
85
- return false;
86
- }
87
- }
88
- async putSymlink(symlinkName, sourceName) {
89
- try {
90
- if (!symlinkName || !sourceName)
91
- return false;
92
- // @ts-ignore
93
- const res = await this.client.putSymlink(symlinkName, sourceName);
94
- return res;
95
- }
96
- catch (error) {
97
- return false;
98
- }
99
- }
100
- async browse(name, cb) {
101
- let token = undefined;
102
- let flag = false;
103
- const maxKeys = "50";
104
- const prefix = name.endsWith('/') ? name : `${name}/`;
105
- try {
106
- do {
107
- const result = await this.client.listV2({
108
- prefix,
109
- 'continuation-token': token,
110
- 'max-keys': maxKeys,
111
- }, {});
112
- for (let item of result.objects || []) {
113
- cb && (await cb(item.name));
114
- }
115
- // @ts-ignore
116
- token = result.nextContinuationToken;
117
- flag = result.isTruncated;
118
- } while (flag);
119
- return true;
120
- }
121
- catch (err) {
122
- console.log(`aliyun browse ${name} error`, err);
123
- return false;
124
- }
125
- }
126
- get cdn() {
127
- if (this.__cdn)
128
- return this.__cdn;
129
- this.__cdn = new pop_core_1.default({
130
- accessKeyId: this.accessKeyId,
131
- accessKeySecret: this.accessKeySecret,
132
- endpoint: 'https://cdn.aliyuncs.com',
133
- apiVersion: '2018-05-10',
134
- });
135
- return this.__cdn;
136
- }
137
- async refreshCDN(url, type = 'File') {
138
- try {
139
- let params = {
140
- ObjectPath: url,
141
- ObjectType: type,
142
- };
143
- const requestOption = {
144
- method: 'POST',
145
- formatParams: false,
146
- };
147
- await this.cdn.request('RefreshObjectCaches', params, requestOption);
148
- return true;
149
- }
150
- catch (err) {
151
- console.log(`aliyun refreshCDN ${url} err`, err);
152
- return false;
153
- }
154
- }
155
- }
156
- exports.default = Aliyun;
@@ -1,46 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.brotliDecompress = exports.brotliCompress = void 0;
4
- const zlib_1 = require("zlib");
5
- const convert_1 = require("../convert");
6
- /**
7
- * brotli 压缩
8
- * @param data
9
- * @returns
10
- */
11
- function brotliCompress(data, quality = zlib_1.default.constants.BROTLI_DEFAULT_QUALITY) {
12
- try {
13
- if (!data)
14
- return '';
15
- const uint8Array = convert_1.default.toUtf8Bytes(data);
16
- const compressBuff = zlib_1.default.brotliCompressSync(uint8Array, {
17
- params: {
18
- [zlib_1.default.constants.BROTLI_PARAM_QUALITY]: quality,
19
- },
20
- });
21
- return compressBuff.toString('base64');
22
- }
23
- catch (error) {
24
- return data || '';
25
- }
26
- }
27
- exports.brotliCompress = brotliCompress;
28
- /**
29
- * brotli 解压
30
- * @param data
31
- * @returns
32
- */
33
- function brotliDecompress(data) {
34
- try {
35
- if (!data)
36
- return '';
37
- const buff = convert_1.default.base64ToBytes(data);
38
- const decomporessBuff = zlib_1.default.brotliDecompressSync(buff);
39
- return decomporessBuff.toString('utf-8');
40
- }
41
- catch (error) {
42
- return data || '';
43
- }
44
- }
45
- exports.brotliDecompress = brotliDecompress;
46
- exports.default = { brotliCompress, brotliDecompress };
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const child_process_1 = require("child_process");
4
- const child_exec = (cmd) => {
5
- return new Promise((resolve) => {
6
- if (!cmd)
7
- return resolve([null, '']);
8
- (0, child_process_1.exec)(cmd, (err, stdout) => {
9
- if (err) {
10
- resolve([err || 'error', '']);
11
- }
12
- else {
13
- resolve([null, stdout || '']);
14
- }
15
- });
16
- });
17
- };
18
- exports.default = { child_exec };
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const crypto_1 = require("crypto");
4
- const ecdh_1 = require("../browser/ecdh");
5
- class EcdhWeb extends ecdh_1.default {
6
- constructor(curve = "P-256", keyFormat = "raw") {
7
- super(curve, keyFormat);
8
- this.__subtle = crypto_1.default.webcrypto.subtle;
9
- }
10
- }
11
- exports.default = EcdhWeb;