UNPKG

@bratcliffe909/mcp-server-segmind

Version:

Model Context Protocol server for Segmind API - Generate images and videos using AI models

62 lines 1.7 kB
class ImageCache { cache = new Map(); maxAge = 15 * 60 * 1000; maxSize = 10; generateId() { return `img_${Date.now()}_${Math.random().toString(36).substring(7)}`; } store(base64, mimeType, path) { this.cleanup(); if (this.cache.size >= this.maxSize) { const entries = Array.from(this.cache.entries()) .sort((a, b) => a[1].timestamp - b[1].timestamp); if (entries.length > 0 && entries[0]) { this.cache.delete(entries[0][0]); } } const id = this.generateId(); this.cache.set(id, { base64, mimeType, path, size: base64.length, timestamp: Date.now(), }); return id; } get(id) { const image = this.cache.get(id); if (image && Date.now() - image.timestamp > this.maxAge) { this.cache.delete(id); return undefined; } return image; } has(id) { return this.get(id) !== undefined; } cleanup() { const now = Date.now(); for (const [id, image] of this.cache.entries()) { if (now - image.timestamp > this.maxAge) { this.cache.delete(id); } } } clear() { this.cache.clear(); } getStats() { this.cleanup(); let totalSize = 0; for (const image of this.cache.values()) { totalSize += image.size; } return { count: this.cache.size, totalSize, }; } } export const imageCache = new ImageCache(); //# sourceMappingURL=image-cache.js.map