Skip to content

Commit 4c514be

Browse files
committed
fix(server): fix lint in logic/base
1 parent 238fc32 commit 4c514be

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

packages/server/src/logic/base.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,18 @@ module.exports = class extends think.Logic {
1414

1515
async __before() {
1616
const referrer = this.ctx.referrer(true);
17-
let origin = this.ctx.request.header.origin;
17+
let origin = this.ctx.origin;
18+
1819
if (origin) {
1920
try {
2021
const parsedOrigin = new URL(origin);
22+
2123
origin = parsedOrigin.hostname;
22-
} catch (error) {
23-
console.error('Invalid origin format:', origin);
24+
} catch (e) {
25+
console.error('Invalid origin format:', origin, e);
2426
}
2527
}
28+
2629
let { secureDomains } = this.config();
2730

2831
if (secureDomains) {
@@ -51,10 +54,16 @@ module.exports = class extends think.Logic {
5154
try {
5255
return new RegExp(domain.slice(1, -1)); // 去掉斜杠并创建 RegExp 对象
5356
} catch (e) {
54-
console.error('Invalid regex pattern in secureDomains:', domain);
57+
console.error(
58+
'Invalid regex pattern in secureDomains:',
59+
domain,
60+
e,
61+
);
62+
5563
return null;
5664
}
5765
}
66+
5867
return domain;
5968
})
6069
.filter(Boolean); // 过滤掉无效的正则表达式
@@ -64,7 +73,7 @@ module.exports = class extends think.Logic {
6473
const isSafe = secureDomains.some((domain) =>
6574
think.isFunction(domain.test)
6675
? domain.test(checking)
67-
: domain === checking
76+
: domain === checking,
6877
);
6978

7079
if (!isSafe) {
@@ -111,7 +120,7 @@ module.exports = class extends think.Logic {
111120
'2fa',
112121
'label',
113122
],
114-
}
123+
},
115124
);
116125

117126
if (think.isEmpty(user)) {
@@ -213,13 +222,13 @@ module.exports = class extends think.Logic {
213222
};
214223

215224
const response = await fetch(requestUrl, options).then((resp) =>
216-
resp.json()
225+
resp.json(),
217226
);
218227

219228
if (!response.success) {
220229
think.logger.debug(
221230
'RecaptchaV3 or Turnstile Result:',
222-
JSON.stringify(response, null, '\t')
231+
JSON.stringify(response, null, '\t'),
223232
);
224233

225234
return this.ctx.throw(403);

0 commit comments

Comments
 (0)