disable the cleanupInteriors function but keep the functionality (#181)
This commit is contained in:
@@ -993,6 +993,9 @@ export class ProductAPI extends BaseSQLDataSource {
|
||||
/**
|
||||
* @function cleanupInteriors
|
||||
* @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(
|
||||
productId: number,
|
||||
@@ -1003,36 +1006,38 @@ export class ProductAPI extends BaseSQLDataSource {
|
||||
Scopes.INTERIORS_WRITE,
|
||||
]);
|
||||
|
||||
// Get all interior files for product on s3
|
||||
const files = await listS3Files(
|
||||
CONFIG.imageBucket,
|
||||
`interiors/${productId}`,
|
||||
);
|
||||
// // Get all interior files for product on s3
|
||||
// const files = await listS3Files(
|
||||
// CONFIG.imageBucket,
|
||||
// `interiors/${productId}`,
|
||||
// );
|
||||
|
||||
const shouldKeep = [];
|
||||
const shouldRemove = [];
|
||||
// const shouldKeep = [];
|
||||
// const shouldRemove = [];
|
||||
|
||||
// Convert to match key format from s3
|
||||
const currentUris = currentInteriors.map((item) => item.uri.substring(1));
|
||||
// // Convert to match key format from s3
|
||||
// const currentUris = currentInteriors.map((item) => item.uri.substring(1));
|
||||
|
||||
// Go through all files on s3 and organize as delete or keep
|
||||
for (const file of files) {
|
||||
if (currentUris.includes(file.Key)) {
|
||||
shouldKeep.push(file.Key);
|
||||
} else {
|
||||
shouldRemove.push(file.Key);
|
||||
}
|
||||
}
|
||||
// // Go through all files on s3 and organize as delete or keep
|
||||
// for (const file of files) {
|
||||
// if (currentUris.includes(file.Key)) {
|
||||
// shouldKeep.push(file.Key);
|
||||
// } else {
|
||||
// shouldRemove.push(file.Key);
|
||||
// }
|
||||
// }
|
||||
|
||||
// Setup all delete actions
|
||||
let removed = [];
|
||||
if (shouldRemove.length > 0) {
|
||||
const response = await deleteFiles(CONFIG.imageBucket, shouldRemove);
|
||||
removed = response.Deleted?.map((item) => item.Key) || [];
|
||||
}
|
||||
// let removed = [];
|
||||
// if (shouldRemove.length > 0) {
|
||||
// const response = await deleteFiles(CONFIG.imageBucket, shouldRemove);
|
||||
// removed = response.Deleted?.map((item) => item.Key) || [];
|
||||
// }
|
||||
|
||||
// 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 };
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user