disable the cleanupInteriors function but keep the functionality (#181)

This commit is contained in:
Arwid Thornström
2025-11-03 10:41:31 +01:00
committed by GitHub
parent 3259fa702c
commit 82e001aaaf
+28 -23
View File
@@ -993,6 +993,9 @@ export class ProductAPI extends BaseSQLDataSource {
/** /**
* @function cleanupInteriors * @function cleanupInteriors
* @description Removes all not used interiors from a product * @description Removes all not used interiors from a product
*
* This function is disabled until we know what to do with dynamic interiors.
* Right now its not good if interiors are removed from s3.
*/ */
async cleanupInteriors( async cleanupInteriors(
productId: number, productId: number,
@@ -1003,36 +1006,38 @@ export class ProductAPI extends BaseSQLDataSource {
Scopes.INTERIORS_WRITE, Scopes.INTERIORS_WRITE,
]); ]);
// Get all interior files for product on s3 // // Get all interior files for product on s3
const files = await listS3Files( // const files = await listS3Files(
CONFIG.imageBucket, // CONFIG.imageBucket,
`interiors/${productId}`, // `interiors/${productId}`,
); // );
const shouldKeep = []; // const shouldKeep = [];
const shouldRemove = []; // const shouldRemove = [];
// Convert to match key format from s3 // // Convert to match key format from s3
const currentUris = currentInteriors.map((item) => item.uri.substring(1)); // const currentUris = currentInteriors.map((item) => item.uri.substring(1));
// Go through all files on s3 and organize as delete or keep // // Go through all files on s3 and organize as delete or keep
for (const file of files) { // for (const file of files) {
if (currentUris.includes(file.Key)) { // if (currentUris.includes(file.Key)) {
shouldKeep.push(file.Key); // shouldKeep.push(file.Key);
} else { // } else {
shouldRemove.push(file.Key); // shouldRemove.push(file.Key);
} // }
} // }
// Setup all delete actions // Setup all delete actions
let removed = []; // let removed = [];
if (shouldRemove.length > 0) { // if (shouldRemove.length > 0) {
const response = await deleteFiles(CONFIG.imageBucket, shouldRemove); // const response = await deleteFiles(CONFIG.imageBucket, shouldRemove);
removed = response.Deleted?.map((item) => item.Key) || []; // removed = response.Deleted?.map((item) => item.Key) || [];
} // }
// Return what we did // Return what we did
return { active: shouldKeep, deleted: removed }; // This is temporary disabled until we know what to do with the interiors.
return { active: [], deleted: [] };
// return { active: shouldKeep, deleted: removed };
} }
/** /**