You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
2.1 KiB
55 lines
2.1 KiB
'use strict';
|
|
const superagent = require('superagent');
|
|
|
|
let TEST = true
|
|
TEST = false
|
|
|
|
module.exports = {
|
|
conf: {
|
|
interval: '0 0 0 * * *',
|
|
/**
|
|
* * * * * * *
|
|
┬ ┬ ┬ ┬ ┬ ┬
|
|
│ │ │ │ │ │
|
|
│ │ │ │ │ └ day of week (0 - 7) (0 or 7 is Sun)
|
|
│ │ │ │ └───── month (1 - 12)
|
|
│ │ │ └────────── day of month (1 - 31)
|
|
│ │ └─────────────── hour (0 - 23)
|
|
│ └──────────────────── minute (0 - 59)
|
|
└───────────────────────── second (0 - 59, OPTIONAL)
|
|
*/
|
|
immediate: true,
|
|
env: ['dev', 'prod'],
|
|
disabled: true, // 是否禁用该定时任务
|
|
},
|
|
callback: async function (app, conf) {
|
|
try {
|
|
let fastgptToken = conf.fastGpt.token;
|
|
|
|
let loginParams = {
|
|
username: conf.fastGpt.username,
|
|
password: conf.fastGpt.password,
|
|
code: '',
|
|
}
|
|
const preLoginRes = await superagent
|
|
.get(`${conf.fastGpt.apiUrl}/api/support/user/account/preLogin`)
|
|
.query({
|
|
username: conf.fastGpt.username,
|
|
});
|
|
if (preLoginRes.body && preLoginRes.body.data && preLoginRes.body.code === 200) {
|
|
loginParams.code = preLoginRes.body.data.code;
|
|
}
|
|
|
|
const res = await superagent
|
|
.post(`${conf.fastGpt.apiUrl}/api/support/user/account/loginByPassword`)
|
|
.send(loginParams);
|
|
if (res.body && res.body.data && res.body.data.token) {
|
|
fastgptToken = res.body.data.token;
|
|
conf.fastGpt.token = fastgptToken;
|
|
}
|
|
console.log('refresh-fgpt-token schedule success', Date.now());
|
|
} catch (error) {
|
|
console.error('refresh-fgpt-token schedule error:', error);
|
|
}
|
|
},
|
|
};
|
|
|