feat: 重构 NodeJS 版本图片处理工具

This commit is contained in:
2026-06-01 22:16:50 +08:00
parent 0922035a4c
commit d277a6118f
4 changed files with 572 additions and 0 deletions
+62
View File
@@ -0,0 +1,62 @@
#!/usr/bin/env node
const { createInterface, showMenu } = require('./utils');
const { runFormatTool } = require('./format');
const { runRecoverExifTool } = require('./recover-exif');
async function main() {
const rl = createInterface();
console.log('\n🎨 图片工具箱');
console.log('=' .repeat(50));
console.log('欢迎使用图片处理工具集合!\n');
try {
while (true) {
const options = [
'📸 图片格式转换 (压缩并调整尺寸)',
'🔧 EXIF 信息恢复 (从原始图片恢复元数据)',
'❌ 退出'
];
const choice = await showMenu(rl, '\n请选择功能', options);
if (choice === -1) {
console.log('❌ 无效的选择,请重新输入');
continue;
}
if (choice === 0) {
// 图片格式转换
await runFormatTool(rl);
} else if (choice === 1) {
// EXIF 信息恢复
await runRecoverExifTool(rl);
} else if (choice === 2) {
// 退出
console.log('\n👋 再见!');
break;
}
// 询问是否继续
const continueChoice = await new Promise((resolve) => {
rl.question('\n是否继续使用其他功能? (y/n): ', resolve);
});
if (continueChoice.toLowerCase() !== 'y' && continueChoice.toLowerCase() !== 'yes') {
console.log('\n👋 再见!');
break;
}
}
} catch (error) {
console.error('\n❌ 发生错误:', error.message);
} finally {
rl.close();
}
}
// 运行主程序
main().catch(error => {
console.error('❌ 程序异常:', error);
process.exit(1);
});