diff --git a/blocks/aem-asset-selector/aem-asset-selector-util.js b/blocks/aem-asset-selector/aem-asset-selector-util.js index 2fa658909..a02ec9acb 100644 --- a/blocks/aem-asset-selector/aem-asset-selector-util.js +++ b/blocks/aem-asset-selector/aem-asset-selector-util.js @@ -57,7 +57,6 @@ const AS_MFE = 'https://experience.adobe.com/solutions/CQ-assets-selectors/stati const IMS_ENV_STAGE = 'stg1'; const IMS_ENV_PROD = 'prod'; const API_KEY = 'franklin'; -const WEB_TOOLS = 'https://master-sacred-dove.ngrok-free.app'; const REL_DOWNLOAD = 'http://ns.adobe.com/adobecloud/rel/download'; const REL_RENDITIONS = 'http://ns.adobe.com/adobecloud/rel/rendition'; // TODO: change this to Asset Link IMS client ID @@ -166,29 +165,6 @@ export function init(cfg, callback) { }); } -/** - * Generates a URL that can be used to retrieve an asset's binary - * without authentication. - * @param {string} url URL to the asset in AEM. - * @returns {Promise} Resolves with the public asset URL. - */ -async function getAssetPublicUrl(url) { - const response = await fetch(`${WEB_TOOLS}/asset-bin?src=${url}`, { - headers: { - Authorization: `Bearer ${imsInstance.getImsToken()}`, - 'x-api-key': API_KEY, - }, - }); - if (!response) { - throw new Error('No response from request'); - } - if (!response.ok) { - throw new Error(`Request failed with status ${response.status}: ${response.statusText}`); - } - const json = await response.json(); - return json['asset-url']; -} - /** * Retrieves the rendition that should be copied into the clipboard for * the given asset. @@ -216,24 +192,6 @@ function getCopyRendition(asset) { return maxRendition; } -/** - * Uses the navigator global object to write a clipboard item to the clipboard. - * The clipboard item's content will be an tag with the given URL as - * its src property. - * @param {string} assetPublicUrl URL to use as the image's src. - * @returns {Promise} Resolves when the item has been written to the clipboard. - */ -async function copyToClipboardWithHtml(assetPublicUrl) { - const assetMarkup = ``; - - const data = [ - // eslint-disable-next-line no-undef - new ClipboardItem({ 'text/html': new Blob([assetMarkup], { type: 'text/html' }) }), - ]; - // Write the new clipboard contents - return navigator.clipboard.write(data); -} - async function loadImageIntoHtmlElement(url) { return new Promise((resolve, reject) => { const img = new Image(); @@ -304,36 +262,6 @@ async function copyToClipboardWithBinary(assetPublicUrl, mimeType, asset) { return navigator.clipboard.write(data); } -/** - * Copies the given asset to the clipboard, without using the Repository API, - * and therefore avoiding calls directly to AEM. The primary case for using - * this method would be if AEM's CORS policies would deny requests from the - * asset selector. - * @param {Asset} asset Asset repository metadata, as provided by the asset - * selector. - * @returns {Promise} Resolves with true if the asset was - * copied successfully, otherwise resolves with false. - */ -export async function copyAssetWithoutRapi(asset) { - const maxRendition = getCopyRendition(asset); - if (!maxRendition) { - logMessage('No rendition to copy found'); - return false; - } - try { - const assetPublicUrl = await getAssetPublicUrl(maxRendition.href.substring(0, maxRendition.href.indexOf('?'))); - if (!assetPublicUrl) { - logMessage('Unable to generate public url for copy'); - return false; - } - await copyToClipboardWithHtml(assetPublicUrl); - } catch (e) { - logMessage('Error copying asset to clipboard', e); - return false; - } - return true; -} - /** * Copies the given asset to the clipboard, using the Repository API to * generate a download URL for the asset, then using the generated URL diff --git a/blocks/aem-asset-selector/aem-asset-selector.js b/blocks/aem-asset-selector/aem-asset-selector.js index f96770c8c..512c45903 100644 --- a/blocks/aem-asset-selector/aem-asset-selector.js +++ b/blocks/aem-asset-selector/aem-asset-selector.js @@ -15,7 +15,6 @@ import { init, renderAssetSelectorWithImsFlow, logoutImsFlow, - copyAssetWithoutRapi, copyAssetWithRapi, } from './aem-asset-selector-util.js'; @@ -54,8 +53,7 @@ export default async function decorate(block) { if (selected) { copy.classList.add('disabled'); copy.innerText = 'Copying...'; - const copyMethod = cfg['use-rapi'] ? copyAssetWithRapi : copyAssetWithoutRapi; - const success = await copyMethod(selected); + const success = await copyAssetWithRapi(selected); if (success) { copy.innerText = 'Copied!'; } else {