32 lines
1.1 KiB
TypeScript
32 lines
1.1 KiB
TypeScript
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 };
|
|
};
|