in frontend/src/app/content-creator/product/add-product/add-product.component.ts [163:195]
async generate() {
if (this.selectedFiles) {
this.loading = true;
this.imagesNames = await Promise.all(
Array.from(this.selectedFiles).map(
async (file) => this.firebaseService.uploadImageToStorage(file).then(
(snapshot: UploadTaskSnapshot): string => {
return snapshot.metadata.name as string;
}))) as string[];
this.isGenerated = true;
this.creatorService.detectProductCategories(this.imagesNames).subscribe(async (res: any) => {
this.generatedJSON = res;
this.labels = res.vision_labels;
this.features = res.images_features;
this.categories = res.images_categories;
const similarCategories: string[][] = await Promise.all(res.similar_products.map(
async (similarProductId: string) =>
firstValueFrom(this.productService.getProduct(similarProductId)).then((res: any) =>
res.categories
)));
this.categories = [...new Set(this.categories.concat(...similarCategories))];
this.imagesURLs = [];
this.imagesNames.map(
(imageName) => this.firebaseService.imageNameToDownloadURL(imageName).then(
(imageURL) => this.imagesURLs.push(imageURL)));
this.similar_products = res.similar_products;
this.loading = false;
this.stepper.next();
});
}
}