bug修复和架构完善
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
const Fse = require('fs-extra');
|
||||
const Path = require('path');
|
||||
const PixivAuth = require('./auth');
|
||||
const DownloadService = require('./services/download');
|
||||
|
||||
// 配置文件路径
|
||||
const CONFIG_FILE_DIR = require('appdata-path').getAppDataPath('pxder');
|
||||
@@ -24,6 +25,7 @@ class PixivBackend {
|
||||
this.config = null;
|
||||
this.auth = null;
|
||||
this.isLoggedIn = false;
|
||||
this.downloadService = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -39,6 +41,10 @@ class PixivBackend {
|
||||
// 创建认证实例,传入代理配置
|
||||
this.auth = new PixivAuth(this.config.proxy);
|
||||
|
||||
// 创建下载服务实例
|
||||
this.downloadService = new DownloadService(this.auth);
|
||||
await this.downloadService.init();
|
||||
|
||||
// 检查登录状态
|
||||
if (this.config.refresh_token) {
|
||||
console.log('检测到已保存的登录信息,正在验证...');
|
||||
@@ -161,6 +167,12 @@ class PixivBackend {
|
||||
// 更新配置
|
||||
this.config.access_token = result.access_token;
|
||||
this.config.refresh_token = result.refresh_token;
|
||||
|
||||
// 如果刷新令牌响应中包含用户信息,则更新
|
||||
if (result.user) {
|
||||
this.config.user = result.user;
|
||||
}
|
||||
|
||||
this.saveConfig();
|
||||
|
||||
this.isLoggedIn = true;
|
||||
@@ -253,6 +265,13 @@ class PixivBackend {
|
||||
getAuth() {
|
||||
return this.auth;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取下载服务实例
|
||||
*/
|
||||
getDownloadService() {
|
||||
return this.downloadService;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = PixivBackend;
|
||||
Reference in New Issue
Block a user