Skip to content
Snippets Groups Projects
Commit 9cf40ef4 authored by dakkar's avatar dakkar
Browse files

merge: thunk the min/max promises (!603)

View MR for information: TransFem-org/Sharkey!603



Approved-by: default avatarMarie <github@yuugi.dev>
Approved-by: default avatarfEmber <acomputerdog@gmail.com>
parents 8fa7afca 17b6c1b3
No related branches found
No related tags found
No related merge requests found
......@@ -37,8 +37,13 @@ export class RateLimiterService {
return Promise.resolve();
}
// those lines with the "wrong" brace style / indentation are
// done that way so that the *other* lines stay identical to
// Misskey, simplifying merges
// Short-term limit
const min = new Promise<void>((ok, reject) => {
// eslint-disable-next-line brace-style
const minP = () => { return new Promise<void>((ok, reject) => {
const minIntervalLimiter = new Limiter({
id: `${actor}:${limitation.key}:min`,
duration: limitation.minInterval! * factor,
......@@ -57,16 +62,18 @@ export class RateLimiterService {
return reject({ code: 'BRIEF_REQUEST_INTERVAL', info });
} else {
if (hasLongTermLimit) {
return max.then(ok, reject);
return maxP().then(ok, reject);
} else {
return ok();
}
}
});
});
// eslint-disable-next-line brace-style
}); };
// Long term limit
const max = new Promise<void>((ok, reject) => {
// eslint-disable-next-line brace-style
const maxP = () => { return new Promise<void>((ok, reject) => {
const limiter = new Limiter({
id: `${actor}:${limitation.key}`,
duration: limitation.duration! * factor,
......@@ -87,7 +94,8 @@ export class RateLimiterService {
return ok();
}
});
});
// eslint-disable-next-line brace-style
}); };
const hasShortTermLimit = typeof limitation.minInterval === 'number';
......@@ -96,9 +104,9 @@ export class RateLimiterService {
typeof limitation.max === 'number';
if (hasShortTermLimit) {
return min;
return minP();
} else if (hasLongTermLimit) {
return max;
return maxP();
} else {
return Promise.resolve();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment