mirror of
https://github.com/whyour/qinglong.git
synced 2026-07-01 04:40:38 +08:00
修改生成系统token逻辑
This commit is contained in:
+8
-30
@@ -10,41 +10,19 @@ const tokenFile = path.join(config.configPath, 'token.json');
|
||||
|
||||
async function getToken() {
|
||||
try {
|
||||
const data = await readFile();
|
||||
const nowTime = Math.round(Date.now() / 1000);
|
||||
if (data.value && data.expiration > nowTime) {
|
||||
console.log(data.value);
|
||||
} else {
|
||||
Container.set('logger', LoggerInstance);
|
||||
const openService = Container.get(OpenService);
|
||||
const appToken = await openService.findSystemToken();
|
||||
console.log(appToken.value);
|
||||
await writeFile({
|
||||
value: appToken.value,
|
||||
expiration: appToken.expiration,
|
||||
});
|
||||
}
|
||||
Container.set('logger', LoggerInstance);
|
||||
const openService = Container.get(OpenService);
|
||||
const appToken = await openService.generateSystemToken();
|
||||
console.log(appToken.value);
|
||||
await writeFile({
|
||||
value: appToken.value,
|
||||
expiration: appToken.expiration,
|
||||
});
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
}
|
||||
|
||||
async function readFile() {
|
||||
return new Promise<any>((resolve, reject) => {
|
||||
fs.readFile(
|
||||
path.join(config.configPath, 'token.json'),
|
||||
{ encoding: 'utf8' },
|
||||
(err, data) => {
|
||||
if (err) {
|
||||
resolve({});
|
||||
} else {
|
||||
resolve(JSON.parse(data));
|
||||
}
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
async function writeFile(data: any) {
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
fs.writeFile(tokenFile, JSON.stringify(data), { encoding: 'utf8' }, () => {
|
||||
|
||||
Reference in New Issue
Block a user