feat:token过期自动更新

This commit is contained in:
Jerry 2025-09-26 13:32:24 +08:00
parent 1b380d8b8e
commit d0eb167245
2 changed files with 23 additions and 0 deletions

View File

@ -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 TokenToken已过期 * OpenList的JWT TokenToken已过期
* @param username * @param username

View File

@ -50,6 +50,12 @@ export class CdnService {
); );
} else { } else {
this.logger.error(`晶灵cdn检查更新失败: ${remoteFiles.code}`); 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) { } catch (error) {
this.logger.error(`晶灵cdn检查更新失败: ${error}`); this.logger.error(`晶灵cdn检查更新失败: ${error}`);