"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.VideoTokensManager = void 0;
const tslib_1 = require("tslib");
const lru_cache_1 = tslib_1.__importDefault(require("lru-cache"));
const constants_1 = require("../initializers/constants");
const extra_utils_1 = require("../../shared/extra-utils");
class VideoTokensManager {
    constructor() {
        this.lruCache = new lru_cache_1.default({
            max: constants_1.LRU_CACHE.VIDEO_TOKENS.MAX_SIZE,
            ttl: constants_1.LRU_CACHE.VIDEO_TOKENS.TTL
        });
    }
    create(videoUUID) {
        const token = (0, extra_utils_1.buildUUID)();
        const expires = new Date(new Date().getTime() + constants_1.LRU_CACHE.VIDEO_TOKENS.TTL);
        this.lruCache.set(token, videoUUID);
        return { token, expires };
    }
    hasToken(options) {
        const value = this.lruCache.get(options.token);
        if (!value)
            return false;
        return value === options.videoUUID;
    }
    static get Instance() {
        return this.instance || (this.instance = new this());
    }
}
exports.VideoTokensManager = VideoTokensManager;
//# sourceMappingURL=video-tokens-manager.js.map