修复登录通知失败造成服务重启

This commit is contained in:
whyour
2025-05-11 14:36:16 +08:00
parent 9a399f8de8
commit 8a18baa921
5 changed files with 14 additions and 77 deletions
+1 -1
View File
@@ -19,7 +19,7 @@ export class HttpServerService {
resolve(this.server);
});
this.server.on('error', (err: Error) => {
this.server?.on('error', (err: Error) => {
Logger.error('Failed to start HTTP service:', err);
reject(err);
});
+1 -1
View File
@@ -59,7 +59,7 @@ export default class NotificationService {
try {
return await notificationModeAction?.call(this);
} catch (error: any) {
throw error;
console.error(error);
}
}
return false;
+11 -2
View File
@@ -1,6 +1,6 @@
import { Service, Inject } from 'typedi';
import winston from 'winston';
import { createRandomString, getNetIp } from '../config/util';
import { createRandomString } from '../config/util';
import config from '../config';
import jwt from 'jsonwebtoken';
import { authenticator } from '@otplib/preset-default';
@@ -271,7 +271,16 @@ export default class UserService {
if (isValid) {
return this.login({ username, password }, req, false);
} else {
const { ip, address } = await getNetIp(req);
const ip = requestIp.getClientIp(req) || '';
const query = new IP2Region();
const ipAddress = query.search(ip);
let address = '';
if (ipAddress) {
const { country, province, city, isp } = ipAddress;
address = uniq([country, province, city, isp])
.filter(Boolean)
.join(' ');
}
await this.updateAuthInfo(authInfo, {
lastip: ip,
lastaddr: address,