mirror of
https://github.com/strapi/strapi.git
synced 2025-11-13 08:38:09 +00:00
28 lines
595 B
JavaScript
28 lines
595 B
JavaScript
'use strict';
|
|
|
|
/**
|
|
* @param events a list of events that need to be limited
|
|
*/
|
|
module.exports = (sender, { limitedEvents = [] } = {}) => {
|
|
let currentDay = new Date().getDate();
|
|
const eventCache = new Map();
|
|
|
|
return async (event, ...args) => {
|
|
if (!limitedEvents.includes(event)) {
|
|
return sender(event, ...args);
|
|
}
|
|
|
|
if (new Date().getDate() !== currentDay) {
|
|
eventCache.clear();
|
|
currentDay = new Date().getDate();
|
|
}
|
|
|
|
if (eventCache.has(event)) {
|
|
return false;
|
|
}
|
|
|
|
eventCache.set(event, true);
|
|
return sender(event, ...args);
|
|
};
|
|
};
|