Files
pwcli/src/commands/aws/s3/clear_prints/clear_prints.ts
T
Arwid ThornströmandGitHub 5c43d166ba Update libs (#28)
* added prompt context library

* updated libs, except chalk that should not be updated

* updated libs and fixed speed
2025-06-17 10:12:48 +02:00

48 lines
1.5 KiB
TypeScript

import { GluegunMenuToolbox } from '@lenne.tech/gluegun-menu';
import chalk = require('chalk');
import { defaultMenuSettings } from '../../../../globals';
import { createPrintBucketStationList } from '../../../../services/aws_s3';
const { AutoComplete, Confirm } = require('enquirer');
module.exports = {
name: 'clear-prints',
alias: ['cp'],
description: 'Clear prints-dev bucket on S3 (a s3 cp)',
hidden: false,
run: async (toolbox: GluegunMenuToolbox) => {
const { system } = toolbox;
const stationListDev = await createPrintBucketStationList(
toolbox,
'photowall-prints-dev',
);
// Now show these in a enquiere prompt where the user can search and choose a folder
const prompt = new AutoComplete({
message: 'Choose a folder',
choices: stationListDev.stationNames,
});
const folder = await prompt.run();
const stationName = folder.split(' ')[0];
// Ask the user if he wants to delete all the files in that station
const confirm = new Confirm({
message: `Do you want to delete all the files in ${chalk.yellow(
stationName,
)}?`,
});
const deleteAll = await confirm.run();
if (deleteAll) {
// Delete all the files in that station
for (const file of stationListDev.stationFiles[stationName]) {
await system.run(`aws s3 rm s3://photowall-prints-dev/${file.Key}`);
}
}
if (toolbox.fromMenu()) {
await toolbox.menu.showMenu('aws s3', defaultMenuSettings);
}
},
};