feat: add CALL util.debugAdd
gitea/salix/pipeline/pr-master There was a failure building this commit Details

This commit is contained in:
Javier Segarra 2024-06-20 11:49:25 +00:00
parent b02a4721af
commit eec160497e
1 changed files with 40 additions and 26 deletions

View File

@ -16,8 +16,10 @@ module.exports = Self => {
accessScopes: ['DEFAULT', 'read:multimedia']}); accessScopes: ['DEFAULT', 'read:multimedia']});
Self.renewToken = async function(ctx) { Self.renewToken = async function(ctx) {
const {accessToken: token} = ctx.req; let accessToken;
let token;
try {
token = ctx.req.accessToken;
const {courtesyTime} = await models.AccessTokenConfig.findOne({ const {courtesyTime} = await models.AccessTokenConfig.findOne({
fields: ['courtesyTime'] fields: ['courtesyTime']
}); });
@ -30,9 +32,12 @@ module.exports = Self => {
try { try {
const exists = await models.AccessToken.findById(token.id); const exists = await models.AccessToken.findById(token.id);
exists && await Self.logout(token.id); exists && await Self.logout(token.id);
} catch (err) { } catch (error) {
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
console.error(err); console.error(error);
const body = JSON.stringify({err: error, token});
await handleError(body);
throw new Error(error);
} }
}, courtesyTime * 1000); }, courtesyTime * 1000);
@ -44,8 +49,17 @@ module.exports = Self => {
createTokenOptions = {scopes: [scopes[0]]}; createTokenOptions = {scopes: [scopes[0]]};
// Create new accessToken // Create new accessToken
const user = await Self.findById(token.userId); const user = await Self.findById(token.userId);
const accessToken = await user.accessTokens.create(createTokenOptions); accessToken = await user.accessTokens.create(createTokenOptions);
return {id: accessToken.id, ttl: accessToken.ttl}; return {id: accessToken.id, ttl: accessToken.ttl};
} catch (error) {
const body = JSON.stringify({error: error.message, token, accessToken});
await handleError(body);
throw new Error(error);
}
}; };
}; };
async function handleError(body, tag = 'renewToken') {
await models.Application.rawSql('CALL util.debugAdd(?,?);', [tag, body]);
}