mirror of
https://github.com/whyour/qinglong.git
synced 2025-05-23 23:06:06 +08:00
修改openapi获取token逻辑
This commit is contained in:
parent
4e58a640e4
commit
816ce31279
|
@ -108,12 +108,26 @@ export default class OpenService {
|
||||||
client_id: string;
|
client_id: string;
|
||||||
client_secret: string;
|
client_secret: string;
|
||||||
}): Promise<any> {
|
}): Promise<any> {
|
||||||
const token = uuidV4();
|
let token = uuidV4();
|
||||||
const expiration = Math.round(Date.now() / 1000) + 2592000; // 2592000 30天
|
const expiration = Math.round(Date.now() / 1000) + 2592000; // 2592000 30天
|
||||||
const doc = await AppModel.findOne({ where: { client_id, client_secret } });
|
const doc = await AppModel.findOne({ where: { client_id, client_secret } });
|
||||||
if (doc) {
|
if (doc) {
|
||||||
|
const timestamp = Math.round(Date.now() / 1000);
|
||||||
|
const invalidTokens = (doc.tokens || []).filter(
|
||||||
|
(x) => x.expiration >= timestamp,
|
||||||
|
);
|
||||||
|
let tokens = invalidTokens;
|
||||||
|
if (invalidTokens.length > 5) {
|
||||||
|
tokens = [
|
||||||
|
...invalidTokens.slice(0, 4),
|
||||||
|
{ ...invalidTokens[4], expiration },
|
||||||
|
];
|
||||||
|
token = invalidTokens[4].value;
|
||||||
|
} else {
|
||||||
|
tokens = [...invalidTokens, { value: token, expiration }];
|
||||||
|
}
|
||||||
await AppModel.update(
|
await AppModel.update(
|
||||||
{ tokens: [...(doc.tokens || []), { value: token, expiration }] },
|
{ tokens },
|
||||||
{ where: { client_id, client_secret } },
|
{ where: { client_id, client_secret } },
|
||||||
);
|
);
|
||||||
return {
|
return {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user