Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function listProducts(projectId, location) {
// [START vision_product_search_list_products]
// Imports the Google Cloud client library
const vision = require('@google-cloud/vision');
// Creates a client
const client = new vision.ProductSearchClient();
/**
* TODO(developer): Uncomment the following line before running the sample.
*/
// const projectId = 'Your Google Cloud project Id';
// const location = 'A compute region name';
// Resource path that represents Google Cloud Platform location.
const locationPath = client.locationPath(projectId, location);
const [products] = await client.listProducts({parent: locationPath});
products.forEach(product => {
console.log(`Product name: ${product.name}`);
console.log(`Product id: ${product.name.split('/').pop()}`);
console.log(`Product display name: ${product.displayName}`);
console.log(`Product description: ${product.description}`);
async function listProductSets(projectId, location) {
// [START vision_product_search_list_product_sets]
// Imports the Google Cloud client library
const vision = require('@google-cloud/vision');
// Creates a client
const client = new vision.ProductSearchClient();
/**
* TODO(developer): Uncomment the following line before running the sample.
*/
// const projectId = 'Your Google Cloud project Id';
// const location = 'A compute region name';
// Resource path that represents Google Cloud Platform location.
const locationPath = client.locationPath(projectId, location);
const [productSets] = await client.listProductSets({parent: locationPath});
productSets.forEach(productSet => {
console.log(`Product Set name: ${productSet.name}`);
console.log(`Product Set display name: ${productSet.displayName}`);
});
// [END vision_product_search_list_product_sets]
async function getSimilarProductsGcs(
projectId,
location,
productSetId,
productCategory,
filePath,
filter
) {
// Imports the Google Cloud client library
const vision = require('@google-cloud/vision');
// Creates a client
const productSearchClient = new vision.ProductSearchClient();
const imageAnnotatorClient = new vision.ImageAnnotatorClient();
/**
* TODO(developer): Uncomment the following line before running the sample.
*/
// const projectId = 'Your Google Cloud project Id';
// const location = 'A compute region name';
// const productSetId = 'Id of the product set';
// const productCategory = 'Category of the product';
// const filePath = 'Local file path of the image to be searched';
// const filter = 'Condition to be applied on the labels';
const productSetPath = productSearchClient.productSetPath(
projectId,
location,
productSetId
);
async function createProductSet(
projectId,
location,
productSetId,
productSetDisplayName
) {
// [START vision_product_search_create_product_set]
// Imports the Google Cloud client library
const vision = require('@google-cloud/vision');
// Creates a client
const client = new vision.ProductSearchClient();
/**
* TODO(developer): Uncomment the following line before running the sample.
*/
// const projectId = 'Your Google Cloud project Id';
// const location = 'A compute region name';
// const productSetId = 'Id of the product set';
// const productSetDisplayName = 'Display name of the product set';
// Resource path that represents Google Cloud Platform location.
const locationPath = client.locationPath(projectId, location);
const productSet = {
displayName: productSetDisplayName,
};
async function updateProductLabels(projectId, location, productId, key, value) {
// [START vision_product_search_update_product_labels]
// Imports the Google Cloud client library
const vision = require('@google-cloud/vision');
// Creates a client
const client = new vision.ProductSearchClient();
/**
* TODO(developer): Uncomment the following line before running the sample.
*/
// const projectId = 'Your Google Cloud project Id';
// const location = 'A compute region name';
// const productId = 'Id of the product';
// const key = 'The key of the label';
// const value = 'The value of the label';
// Resource path that represents full path to the product.
const productPath = client.productPath(projectId, location, productId);
const product = {
name: productPath,
productLabels: [
async function listReferenceImage(projectId, location, productId) {
// [START vision_product_search_list_reference_images]
const vision = require('@google-cloud/vision');
const client = new vision.ProductSearchClient();
/**
* TODO(developer): Uncomment the following line before running the sample.
*/
// const projectId = 'Your Google Cloud project Id';
// const formattedParent = client.productPath(projectId, location, productId);
// const location = 'A compute region name';
// const productId = 'Id of the product';
const formattedParent = client.productPath(projectId, location, productId);
const request = {
parent: formattedParent,
};
const [response] = await client.listReferenceImages(request);
response.forEach(image => {
async function purgeOrphanProducts(projectId, location) {
// Deletes all products not in any product sets.
// Imports the Google Cloud client library
const vision = require('@google-cloud/vision');
// Creates a client
const client = new vision.ProductSearchClient();
/**
* TODO(developer): Uncomment the following line before running the sample.
*/
// const projectId = 'Your Google Cloud project Id';
// const location = 'A compute region name';
const formattedParent = client.locationPath(projectId, location);
// The operation is irreversible and removes multiple products.
// The user is required to pass in force=true to actually perform the purge.
// If force is not set to True, the service raises an error.
const force = true;
try {
const [operation] = await client.purgeProducts({
async function addProductToProductSet(
projectId,
location,
productId,
productSetId
) {
// [START vision_product_search_add_product_to_product_set]
const vision = require('@google-cloud/vision');
const client = new vision.ProductSearchClient();
/**
* TODO(developer): Uncomment the following line before running the sample.
*/
// const projectId = 'Your Google Cloud project Id';
// const location = 'A compute region name';
// const productId = 'Id of the product';
// const productSetId = 'Id of the product set';
const productPath = client.productPath(projectId, location, productId);
const productSetPath = client.productSetPath(
projectId,
location,
productSetId
);
async function getProductSet(projectId, location, productSetId) {
// [START vision_product_search_get_product_set]
// Imports the Google Cloud client library
const vision = require('@google-cloud/vision');
// Creates a client
const client = new vision.ProductSearchClient();
/**
* TODO(developer): Uncomment the following line before running the sample.
*/
// const projectId = 'Your Google Cloud project Id';
// const location = 'A compute region name';
// const productSetId = 'Id of the product set';
// Resource path that represents Google Cloud Platform location.
const productSetPath = client.productSetPath(
projectId,
location,
productSetId
);
const [productSet] = await client.getProductSet({name: productSetPath});
async function getSimilarProductsFile(
projectId,
location,
productSetId,
productCategory,
filePath,
filter
) {
// Imports the Google Cloud client library
const vision = require('@google-cloud/vision');
const fs = require('fs');
// Creates a client
const productSearchClient = new vision.ProductSearchClient();
const imageAnnotatorClient = new vision.ImageAnnotatorClient();
/**
* TODO(developer): Uncomment the following line before running the sample.
*/
// const projectId = 'nodejs-docs-samples';
// const location = 'us-west1';
// const productSetId = 'indexed_product_set_id_for_testing';
// const productCategory = 'apparel';
// const filePath = './resources/shoes_1.jpg';
// const filter = '';
const productSetPath = productSearchClient.productSetPath(
projectId,
location,
productSetId
);