@jayfong/x-server 1.30.1 → 1.30.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/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [1.30.2](https://github.com/jfWorks/x-server/compare/v1.30.1...v1.30.2) (2022-05-26)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * use lz-string ([bf0e9af](https://github.com/jfWorks/x-server/commit/bf0e9af411c86ebd2b6527fc75be1476559c25fa))
11
+
5
12
  ### [1.30.1](https://github.com/jfWorks/x-server/compare/v1.30.0...v1.30.1) (2022-05-26)
6
13
 
7
14
 
@@ -1,29 +1,26 @@
1
1
  "use strict";
2
2
 
3
- exports.__esModule = true;
4
- exports.XServerClientHelper = void 0;
5
-
6
- var _vtils = require("vtils");
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
7
4
 
8
- var _shorty = require("./utils/shorty");
5
+ exports.__esModule = true;
6
+ exports.processXServerResponse = processXServerResponse;
9
7
 
10
- class XServerClientHelper {
11
- static processResponse(data) {
12
- // 处理混淆
13
- // _#
14
- const shortyKey = String.fromCharCode(95) + String.fromCharCode(35);
8
+ var _lzString = _interopRequireDefault(require("lz-string"));
15
9
 
16
- if (data && typeof data === 'object' && data[shortyKey] != null) {
17
- try {
18
- data = JSON.parse(new _shorty.Shorty().decode(data[shortyKey]));
19
- } catch {}
20
- } // 处理数组打包
10
+ var _vtils = require("vtils");
21
11
 
12
+ // _#
13
+ const obfuscateKey = [90, 30].map(v => String.fromCharCode(v + 5)).join('');
22
14
 
23
- data = _vtils.DataPacker.unpackIfNeeded(data);
24
- return data;
25
- }
15
+ function processXServerResponse(data) {
16
+ // 处理混淆
17
+ if (data && typeof data === 'object' && data[obfuscateKey] != null) {
18
+ try {
19
+ data = JSON.parse(_lzString.default.decompress(data[obfuscateKey]));
20
+ } catch {}
21
+ } // 处理数组打包
26
22
 
27
- }
28
23
 
29
- exports.XServerClientHelper = XServerClientHelper;
24
+ data = _vtils.DataPacker.unpackIfNeeded(data);
25
+ return data;
26
+ }
@@ -1,16 +1,18 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+
3
5
  exports.__esModule = true;
4
6
  exports.Handler = void 0;
5
7
 
8
+ var _lzString = _interopRequireDefault(require("lz-string"));
9
+
6
10
  var _vtils = require("vtils");
7
11
 
8
12
  var _dispose = require("../services/dispose");
9
13
 
10
14
  var _http_error = require("../core/http_error");
11
15
 
12
- var _shorty = require("../utils/shorty");
13
-
14
16
  var _validator = require("vtils/validator");
15
17
 
16
18
  class Handler {
@@ -59,7 +61,7 @@ class Handler {
59
61
 
60
62
  if (this.options.responseDataObfuscate) {
61
63
  res = {
62
- '_#': new _shorty.Shorty().encode(JSON.stringify(res))
64
+ '_#': _lzString.default.compress(JSON.stringify(res))
63
65
  };
64
66
  }
65
67
 
@@ -1,3 +1 @@
1
- export declare class XServerClientHelper {
2
- static processResponse<T>(data: any): T;
3
- }
1
+ export declare function processXServerResponse<T>(data: any): T;
@@ -1,20 +1,16 @@
1
- import { DataPacker } from 'vtils';
2
- import { Shorty } from "./utils/shorty";
3
- export class XServerClientHelper {
4
- static processResponse(data) {
5
- // 处理混淆
6
- // _#
7
- const shortyKey = String.fromCharCode(95) + String.fromCharCode(35);
1
+ import LZString from 'lz-string';
2
+ import { DataPacker } from 'vtils'; // _#
8
3
 
9
- if (data && typeof data === 'object' && data[shortyKey] != null) {
10
- try {
11
- data = JSON.parse(new Shorty().decode(data[shortyKey]));
12
- } catch {}
13
- } // 处理数组打包
4
+ const obfuscateKey = [90, 30].map(v => String.fromCharCode(v + 5)).join('');
5
+ export function processXServerResponse(data) {
6
+ // 处理混淆
7
+ if (data && typeof data === 'object' && data[obfuscateKey] != null) {
8
+ try {
9
+ data = JSON.parse(LZString.decompress(data[obfuscateKey]));
10
+ } catch {}
11
+ } // 处理数组打包
14
12
 
15
13
 
16
- data = DataPacker.unpackIfNeeded(data);
17
- return data;
18
- }
19
-
14
+ data = DataPacker.unpackIfNeeded(data);
15
+ return data;
20
16
  }
@@ -1,7 +1,7 @@
1
+ import LZString from 'lz-string';
1
2
  import { DataPacker } from 'vtils';
2
3
  import { DisposeService } from "../services/dispose";
3
4
  import { HttpError } from "../core/http_error";
4
- import { Shorty } from "../utils/shorty";
5
5
  import { yup } from 'vtils/validator';
6
6
  export class Handler {
7
7
  constructor(options) {
@@ -49,7 +49,7 @@ export class Handler {
49
49
 
50
50
  if (this.options.responseDataObfuscate) {
51
51
  res = {
52
- '_#': new Shorty().encode(JSON.stringify(res))
52
+ '_#': LZString.compress(JSON.stringify(res))
53
53
  };
54
54
  }
55
55
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jayfong/x-server",
3
- "version": "1.30.1",
3
+ "version": "1.30.2",
4
4
  "license": "ISC",
5
5
  "sideEffects": false,
6
6
  "main": "lib/_cjs/index.js",
@@ -56,6 +56,7 @@
56
56
  "http-errors": "^1.8.1",
57
57
  "ioredis": "^4.28.5",
58
58
  "jsonwebtoken": "^8.5.1",
59
+ "lz-string": "^1.4.4",
59
60
  "mini-svg-data-uri": "^1.4.4",
60
61
  "mint-filter": "^3.0.1",
61
62
  "node-ssh": "^12.0.4",
@@ -76,6 +77,7 @@
76
77
  "@types/fs-extra": "^9.0.13",
77
78
  "@types/ioredis": "^4.28.10",
78
79
  "@types/json-schema": "^7.0.11",
80
+ "@types/lz-string": "^1.3.34",
79
81
  "eslint": "^7.32.0",
80
82
  "haoma": "^3.6.4",
81
83
  "husky": "^4.3.8",
@@ -1,236 +0,0 @@
1
- "use strict";
2
-
3
- exports.__esModule = true;
4
- exports.Shorty = void 0;
5
-
6
- /* eslint-disable */
7
- // @ts-nocheck
8
- // https://github.com/enkimute/shorty.js
9
- function ShortyRaw(tokensize) {
10
- this.tokensize = tokensize || 10;
11
- this.reset(true);
12
- }
13
-
14
- ShortyRaw.prototype.reset = function (full) {
15
- if (full === true) {
16
- this.nodes = [{
17
- up: 0,
18
- weight: 0
19
- }];
20
- this.nyt = 0;
21
- this.nodecount = 0;
22
- }
23
-
24
- this.data = '';
25
- this.curpos = 0;
26
- this.bitCount = 7;
27
- this.bitChar = 0;
28
- };
29
-
30
- ShortyRaw.prototype.findNode = function (x) {
31
- for (let i = this.nodes.length - 1; i > 0; i--) if (typeof this.nodes[i].symbol != 'undefined' && this.nodes[i].symbol == x) return i;
32
-
33
- return 0;
34
- };
35
-
36
- ShortyRaw.prototype.addNode = function (token) {
37
- if (this.nodecount >= 2046) return 0;
38
- this.nodes[++this.nodecount] = {
39
- up: this.nyt,
40
- symbol: token,
41
- weight: 1
42
- };
43
- this.nodes[++this.nodecount] = {
44
- up: this.nyt,
45
- weight: 0
46
- };
47
- this.nodes[this.nyt].weight += 1;
48
- this.nyt = this.nodecount;
49
- if (this.nodes[this.nodecount - 2].up != this.nodecount - 2) this.balanceNode(this.nodes[this.nodecount - 2].up);
50
- return this.nodecount - 2;
51
- };
52
-
53
- ShortyRaw.prototype.swapNode = function (a, b) {
54
- const t = this.nodes[a].symbol;
55
- const u = this.nodes[b].symbol;
56
- const v = this.nodes[a].weight;
57
- this.nodes[a].symbol = u;
58
- this.nodes[b].symbol = t;
59
- this.nodes[a].weight = this.nodes[b].weight;
60
- this.nodes[b].weight = v;
61
-
62
- for (let n = this.nodes.length - 1; n > 0; n--) if (this.nodes[n].up == a) this.nodes[n].up = b;else if (this.nodes[n].up == b) this.nodes[n].up = a;
63
- };
64
-
65
- ShortyRaw.prototype.balanceNode = function (node) {
66
- while (true) {
67
- let minnr = node;
68
- const weight = this.nodes[node].weight;
69
-
70
- while (minnr > 1 && this.nodes[minnr - 1].weight == weight) minnr--;
71
-
72
- if (minnr != node && minnr != this.nodes[node].up) {
73
- this.swapNode(minnr, node);
74
- node = minnr;
75
- }
76
-
77
- this.nodes[node].weight++;
78
- if (this.nodes[node].up == node) return;
79
- node = this.nodes[node].up;
80
- }
81
- };
82
-
83
- ShortyRaw.prototype.emitNode = function (node) {
84
- const emit = [];
85
-
86
- while (node != 0) {
87
- emit.unshift(node % 2);
88
- node = this.nodes[node].up;
89
- }
90
-
91
- for (let e = 0; e < emit.length; e++) this.emitBit(emit[e]);
92
- };
93
-
94
- ShortyRaw.prototype.emitNyt = function (token) {
95
- this.emitNode(this.nyt);
96
- const ll = token.length - 1;
97
- if (this.tokensize > 8) this.emitBit(ll & 8);
98
- if (this.tokensize > 4) this.emitBit(ll & 4);
99
- if (this.tokensize > 2) this.emitBit(ll & 2);
100
- if (this.tokensize > 1) this.emitBit(ll & 1);
101
-
102
- for (let cc = 0; cc < token.length; cc++) this.emitByte(token.charCodeAt(cc));
103
-
104
- return this.nyt;
105
- };
106
-
107
- ShortyRaw.prototype.readNode = function () {
108
- if (this.nyt == 0) {
109
- var len = (this.tokensize > 8 ? this.readBit() * 8 : 0) + (this.tokensize > 4 ? this.readBit() * 4 : 0) + (this.tokensize > 2 ? this.readBit() * 2 : 0) + (this.tokensize > 1 ? this.readBit() : 0) + 1;
110
- var stream = '';
111
-
112
- while (len--) stream += this.readByte();
113
-
114
- return stream;
115
- }
116
-
117
- let node = 0;
118
-
119
- while (true) {
120
- const bit = this.readBit();
121
- if (this.nodes[node].symbol == undefined) for (let m = 0;; m++) if (this.nodes[m].up == node && m != node && m % 2 == bit) {
122
- node = m;
123
- break;
124
- }
125
-
126
- if (this.nodes[node].symbol != undefined || this.nodes[node].weight == 0) {
127
- if (this.nodes[node].weight) return this.nodes[node].symbol;
128
- var len = (this.tokensize > 8 ? this.readBit() * 8 : 0) + (this.tokensize > 4 ? this.readBit() * 4 : 0) + (this.tokensize > 2 ? this.readBit() * 2 : 0) + (this.tokensize > 1 ? this.readBit() : 0) + 1;
129
- var stream = '';
130
-
131
- while (len--) stream += this.readByte();
132
-
133
- return stream;
134
- }
135
- }
136
- };
137
-
138
- ShortyRaw.prototype.emitBit = function (bit) {
139
- if (bit) this.bitChar += 1 << this.bitCount;
140
-
141
- if (--this.bitCount < 0) {
142
- this.data += String.fromCharCode(this.bitChar);
143
- this.bitCount = 7;
144
- this.bitChar = 0;
145
- }
146
- };
147
-
148
- ShortyRaw.prototype.emitByte = function (byte) {
149
- for (let i = 7; i >= 0; i--) {
150
- this.emitBit(byte >> i & 1);
151
- }
152
- };
153
-
154
- ShortyRaw.prototype.readBit = function () {
155
- if (this.curpos == this.data.length * 8) throw 'done';
156
- const bit = this.data.charCodeAt(this.curpos >> 3) >> (7 - this.curpos & 7) & 1;
157
- this.curpos++;
158
- return bit;
159
- };
160
-
161
- ShortyRaw.prototype.readByte = function () {
162
- res = 0;
163
-
164
- for (let i = 0; i < 8; i++) res += (128 >> i) * this.readBit();
165
-
166
- return String.fromCharCode(res);
167
- };
168
-
169
- ShortyRaw.prototype.deflate = function (data) {
170
- let token,
171
- l = data.length,
172
- i,
173
- x;
174
- this.reset();
175
-
176
- for (i = 0; i < l; i++) {
177
- token = data[i];
178
-
179
- if (this.tokensize > 1) {
180
- if (/[a-zA-Z]/.test(token)) while (i + 1 < l && token.length < this.tokensize && /[a-zA-Z]/.test(data[i + 1])) {
181
- token += data[++i];
182
- } else if (/[=\[\],\.:\"'\{\}]/.test(token)) while (i + 1 < l && token.length < this.tokensize && /[=\[\],\.:\"'\{\}]/.test(data[i + 1])) {
183
- i++;
184
- token += data[i];
185
- } //joe hl patch "
186
- }
187
-
188
- x = this.findNode(token);
189
-
190
- if (!x) {
191
- this.emitNyt(token);
192
- x = this.addNode(token);
193
- } else {
194
- this.emitNode(x);
195
- this.balanceNode(x);
196
- }
197
- }
198
-
199
- if (this.bitCount != 7) {
200
- const oldlength = this.data.length;
201
- this.emitNode(this.nyt);
202
- if (oldlength == this.data.length) this.emitByte(0);
203
- }
204
-
205
- return this.data;
206
- };
207
-
208
- ShortyRaw.prototype.inflate = function (data) {
209
- this.reset();
210
- this.data = data;
211
- let output = '';
212
-
213
- try {
214
- for (let i = 0; i >= 0; i++) {
215
- const token = this.readNode();
216
- output += token;
217
- const node = this.findNode(token);
218
- if (!node) this.addNode(token);else this.balanceNode(node);
219
- }
220
- } catch (e) {}
221
-
222
- return output;
223
- };
224
-
225
- class Shorty extends ShortyRaw {
226
- encode(data) {
227
- return this.deflate(data);
228
- }
229
-
230
- decode(data) {
231
- return this.inflate(data);
232
- }
233
-
234
- }
235
-
236
- exports.Shorty = Shorty;
@@ -1,6 +0,0 @@
1
- declare function ShortyRaw(tokensize: any): void;
2
- export declare class Shorty extends ShortyRaw {
3
- encode(data: string): string;
4
- decode(data: string): string;
5
- }
6
- export {};
@@ -1,229 +0,0 @@
1
- /* eslint-disable */
2
- // @ts-nocheck
3
- // https://github.com/enkimute/shorty.js
4
- function ShortyRaw(tokensize) {
5
- this.tokensize = tokensize || 10;
6
- this.reset(true);
7
- }
8
-
9
- ShortyRaw.prototype.reset = function (full) {
10
- if (full === true) {
11
- this.nodes = [{
12
- up: 0,
13
- weight: 0
14
- }];
15
- this.nyt = 0;
16
- this.nodecount = 0;
17
- }
18
-
19
- this.data = '';
20
- this.curpos = 0;
21
- this.bitCount = 7;
22
- this.bitChar = 0;
23
- };
24
-
25
- ShortyRaw.prototype.findNode = function (x) {
26
- for (let i = this.nodes.length - 1; i > 0; i--) if (typeof this.nodes[i].symbol != 'undefined' && this.nodes[i].symbol == x) return i;
27
-
28
- return 0;
29
- };
30
-
31
- ShortyRaw.prototype.addNode = function (token) {
32
- if (this.nodecount >= 2046) return 0;
33
- this.nodes[++this.nodecount] = {
34
- up: this.nyt,
35
- symbol: token,
36
- weight: 1
37
- };
38
- this.nodes[++this.nodecount] = {
39
- up: this.nyt,
40
- weight: 0
41
- };
42
- this.nodes[this.nyt].weight += 1;
43
- this.nyt = this.nodecount;
44
- if (this.nodes[this.nodecount - 2].up != this.nodecount - 2) this.balanceNode(this.nodes[this.nodecount - 2].up);
45
- return this.nodecount - 2;
46
- };
47
-
48
- ShortyRaw.prototype.swapNode = function (a, b) {
49
- const t = this.nodes[a].symbol;
50
- const u = this.nodes[b].symbol;
51
- const v = this.nodes[a].weight;
52
- this.nodes[a].symbol = u;
53
- this.nodes[b].symbol = t;
54
- this.nodes[a].weight = this.nodes[b].weight;
55
- this.nodes[b].weight = v;
56
-
57
- for (let n = this.nodes.length - 1; n > 0; n--) if (this.nodes[n].up == a) this.nodes[n].up = b;else if (this.nodes[n].up == b) this.nodes[n].up = a;
58
- };
59
-
60
- ShortyRaw.prototype.balanceNode = function (node) {
61
- while (true) {
62
- let minnr = node;
63
- const weight = this.nodes[node].weight;
64
-
65
- while (minnr > 1 && this.nodes[minnr - 1].weight == weight) minnr--;
66
-
67
- if (minnr != node && minnr != this.nodes[node].up) {
68
- this.swapNode(minnr, node);
69
- node = minnr;
70
- }
71
-
72
- this.nodes[node].weight++;
73
- if (this.nodes[node].up == node) return;
74
- node = this.nodes[node].up;
75
- }
76
- };
77
-
78
- ShortyRaw.prototype.emitNode = function (node) {
79
- const emit = [];
80
-
81
- while (node != 0) {
82
- emit.unshift(node % 2);
83
- node = this.nodes[node].up;
84
- }
85
-
86
- for (let e = 0; e < emit.length; e++) this.emitBit(emit[e]);
87
- };
88
-
89
- ShortyRaw.prototype.emitNyt = function (token) {
90
- this.emitNode(this.nyt);
91
- const ll = token.length - 1;
92
- if (this.tokensize > 8) this.emitBit(ll & 8);
93
- if (this.tokensize > 4) this.emitBit(ll & 4);
94
- if (this.tokensize > 2) this.emitBit(ll & 2);
95
- if (this.tokensize > 1) this.emitBit(ll & 1);
96
-
97
- for (let cc = 0; cc < token.length; cc++) this.emitByte(token.charCodeAt(cc));
98
-
99
- return this.nyt;
100
- };
101
-
102
- ShortyRaw.prototype.readNode = function () {
103
- if (this.nyt == 0) {
104
- var len = (this.tokensize > 8 ? this.readBit() * 8 : 0) + (this.tokensize > 4 ? this.readBit() * 4 : 0) + (this.tokensize > 2 ? this.readBit() * 2 : 0) + (this.tokensize > 1 ? this.readBit() : 0) + 1;
105
- var stream = '';
106
-
107
- while (len--) stream += this.readByte();
108
-
109
- return stream;
110
- }
111
-
112
- let node = 0;
113
-
114
- while (true) {
115
- const bit = this.readBit();
116
- if (this.nodes[node].symbol == undefined) for (let m = 0;; m++) if (this.nodes[m].up == node && m != node && m % 2 == bit) {
117
- node = m;
118
- break;
119
- }
120
-
121
- if (this.nodes[node].symbol != undefined || this.nodes[node].weight == 0) {
122
- if (this.nodes[node].weight) return this.nodes[node].symbol;
123
- var len = (this.tokensize > 8 ? this.readBit() * 8 : 0) + (this.tokensize > 4 ? this.readBit() * 4 : 0) + (this.tokensize > 2 ? this.readBit() * 2 : 0) + (this.tokensize > 1 ? this.readBit() : 0) + 1;
124
- var stream = '';
125
-
126
- while (len--) stream += this.readByte();
127
-
128
- return stream;
129
- }
130
- }
131
- };
132
-
133
- ShortyRaw.prototype.emitBit = function (bit) {
134
- if (bit) this.bitChar += 1 << this.bitCount;
135
-
136
- if (--this.bitCount < 0) {
137
- this.data += String.fromCharCode(this.bitChar);
138
- this.bitCount = 7;
139
- this.bitChar = 0;
140
- }
141
- };
142
-
143
- ShortyRaw.prototype.emitByte = function (byte) {
144
- for (let i = 7; i >= 0; i--) {
145
- this.emitBit(byte >> i & 1);
146
- }
147
- };
148
-
149
- ShortyRaw.prototype.readBit = function () {
150
- if (this.curpos == this.data.length * 8) throw 'done';
151
- const bit = this.data.charCodeAt(this.curpos >> 3) >> (7 - this.curpos & 7) & 1;
152
- this.curpos++;
153
- return bit;
154
- };
155
-
156
- ShortyRaw.prototype.readByte = function () {
157
- res = 0;
158
-
159
- for (let i = 0; i < 8; i++) res += (128 >> i) * this.readBit();
160
-
161
- return String.fromCharCode(res);
162
- };
163
-
164
- ShortyRaw.prototype.deflate = function (data) {
165
- let token,
166
- l = data.length,
167
- i,
168
- x;
169
- this.reset();
170
-
171
- for (i = 0; i < l; i++) {
172
- token = data[i];
173
-
174
- if (this.tokensize > 1) {
175
- if (/[a-zA-Z]/.test(token)) while (i + 1 < l && token.length < this.tokensize && /[a-zA-Z]/.test(data[i + 1])) {
176
- token += data[++i];
177
- } else if (/[=\[\],\.:\"'\{\}]/.test(token)) while (i + 1 < l && token.length < this.tokensize && /[=\[\],\.:\"'\{\}]/.test(data[i + 1])) {
178
- i++;
179
- token += data[i];
180
- } //joe hl patch "
181
- }
182
-
183
- x = this.findNode(token);
184
-
185
- if (!x) {
186
- this.emitNyt(token);
187
- x = this.addNode(token);
188
- } else {
189
- this.emitNode(x);
190
- this.balanceNode(x);
191
- }
192
- }
193
-
194
- if (this.bitCount != 7) {
195
- const oldlength = this.data.length;
196
- this.emitNode(this.nyt);
197
- if (oldlength == this.data.length) this.emitByte(0);
198
- }
199
-
200
- return this.data;
201
- };
202
-
203
- ShortyRaw.prototype.inflate = function (data) {
204
- this.reset();
205
- this.data = data;
206
- let output = '';
207
-
208
- try {
209
- for (let i = 0; i >= 0; i++) {
210
- const token = this.readNode();
211
- output += token;
212
- const node = this.findNode(token);
213
- if (!node) this.addNode(token);else this.balanceNode(node);
214
- }
215
- } catch (e) {}
216
-
217
- return output;
218
- };
219
-
220
- export class Shorty extends ShortyRaw {
221
- encode(data) {
222
- return this.deflate(data);
223
- }
224
-
225
- decode(data) {
226
- return this.inflate(data);
227
- }
228
-
229
- }