efront 3.19.2 → 3.20.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/coms/basic/cross_.js +34 -8
- package/coms/crypt/encode62.js +12 -6
- package/coms/zimoli/encode62.js +12 -6
- package/coms/zimoli/submit.js +1 -1
- package/package.json +1 -1
- package/public/efront.js +1 -1
package/coms/basic/cross_.js
CHANGED
|
@@ -6,10 +6,12 @@ function isFile(a) {
|
|
|
6
6
|
}
|
|
7
7
|
}
|
|
8
8
|
var base = null, location_href = null;
|
|
9
|
+
var encrypt = null;
|
|
9
10
|
// ///// 1 ////////// 2 /////// 3 //// 4 //
|
|
10
11
|
var domainReg = /^(?:(https?)\:)?\/\/(.*?)(?:\/(.*?))?([\?#].*)?$/i;
|
|
11
12
|
var setHost = function (host) {
|
|
12
13
|
base = host;
|
|
14
|
+
if (encrypt) encrypt = getCode.call(this);
|
|
13
15
|
};
|
|
14
16
|
var HeadersKeys = ["Content-Type"];
|
|
15
17
|
var cors_hosts = [];
|
|
@@ -26,7 +28,7 @@ function isChildPath(relative, path) {
|
|
|
26
28
|
return relative.replace(/^(.*\/)[^\/]*$/, path);
|
|
27
29
|
}
|
|
28
30
|
|
|
29
|
-
var getCrossUrl = function (domain, headers) {
|
|
31
|
+
var getCrossUrl = function (domain, headers, encrypt) {
|
|
30
32
|
if (notCross(domain)) return domain;
|
|
31
33
|
var originDomain = getDomainPath(domain);
|
|
32
34
|
var _cookies = getCookies(originDomain);
|
|
@@ -37,9 +39,13 @@ var getCrossUrl = function (domain, headers) {
|
|
|
37
39
|
extend(_headers, headers);
|
|
38
40
|
_headers = serialize(_headers);
|
|
39
41
|
if (_headers) _headers = "," + _headers;
|
|
40
|
-
|
|
42
|
+
var b = encrypt ? "!" : `*`;
|
|
43
|
+
domain = domain
|
|
41
44
|
.replace(/^(s?)(\/\/)/i, "http$1:$2")
|
|
42
|
-
.replace(domainReg,
|
|
45
|
+
.replace(domainReg, `$2${_headers}/$3$4`)
|
|
46
|
+
if (/^(https\:|s\/\/)/i.test(domain)) domain = b + domain;
|
|
47
|
+
if (encrypt) domain = encode62.timeencode(domain);
|
|
48
|
+
return base + b + domain;
|
|
43
49
|
};
|
|
44
50
|
function noop() { }
|
|
45
51
|
function toResponse() {
|
|
@@ -113,7 +119,7 @@ function cross_(jsonp, digest = noop, method, url, headers) {
|
|
|
113
119
|
}
|
|
114
120
|
else {
|
|
115
121
|
var nocross = notCross(url);
|
|
116
|
-
var callback = function () {
|
|
122
|
+
var callback = async function () {
|
|
117
123
|
var exposeHeaders = !nocross && xhr.getResponseHeader("access-control-expose-headers");
|
|
118
124
|
var exposeMap = {};
|
|
119
125
|
if (exposeHeaders) exposeHeaders.split(",").forEach(h => exposeMap[h.toLowerCase()] = true);
|
|
@@ -124,6 +130,13 @@ function cross_(jsonp, digest = noop, method, url, headers) {
|
|
|
124
130
|
addCookie(cookie, originDomain);
|
|
125
131
|
}
|
|
126
132
|
}
|
|
133
|
+
if (isencrypt && xhr.response) {
|
|
134
|
+
xhr = {
|
|
135
|
+
status: xhr.status,
|
|
136
|
+
response: encode62.safedecode(xhr.response || xhr.responseText, xhr.encrypt),
|
|
137
|
+
};
|
|
138
|
+
xhr.responseText = xhr.response;
|
|
139
|
+
};
|
|
127
140
|
switch (xhr.status) {
|
|
128
141
|
case 0:
|
|
129
142
|
if (!xhr.response) {
|
|
@@ -167,6 +180,10 @@ function cross_(jsonp, digest = noop, method, url, headers) {
|
|
|
167
180
|
var xhr = cross(callback, onerror);
|
|
168
181
|
var send = xhr.send;
|
|
169
182
|
xhr.toString = toResponse;
|
|
183
|
+
var isencrypt = /^[夏商周秦xszq]/i.test(method);
|
|
184
|
+
if (isencrypt) method = method.slice(1);
|
|
185
|
+
if (isencrypt && !encrypt) encrypt = cross.getCode();
|
|
186
|
+
xhr.encrypt = encrypt;
|
|
170
187
|
xhr.json = xhr.data = xhr.send = function (data, value) {
|
|
171
188
|
if (!jsondata && !(isEmpty(data) && isEmpty(value))) jsondata = data instanceof Array ? [] : {};
|
|
172
189
|
if (FormData && data instanceof FormData) {
|
|
@@ -202,8 +219,9 @@ function cross_(jsonp, digest = noop, method, url, headers) {
|
|
|
202
219
|
datas = serialize(jsondata, "&", "=");
|
|
203
220
|
}
|
|
204
221
|
};
|
|
205
|
-
|
|
206
|
-
|
|
222
|
+
var fire = async function () {
|
|
223
|
+
var code = await xhr.encrypt;
|
|
224
|
+
xhr.encrypt = code;
|
|
207
225
|
var isform = /^f/i.test(method);
|
|
208
226
|
if (isform) {
|
|
209
227
|
if (method === 'form') method = 'post';
|
|
@@ -236,12 +254,12 @@ function cross_(jsonp, digest = noop, method, url, headers) {
|
|
|
236
254
|
extend(realHeaders, _headers);
|
|
237
255
|
xhr.open(method, url);
|
|
238
256
|
} else {
|
|
239
|
-
xhr.open(method, getCrossUrl(url, _headers));
|
|
257
|
+
xhr.open(method, getCrossUrl(url, _headers, isencrypt));
|
|
240
258
|
}
|
|
241
259
|
if (is_gb2312) xhr.overrideMimeType("text/plain; charset=gb2312");
|
|
242
260
|
|
|
243
261
|
Object.keys(realHeaders).forEach(key => setRequestHeader.call(xhr, key, realHeaders[key]));
|
|
244
|
-
if (!isEmpty(datas)) send.call(xhr, datas);
|
|
262
|
+
if (!isEmpty(datas)) send.call(xhr, nocross || !isencrypt ? datas : encode62.safeencode(datas, code));
|
|
245
263
|
else send.call(xhr);
|
|
246
264
|
digest();
|
|
247
265
|
};
|
|
@@ -323,9 +341,17 @@ function reform(r, info, fire, cancel, e) {
|
|
|
323
341
|
function addReform(r) {
|
|
324
342
|
if (isFunction(r)) reforms.push(r);
|
|
325
343
|
}
|
|
344
|
+
function getCode() {
|
|
345
|
+
return new Promise((ok, oh) => {
|
|
346
|
+
this('get', base + "!").then((xhr) => { return ok(encode62.timedecode(xhr.response || xhr.responseText)) }, () => {
|
|
347
|
+
return oh('未连接到可加密的服务器!');
|
|
348
|
+
});
|
|
349
|
+
});
|
|
350
|
+
}
|
|
326
351
|
var bind = cross_.bind;
|
|
327
352
|
cross_.bind = function () {
|
|
328
353
|
var cross_ = bind.apply(this, arguments);
|
|
354
|
+
arguments[0].getCode = getCode.bind(cross_);
|
|
329
355
|
extend(cross_, {
|
|
330
356
|
requests,
|
|
331
357
|
abortAll() {
|
package/coms/crypt/encode62.js
CHANGED
|
@@ -28,13 +28,20 @@ Object.assign(encode62, {
|
|
|
28
28
|
src,
|
|
29
29
|
map,
|
|
30
30
|
time_delta: parseInt("zzzzz", 36),
|
|
31
|
+
safeencode(string, sign, offset) {
|
|
32
|
+
string = encodeURIComponent(string).replace(/\./g, '..').replace(/[\!'\(\)~]/g, a => escape(a)).replace(/%/g, '.');
|
|
33
|
+
return this.encode62(string, sign, offset);
|
|
34
|
+
},
|
|
35
|
+
safedecode(string, sign, offset) {
|
|
36
|
+
string = this.decode62(string, sign, offset).replace(/\.\.?/g, a => a === '.' ? "%" : ".");
|
|
37
|
+
return decodeURIComponent(string);
|
|
38
|
+
},
|
|
31
39
|
timedecode(string) {
|
|
32
40
|
var { time_delta } = this;
|
|
33
41
|
var time_rest = string.slice(string.length - time_delta.toString(36).length, string.length);
|
|
34
42
|
var time_start = parseInt((new Date() - parseInt(time_rest, 36)) / time_delta) * time_delta;
|
|
35
43
|
var time_stamp = time_start + parseInt(time_rest, 36);
|
|
36
|
-
|
|
37
|
-
return decodeURIComponent(string);
|
|
44
|
+
return this.safedecode(string.slice(0, string.length - time_delta.toString(36).length), time_stamp.toString(36));
|
|
38
45
|
},
|
|
39
46
|
timeencode(string) {
|
|
40
47
|
var { time_delta } = this;
|
|
@@ -43,8 +50,7 @@ Object.assign(encode62, {
|
|
|
43
50
|
var time_rest = time_stamp % time_delta;
|
|
44
51
|
var time_rest_str = time_rest.toString(36);
|
|
45
52
|
var time_delta_str = time_delta.toString(36);
|
|
46
|
-
|
|
47
|
-
return this.encode62(string, time_stamp.toString(36)) + repeat("0", time_delta_str.length - time_rest_str.length) + time_rest_str;
|
|
53
|
+
return this.safeencode(string, time_stamp.toString(36)) + repeat("0", time_delta_str.length - time_rest_str.length) + time_rest_str;
|
|
48
54
|
},
|
|
49
55
|
timeupdate(string) {
|
|
50
56
|
var { time_delta } = this;
|
|
@@ -57,7 +63,7 @@ Object.assign(encode62, {
|
|
|
57
63
|
return this.timeencode(this.timedecode(string));
|
|
58
64
|
}
|
|
59
65
|
},
|
|
60
|
-
encode62(data, sign) {
|
|
66
|
+
encode62(data, sign, offset = 0) {
|
|
61
67
|
if (!sign) return data;
|
|
62
68
|
var result = String(data);
|
|
63
69
|
sign = String(sign);
|
|
@@ -65,7 +71,7 @@ Object.assign(encode62, {
|
|
|
65
71
|
var result = result.replace(/\w/g, function (w, cx) {
|
|
66
72
|
var code = map[w];
|
|
67
73
|
if (typeof code !== "number") return w;
|
|
68
|
-
var s = code ^ (sign.charCodeAt(cx % sign.length) % src.length);
|
|
74
|
+
var s = code ^ (sign.charCodeAt((offset + cx) % sign.length) % src.length);
|
|
69
75
|
if (s >= src.length) return w;
|
|
70
76
|
return src[s];
|
|
71
77
|
});
|
package/coms/zimoli/encode62.js
CHANGED
|
@@ -18,13 +18,20 @@ var encode62 = {
|
|
|
18
18
|
}
|
|
19
19
|
return buff.join('');
|
|
20
20
|
},
|
|
21
|
+
safeencode(string, sign, offset) {
|
|
22
|
+
string = encodeURIComponent(string).replace(/\./g, '..').replace(/[\!'\(\)~]/g, a => escape(a)).replace(/%/g, '.');
|
|
23
|
+
return this.encode(string, sign, offset);
|
|
24
|
+
},
|
|
25
|
+
safedecode(string, sign, offset) {
|
|
26
|
+
string = this.encode(string, sign, offset).replace(/\.\.?/g, a => a === '.' ? "%" : ".");
|
|
27
|
+
return decodeURIComponent(string);
|
|
28
|
+
},
|
|
21
29
|
timedecode(string) {
|
|
22
30
|
var { time_delta } = this;
|
|
23
31
|
var time_rest = string.slice(string.length - time_delta.toString(36).length, string.length);
|
|
24
32
|
var time_start = parseInt((new Date() - parseInt(time_rest, 36)) / time_delta) * time_delta;
|
|
25
33
|
var time_stamp = time_start + parseInt(time_rest, 36);
|
|
26
|
-
|
|
27
|
-
return decodeURIComponent(string);
|
|
34
|
+
return this.safedecode(string.slice(0, string.length - time_delta.toString(36).length), time_stamp.toString(36));
|
|
28
35
|
},
|
|
29
36
|
timeencode(string) {
|
|
30
37
|
var { time_delta } = this;
|
|
@@ -35,8 +42,7 @@ var encode62 = {
|
|
|
35
42
|
var time_rest = time_stamp % time_delta;
|
|
36
43
|
var time_rest_str = time_rest.toString(36);
|
|
37
44
|
var time_delta_str = time_delta.toString(36);
|
|
38
|
-
|
|
39
|
-
return this.encode(string, time_stamp.toString(36)) + repeat("0", time_delta_str.length - time_rest_str.length) + time_rest_str;
|
|
45
|
+
return this.safeencode(string, time_stamp.toString(36)) + repeat("0", time_delta_str.length - time_rest_str.length) + time_rest_str;
|
|
40
46
|
},
|
|
41
47
|
timeupdate(string) {
|
|
42
48
|
var { time_delta } = this;
|
|
@@ -50,7 +56,7 @@ var encode62 = {
|
|
|
50
56
|
return this.timeencode(this.timedecode(string));
|
|
51
57
|
}
|
|
52
58
|
},
|
|
53
|
-
encode(data, sign) {
|
|
59
|
+
encode(data, sign, offset = 0) {
|
|
54
60
|
if (!sign) return data;
|
|
55
61
|
var result = String(data);
|
|
56
62
|
sign = String(sign);
|
|
@@ -58,7 +64,7 @@ var encode62 = {
|
|
|
58
64
|
var result = result.replace(/\w/g, function (w, cx) {
|
|
59
65
|
var code = map[w];
|
|
60
66
|
if (!isNumber(code)) return w;
|
|
61
|
-
var s = code ^ (sign.charCodeAt(cx % sign.length) % src.length);
|
|
67
|
+
var s = code ^ (sign.charCodeAt((offset + cx) % sign.length) % src.length);
|
|
62
68
|
if (s >= src.length) return w;
|
|
63
69
|
return src[s];
|
|
64
70
|
});
|
package/coms/zimoli/submit.js
CHANGED