@wutiange/log-listener-plugin 2.0.1-alpha.1 → 2.0.1-alpha.3
Sign up to get free protection for your applications and to get access to all the features.
package/README.md
CHANGED
@@ -53,7 +53,7 @@ In your `info.plist` add the following strings:
|
|
53
53
|
```plist
|
54
54
|
<key>NSBonjourServices</key>
|
55
55
|
<array>
|
56
|
-
<string>
|
56
|
+
<string>_http._tcp</string>
|
57
57
|
</array>
|
58
58
|
<key>NSLocalNetworkUsageDescription</key>
|
59
59
|
<string>Access nearby Log Records to view logs</string>
|
package/dist/src/Server.js
CHANGED
@@ -26,6 +26,7 @@ class Server {
|
|
26
26
|
this.urlsListener = onNewUrlCallback;
|
27
27
|
};
|
28
28
|
this.requestJoin = (url, token) => __awaiter(this, void 0, void 0, function* () {
|
29
|
+
var _a;
|
29
30
|
const response = yield fetch(url, {
|
30
31
|
method: "POST",
|
31
32
|
headers: {
|
@@ -33,7 +34,7 @@ class Server {
|
|
33
34
|
},
|
34
35
|
body: JSON.stringify({
|
35
36
|
token,
|
36
|
-
model: this.innerBaseData.
|
37
|
+
model: (_a = this.innerBaseData.Model) !== null && _a !== void 0 ? _a : `${this.innerBaseData.systemName}v${this.innerBaseData.osVersion}`,
|
37
38
|
id: (0, md5_1.default)(JSON.stringify(this.innerBaseData)).toString(),
|
38
39
|
}),
|
39
40
|
});
|
@@ -47,6 +48,7 @@ class Server {
|
|
47
48
|
return true;
|
48
49
|
});
|
49
50
|
this.send = (path, data) => __awaiter(this, void 0, void 0, function* () {
|
51
|
+
var _a;
|
50
52
|
const request = (url, _data) => __awaiter(this, void 0, void 0, function* () {
|
51
53
|
yield Promise.race([
|
52
54
|
fetch(`${url}/${path}`, {
|
@@ -71,7 +73,10 @@ class Server {
|
|
71
73
|
yield Promise.all(this.getUrls().map((e) => __awaiter(this, void 0, void 0, function* () { return request(e, data); })));
|
72
74
|
}
|
73
75
|
catch (error) {
|
74
|
-
|
76
|
+
if ((_a = error === null || error === void 0 ? void 0 : error.message) === null || _a === void 0 ? void 0 : _a.includes("Network request failed")) {
|
77
|
+
return;
|
78
|
+
}
|
79
|
+
logger_1.default.warn(common_1.LOG_KEY, "上报日志失败", error);
|
75
80
|
}
|
76
81
|
});
|
77
82
|
this.log = (data) => __awaiter(this, void 0, void 0, function* () {
|
package/dist/src/Server.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Server.js","sourceRoot":"","sources":["../../src/Server.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,mCAAyC;AAEzC,qCAA2D;AAC3D,sDAA8B;AAC9B,wDAAgC;AAGhC,MAAM,YAAY,GAAG,KAAK,CAAC;AAC3B,MAAM,MAAM;IAUV,YAAY,GAAqC,EAAE,UAAkB,KAAK;QATlE,eAAU,GAA2B,EAAE,CAAC;QAExC,aAAQ,GAAwB,EAAE,CAAC;QAKnC,kBAAa,GAA2B,EAAE,CAAC;QAanD,oBAAe,GAAG,CAChB,gBAA2E,EAC3E,EAAE;YACF,IAAI,CAAC,YAAY,GAAG,gBAAgB,CAAC;QACvC,CAAC,CAAC;QAEM,gBAAW,GAAG,CAAO,GAAW,EAAE,KAAa,EAAE,EAAE
|
1
|
+
{"version":3,"file":"Server.js","sourceRoot":"","sources":["../../src/Server.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,mCAAyC;AAEzC,qCAA2D;AAC3D,sDAA8B;AAC9B,wDAAgC;AAGhC,MAAM,YAAY,GAAG,KAAK,CAAC;AAC3B,MAAM,MAAM;IAUV,YAAY,GAAqC,EAAE,UAAkB,KAAK;QATlE,eAAU,GAA2B,EAAE,CAAC;QAExC,aAAQ,GAAwB,EAAE,CAAC;QAKnC,kBAAa,GAA2B,EAAE,CAAC;QAanD,oBAAe,GAAG,CAChB,gBAA2E,EAC3E,EAAE;YACF,IAAI,CAAC,YAAY,GAAG,gBAAgB,CAAC;QACvC,CAAC,CAAC;QAEM,gBAAW,GAAG,CAAO,GAAW,EAAE,KAAa,EAAE,EAAE;;YACzD,MAAM,QAAQ,GAAG,MA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 -100,20 +100,6 @@ describe('Server', () => {
|
|
100
100
|
expect(global.fetch).toHaveBeenCalled();
|
101
101
|
expect(utils_1.sleep).toHaveBeenCalledWith(100, true);
|
102
102
|
}));
|
103
|
-
it('should handle errors and send error data', () => __awaiter(void 0, void 0, void 0, function* () {
|
104
|
-
global.fetch.mockImplementation(() => Promise.reject(new Error('Network error')));
|
105
|
-
const testData = { message: 'test' };
|
106
|
-
yield server.log(testData);
|
107
|
-
expect(global.fetch).toHaveBeenCalledWith(expect.any(String), expect.objectContaining({
|
108
|
-
body: expect.stringContaining('log-plugin-internal-error')
|
109
|
-
}));
|
110
|
-
const lastCall = global.fetch.mock.calls[global.fetch.mock.calls.length - 1];
|
111
|
-
const body = JSON.parse(lastCall[1].body);
|
112
|
-
expect(body).toMatchObject({
|
113
|
-
tag: 'log-plugin-internal-error',
|
114
|
-
level: 'error'
|
115
|
-
});
|
116
|
-
}));
|
117
103
|
});
|
118
104
|
describe('Base Data Management', () => {
|
119
105
|
it('should update base data', () => __awaiter(void 0, void 0, void 0, function* () {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Server.test.js","sourceRoot":"","sources":["../../../src/__tests__/Server.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,uDAA+B;AAC/B,oCAAiC;AAGjC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,GAAG,EAAE;IACzB,MAAM,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;IAC9C,uCACK,MAAM,KACT,KAAK,EAAE,IAAI,CAAC,EAAE,EAAE,IAChB;AACJ,CAAC,CAAC,CAAC;AAIH,IAAI,CAAC,IAAI,CAAC,uBAAuB,EAAE,GAAG,EAAE,CAAC,SAAS,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;AAGvE,MAAM,CAAC,KAAK,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;AAEzB,QAAQ,CAAC,QAAQ,EAAE,GAAG,EA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gB,CAAC;gBACtB,IAAI,EAAE,MAAM,CAAC,gBAAgB,CAAC,gBAAgB,CAAC;aAChD,CAAC,CACH,CAAC;QACJ,CAAC,CAAA,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
package/src/Server.ts
CHANGED
@@ -41,7 +41,7 @@ class Server {
|
|
41
41
|
},
|
42
42
|
body: JSON.stringify({
|
43
43
|
token,
|
44
|
-
model: this.innerBaseData.
|
44
|
+
model: this.innerBaseData.Model ?? `${this.innerBaseData.systemName}v${this.innerBaseData.osVersion}`,
|
45
45
|
id: md5(JSON.stringify(this.innerBaseData)).toString(),
|
46
46
|
}),
|
47
47
|
});
|
@@ -131,9 +131,10 @@ class Server {
|
|
131
131
|
}
|
132
132
|
await Promise.all(this.getUrls().map(async (e) => request(e, data)));
|
133
133
|
} catch (error: any) {
|
134
|
-
|
135
|
-
|
136
|
-
|
134
|
+
if (error?.message?.includes("Network request failed")) {
|
135
|
+
return
|
136
|
+
}
|
137
|
+
logger.warn(LOG_KEY, "上报日志失败", error)
|
137
138
|
}
|
138
139
|
};
|
139
140
|
|
@@ -129,31 +129,6 @@ describe('Server', () => {
|
|
129
129
|
expect(global.fetch).toHaveBeenCalled();
|
130
130
|
expect(sleep).toHaveBeenCalledWith(100, true);
|
131
131
|
});
|
132
|
-
|
133
|
-
it('should handle errors and send error data', async () => {
|
134
|
-
(global.fetch as jest.Mock).mockImplementation(() =>
|
135
|
-
Promise.reject(new Error('Network error'))
|
136
|
-
);
|
137
|
-
|
138
|
-
const testData = { message: 'test' };
|
139
|
-
await server.log(testData);
|
140
|
-
|
141
|
-
// 修改这里的断言来匹配实际的错误格式
|
142
|
-
expect(global.fetch).toHaveBeenCalledWith(
|
143
|
-
expect.any(String),
|
144
|
-
expect.objectContaining({
|
145
|
-
body: expect.stringContaining('log-plugin-internal-error')
|
146
|
-
})
|
147
|
-
);
|
148
|
-
|
149
|
-
// 如果需要更精确的检查,可以添加以下断言
|
150
|
-
const lastCall = (global.fetch as jest.Mock).mock.calls[(global.fetch as jest.Mock).mock.calls.length - 1];
|
151
|
-
const body = JSON.parse(lastCall[1].body);
|
152
|
-
expect(body).toMatchObject({
|
153
|
-
tag: 'log-plugin-internal-error',
|
154
|
-
level: 'error'
|
155
|
-
});
|
156
|
-
});
|
157
132
|
});
|
158
133
|
|
159
134
|
describe('Base Data Management', () => {
|