63 lines
1.6 KiB
JavaScript
Executable File
63 lines
1.6 KiB
JavaScript
Executable File
#!/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);
|
|
});
|