UNPKG

rednote-mcp

Version:

A friendly tool to help you access and interact with Xiaohongshu (RedNote) content through Model Context Protocol.

48 lines (47 loc) 2.06 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.CookieManager = void 0; const fs_1 = __importDefault(require("fs")); const path_1 = __importDefault(require("path")); const logger_1 = __importDefault(require("../utils/logger")); class CookieManager { constructor(cookiePath) { logger_1.default.info(`Initializing CookieManager with path: ${cookiePath}`); this.cookiePath = cookiePath; } async saveCookies(cookies) { logger_1.default.info(`Saving ${cookies.length} cookies to ${this.cookiePath}`); const dir = path_1.default.dirname(this.cookiePath); if (!fs_1.default.existsSync(dir)) { logger_1.default.info(`Creating directory: ${dir}`); fs_1.default.mkdirSync(dir, { recursive: true }); } await fs_1.default.promises.writeFile(this.cookiePath, JSON.stringify(cookies, null, 2)); logger_1.default.info('Cookies saved successfully'); } async loadCookies() { if (!fs_1.default.existsSync(this.cookiePath)) { logger_1.default.info('No cookies file found, returning empty array'); return []; } logger_1.default.info(`Loading cookies from ${this.cookiePath}`); const data = await fs_1.default.promises.readFile(this.cookiePath, 'utf-8'); const cookies = JSON.parse(data); logger_1.default.info(`Loaded ${cookies.length} cookies`); return cookies; } async clearCookies() { if (fs_1.default.existsSync(this.cookiePath)) { logger_1.default.info(`Clearing cookies at ${this.cookiePath}`); await fs_1.default.promises.unlink(this.cookiePath); logger_1.default.info('Cookies cleared successfully'); } else { logger_1.default.info('No cookies file found to clear'); } } } exports.CookieManager = CookieManager;