UNPKG

@tsavo/printify-mcp

Version:

A Model Context Protocol (MCP) server for integrating AI assistants with Printify's print-on-demand platform

58 lines 1.56 kB
/** * File utilities for Printify MCP */ import * as fs from 'fs'; import * as path from 'path'; /** * Ensure a directory exists, creating it if necessary */ export function ensureDirectoryExists(dirPath) { if (!fs.existsSync(dirPath)) { fs.mkdirSync(dirPath, { recursive: true }); console.log(`Created directory: ${dirPath}`); } } /** * Generate a temporary file path */ export function generateTempFilePath(baseDir, fileName, extension = 'png') { // Ensure the directory exists ensureDirectoryExists(baseDir); // Generate a unique filename with timestamp const uniqueFileName = `${Date.now()}_${fileName}.${extension}`; return path.resolve(path.join(baseDir, uniqueFileName)); } /** * Clean up temporary files */ export function cleanupFiles(filePaths) { filePaths.forEach(filePath => { if (filePath && fs.existsSync(filePath)) { try { fs.unlinkSync(filePath); console.log(`Cleaned up file: ${filePath}`); } catch (error) { console.error(`Error cleaning up file ${filePath}:`, error); } } }); } /** * Get file information */ export function getFileInfo(filePath) { if (!filePath) { return { exists: false }; } if (fs.existsSync(filePath)) { const stats = fs.statSync(filePath); return { exists: true, size: stats.size, stats }; } return { exists: false }; } //# sourceMappingURL=file-utils.js.map