Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * isActionTimeoutExpired check the time since the cache was set
- */
- function isActionTimeoutExpired(action) {
- var actions = easy.context.site.actions;
- var expired = true;
- if (actions && actions.length) {
- easy.utils.each(actions, function (currAction) {
- if (currAction.name === action) {
- expired = isExpired(new Date(currAction.set).getTime() / 1000,
- currAction.expiresMin);
- }
- });
- }
- return expired;
- }
- /**
- * setActionsTimeout Set timeout for action to be expired
- * @param {number} min Time in minutes
- */
- function setActionTimeout(action, min) {
- if (!easy.context.site.actions) {
- easy.context.site.actions = [];
- }
- function pushOrUpdate (data) {
- if (data.hasOwnProperty('name')) {
- var updated = false;
- easy.utils.each(easy.context.site.actions, function (obj) {
- if (obj.hasOwnProperty('name') && obj.name === data.name) {
- obj.set = new Date();
- obj.expiresMin = data.expiresMin;
- updated = true;
- }
- });
- if (!updated) {
- easy.context.site.actions.push({
- name: action,
- set: new Date(),
- expiresMin: min
- });
- }
- }
- }
- pushOrUpdate({
- name: action,
- set: new Date(),
- expiresMin: min
- });
- easy.context.save();
- }
- /**
- * Check if the saved timestamp has expired
- * @param {Int} timestamp Unix timestamp
- * @param {Int} duration Minute as unit
- * @return {Boolean}
- */
- function isExpired(timestamp, duration) {
- var currentTimestamp = getTimestamp();
- var dur_inSecond = duration * 60;
- return (currentTimestamp - timestamp) >= dur_inSecond ? true : false;
- }
- function getTimestamp () {
- return Math.round(new Date().getTime() / 1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement