Open source candidates with configured browser
This commit is contained in:
@@ -240,6 +240,31 @@ export async function getProductPictures(
|
||||
};
|
||||
}
|
||||
|
||||
export async function openProductSource(config, { manufacturerId, sourceKey, url }) {
|
||||
const sourceUrl = normalizeSourceUrl(url);
|
||||
const mapping = await listMappingSources(config, { manufacturerId });
|
||||
const source = mapping.items.find(
|
||||
(item) => item.enabled && String(item.key ?? "").toLowerCase() === String(sourceKey ?? "").toLowerCase(),
|
||||
);
|
||||
|
||||
if (!source) {
|
||||
throw new Error("Source mapping was not found for selected manufacturer.");
|
||||
}
|
||||
|
||||
await openInBrowser(sourceUrl, { engine: source.browserEngine });
|
||||
|
||||
return {
|
||||
configured: mapping.configured,
|
||||
opened: true,
|
||||
source: {
|
||||
key: source.key,
|
||||
name: source.name,
|
||||
browserEngine: source.browserEngine,
|
||||
},
|
||||
url: sourceUrl,
|
||||
};
|
||||
}
|
||||
|
||||
async function findSourceCandidates(source, product, { includePictures = false } = {}) {
|
||||
const searchAttempts = buildAdapterSearchUrls(source, product);
|
||||
let lastSearchUrl = searchAttempts[0]?.url || normalizeSourceUrl(source.url);
|
||||
|
||||
Reference in New Issue
Block a user