UNPKG

@akemona-org/strapi

Version:

An open source headless CMS solution to create and manage your own API. It provides a powerful dashboard and features to make your life easier. Databases supported: MongoDB, MySQL, MariaDB, PostgreSQL, SQLite

28 lines (22 loc) 595 B
'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); }; };