Skip to content

Commit 89767ce

Browse files
committed
feat: 支持查看日志(前端>=2.16.60)
1 parent ea8bb4d commit 89767ce

15 files changed

Lines changed: 860 additions & 20 deletions

File tree

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,7 @@ backend/sub-store.min.js
138138
CHANGELOG.md
139139

140140
.codeartsdoer
141-
.github/copilot-instructions.md
141+
.github/copilot-instructions.md
142+
CODEMAP.md
143+
CONTEXT_BUNDLE.md
144+
mydocs

backend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sub-store",
3-
"version": "2.22.6",
3+
"version": "2.22.7",
44
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.",
55
"main": "src/main.js",
66
"scripts": {

backend/src/constants.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ export const ARTIFACT_REPOSITORY_KEY = 'Sub-Store Artifacts Repository';
1414
export const RESOURCE_CACHE_KEY = '#sub-store-cached-resource';
1515
export const HEADERS_RESOURCE_CACHE_KEY = '#sub-store-cached-headers-resource';
1616
export const SCRIPT_RESOURCE_CACHE_KEY = '#sub-store-cached-script-resource';
17+
export const LOGS_KEY = '#sub-store-logs';
1718
export const DEFAULT_CACHE_TTL = 60 * 60 * 1000; // 1 hour
1819
export const DEFAULT_HEADERS_CACHE_TTL = 60 * 1000; // 1 min
1920
export const DEFAULT_SCRIPT_CACHE_TTL = 48 * 3600 * 1000; // 48 hours
21+
export const DEFAULT_LOGS_MAX_COUNT = 0;

backend/src/core/proxy-utils/index.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -373,11 +373,7 @@ function produce(proxies, targetPlatform, type, opts = {}) {
373373
return producer.produce(proxy, type, opts);
374374
} catch (err) {
375375
$.error(
376-
`Cannot produce proxy: ${JSON.stringify(
377-
proxy,
378-
null,
379-
2,
380-
)}\nReason: ${err}`,
376+
`Cannot produce proxy: ${proxy.name}\nReason: ${err}`,
381377
);
382378
return '';
383379
}

backend/src/core/proxy-utils/producers/egern.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -580,11 +580,7 @@ export default function Egern_Producer() {
580580
};
581581
} catch (err) {
582582
$.error(
583-
`Cannot produce proxy: ${JSON.stringify(
584-
sourceProxy,
585-
null,
586-
2,
587-
)}\nReason: ${err}`,
583+
`Cannot produce proxy: ${proxy.name}\nReason: ${err}`,
588584
);
589585
return null;
590586
}

backend/src/core/proxy-utils/producers/v2ray.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,7 @@ export default function V2Ray_Producer() {
1313
try {
1414
result.push(URI.produce(proxy));
1515
} catch (err) {
16-
$.error(
17-
`Cannot produce proxy: ${JSON.stringify(
18-
proxy,
19-
null,
20-
2,
21-
)}\nReason: ${err}`,
22-
);
16+
$.error(`Cannot produce proxy: ${proxy.name}\nReason: ${err}`);
2317
}
2418
});
2519

backend/src/products/sub-store-0.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import registerFileRoutes from '@/restful/file';
2424
import registerTokenRoutes from '@/restful/token';
2525
import registerArchiveRoutes from '@/restful/archives';
2626
import registerModuleRoutes from '@/restful/module';
27+
import registerLogRoutes from '@/restful/logs';
2728

2829
migrate();
2930
serve();
@@ -42,6 +43,7 @@ function serve() {
4243
registerSortRoutes($app);
4344
registerArchiveRoutes($app);
4445
registerMiscRoutes($app);
46+
registerLogRoutes($app);
4547

4648
$app.start();
4749
}

backend/src/restful/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import registerSortingRoutes from './sort';
2323
import registerMiscRoutes from './miscs';
2424
import registerNodeInfoRoutes from './node-info';
2525
import registerParserRoutes from './parser';
26+
import registerLogRoutes from './logs';
2627

2728
export default function serve() {
2829
let port;
@@ -139,6 +140,7 @@ export default function serve() {
139140
registerNodeInfoRoutes($app);
140141
registerMiscRoutes($app);
141142
registerParserRoutes($app);
143+
registerLogRoutes($app);
142144

143145
$app.start();
144146

backend/src/restful/logs.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import $ from '@/core/app';
2+
import { InternalServerError, RequestInvalidError } from '@/restful/errors';
3+
import { failed, success } from '@/restful/response';
4+
import { clearLogEntries, getLogEntries } from '@/utils/debug-logs';
5+
6+
export default function register($app) {
7+
$app.route('/api/logs').get(getLogs).delete(clearLogs);
8+
}
9+
10+
function getLogs(req, res) {
11+
try {
12+
success(res, getLogEntries($, req.query || {}));
13+
} catch (e) {
14+
if (e instanceof SyntaxError) {
15+
failed(
16+
res,
17+
new RequestInvalidError(
18+
'INVALID_LOG_KEYWORD_REGEX',
19+
'Invalid log keyword regular expression',
20+
`Reason: ${e.message ?? e}`,
21+
),
22+
400,
23+
);
24+
return;
25+
}
26+
27+
failed(
28+
res,
29+
new InternalServerError(
30+
'FAILED_TO_GET_LOGS',
31+
'Failed to get logs',
32+
`Reason: ${e.message ?? e}`,
33+
),
34+
);
35+
}
36+
}
37+
38+
function clearLogs(req, res) {
39+
try {
40+
clearLogEntries($);
41+
success(res);
42+
} catch (e) {
43+
failed(
44+
res,
45+
new InternalServerError(
46+
'FAILED_TO_CLEAR_LOGS',
47+
'Failed to clear logs',
48+
`Reason: ${e.message ?? e}`,
49+
),
50+
);
51+
}
52+
}

backend/src/restful/settings.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { success, failed } from './response';
33
import { InternalServerError } from '@/restful/errors';
44
import $ from '@/core/app';
55
import Gist from '@/utils/gist';
6+
import { clearLogSettingsCache } from '@/utils/debug-logs';
67

78
export default function register($app) {
89
const settings = $.read(SETTINGS_KEY);
@@ -54,7 +55,21 @@ async function updateSettings(req, res) {
5455
delete newSettings[key];
5556
}
5657
});
58+
if ('logsMaxCount' in newSettings) {
59+
const rawLogsMaxCount = newSettings.logsMaxCount;
60+
const value = Number(rawLogsMaxCount);
61+
if (
62+
rawLogsMaxCount === null ||
63+
rawLogsMaxCount === undefined ||
64+
rawLogsMaxCount === '' ||
65+
!isFinite(value) ||
66+
value < 0
67+
) {
68+
delete newSettings.logsMaxCount;
69+
}
70+
}
5771
$.write(newSettings, SETTINGS_KEY);
72+
clearLogSettingsCache();
5873
if (
5974
req.body.githubUser ||
6075
req.body.gistToken ||

0 commit comments

Comments
 (0)