mirror of
https://github.com/whyour/qinglong.git
synced 2026-07-01 04:40:38 +08:00
增加初始化过程
This commit is contained in:
+10
-6
@@ -1,7 +1,7 @@
|
||||
import { NotificationInfo } from '../data/notify';
|
||||
import { Service, Inject } from 'typedi';
|
||||
import winston from 'winston';
|
||||
import AuthService from './auth';
|
||||
import UserService from './user';
|
||||
import got from 'got';
|
||||
import nodemailer from 'nodemailer';
|
||||
import crypto from 'crypto';
|
||||
@@ -9,8 +9,8 @@ import { HttpProxyAgent, HttpsProxyAgent } from 'hpagent';
|
||||
|
||||
@Service()
|
||||
export default class NotificationService {
|
||||
@Inject((type) => AuthService)
|
||||
private authService!: AuthService;
|
||||
@Inject((type) => UserService)
|
||||
private userService!: UserService;
|
||||
|
||||
private modeMap = new Map([
|
||||
['goCqHttpBot', this.goCqHttpBot],
|
||||
@@ -32,8 +32,11 @@ export default class NotificationService {
|
||||
|
||||
constructor(@Inject('logger') private logger: winston.Logger) {}
|
||||
|
||||
public async notify(title: string, content: string) {
|
||||
const { type, ...rest } = await this.authService.getNotificationMode();
|
||||
public async notify(
|
||||
title: string,
|
||||
content: string,
|
||||
): Promise<boolean | undefined> {
|
||||
const { type, ...rest } = await this.userService.getNotificationMode();
|
||||
if (type) {
|
||||
this.title = title;
|
||||
this.content = content;
|
||||
@@ -42,9 +45,10 @@ export default class NotificationService {
|
||||
try {
|
||||
return await notificationModeAction?.call(this);
|
||||
} catch (error: any) {
|
||||
return error.message;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public async testNotify(
|
||||
|
||||
@@ -13,7 +13,7 @@ import NotificationService from './notify';
|
||||
import { Request } from 'express';
|
||||
|
||||
@Service()
|
||||
export default class AuthService {
|
||||
export default class UserService {
|
||||
@Inject((type) => NotificationService)
|
||||
private notificationService!: NotificationService;
|
||||
private authDb = new DataStore({ filename: config.authDbFile });
|
||||
@@ -160,6 +160,14 @@ export default class AuthService {
|
||||
}
|
||||
}
|
||||
|
||||
public async logout(platform: string): Promise<any> {
|
||||
const authInfo = this.getAuthInfo();
|
||||
this.updateAuthInfo(authInfo, {
|
||||
token: '',
|
||||
tokens: { ...authInfo.tokens, [platform]: '' },
|
||||
});
|
||||
}
|
||||
|
||||
public async getLoginLog(): Promise<AuthInfo[]> {
|
||||
return new Promise((resolve) => {
|
||||
this.authDb.find({ type: AuthDataType.loginLog }).exec((err, docs) => {
|
||||
@@ -205,6 +213,18 @@ export default class AuthService {
|
||||
};
|
||||
}
|
||||
|
||||
public async updateUsernameAndPassword({
|
||||
username,
|
||||
password,
|
||||
}: {
|
||||
username: string;
|
||||
password: string;
|
||||
}) {
|
||||
const authInfo = this.getAuthInfo();
|
||||
this.updateAuthInfo(authInfo, { username, password });
|
||||
return { code: 200, message: '更新成功' };
|
||||
}
|
||||
|
||||
public getUserInfo(): Promise<any> {
|
||||
return new Promise((resolve) => {
|
||||
fs.readFile(config.authConfigFile, 'utf8', (err, data) => {
|
||||
Reference in New Issue
Block a user