mirror of
https://github.com/crystelf/crystelf-core.git
synced 2025-12-05 10:31:56 +00:00
feat:token过期自动更新
This commit is contained in:
parent
1b380d8b8e
commit
d0eb167245
@ -37,6 +37,23 @@ export class OpenListService {
|
||||
}
|
||||
}
|
||||
|
||||
public async updateToken(): Promise<boolean> {
|
||||
try {
|
||||
const username = this.configService.get('OPENLIST_API_BASE_USERNAME');
|
||||
const password = this.configService.get('OPENLIST_API_BASE_PASSWORD');
|
||||
if (username && password) {
|
||||
this.token = await OpenListUtils.getToken(username, password);
|
||||
return true;
|
||||
} else {
|
||||
this.logger.warn('请先配置用户名和密码..');
|
||||
return false;
|
||||
}
|
||||
} catch (e) {
|
||||
this.logger.error(`更新token失败: ${e.message}`);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取OpenList的JWT Token,如果Token已过期,则重新获取
|
||||
* @param username 用户名
|
||||
|
||||
@ -50,6 +50,12 @@ export class CdnService {
|
||||
);
|
||||
} else {
|
||||
this.logger.error(`晶灵cdn检查更新失败: ${remoteFiles.code}`);
|
||||
if (remoteFiles.code === 401) {
|
||||
this.logger.log('尝试更新token..');
|
||||
if (await this.openListService.updateToken()) {
|
||||
this.logger.log('更新token成功..');
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
this.logger.error(`晶灵cdn检查更新失败: ${error}`);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user