added prints bucket commands

This commit is contained in:
Arwid Thornström
2025-01-22 09:41:06 +01:00
parent 4bb789be7c
commit 49deffc8ba
4 changed files with 113 additions and 102 deletions
+31
View File
@@ -0,0 +1,31 @@
export const createPrintBucketStationList = async (toolbox, bucket) => {
const { system } = toolbox;
// List all the folders on root level in bucket photowall-prints-dev
const allFiles = await system.run(
`aws s3api list-objects-v2 --bucket ${bucket} --output json`
);
const allFilesArray = JSON.parse(allFiles);
// Organize all the files in different folder if the folder name starts with station
const stations = [];
for (const file of allFilesArray.Contents) {
if (file.Key.startsWith('station')) {
// Get the station name
const stationName = file.Key.split('/')[0];
if (!stations[stationName]) {
stations[stationName] = [];
}
// Then push the file into the station
stations[stationName].push(file);
}
}
// Take all the station and create another list with the station and the number of files
const stationList = [];
for (const station in stations) {
stationList.push(`${station} (${stations[station].length} files)`);
}
return { stationNames: stationList, stationFiles: stations };
};