const fs = require('fs');
const path = require('path');
const { v4: uuidv4 } = require('uuid');
/**
* Archives text block content for short-lived tasks with verbose logging.
* @param {string} title - Title of the archived content.
* @param {string} content - The text content to archive.
*/
function archiveText(title, content) {
const timestamp = new Date().toISOString();
const filename = `${timestamp}_${uuidv4()}.txt`; // Unique filename
const filepath = path.join(__dirname, 'archives', filename); // Archive directory
// Ensure the archives directory exists
if (!fs.existsSync(path.join(__dirname, 'archives'))) {
fs.mkdirSync(path.join(__dirname, 'archives'));
}
try {
fs.writeFileSync(filepath, content); // Write content to file
console.log(`[INFO] Archived content: ${title} to ${filepath}`); // Verbose log
} catch (error) {
console.error(`[ERROR] Failed to archive content: ${error.message}`); // Verbose log
}
}
module.exports = archiveText;
Add your comment