Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add temporary workaround for AEM presigned photoshopAction urls #29

Merged
merged 5 commits into from
Dec 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 29 additions & 4 deletions projects/worker-cc-photoshop/actions/worker-cc-photoshop/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const sdk = require('@adobe/aio-lib-photoshop-api');
const libFiles = require('@adobe/aio-lib-files');
const { v4: uuidv4 } = require("uuid");
const { AioLibFilesMock } = require("../../lib/mock-aio-lib-files");
const path = require("path");
const { downloadFile } = require('@adobe/httptransfer');

/**
* Acquire authorization
Expand Down Expand Up @@ -51,11 +53,34 @@ function getAuthorization(params) {
* @param {Object} instructions Rendition instructions
* @returns {Object} options for Photoshop Actions Api request
*/
async function setupPhotoshopActionsOptions(client, instructions) {
async function setupPhotoshopActionsOptions(client, instructions, files) {
if (!instructions || !instructions.photoshopAction) {
throw Error("Photoshop Action url not provided");
}
const options = await client.fileResolver.resolveInputsPhotoshopActionsOptions({ actions: instructions.photoshopAction });

// workaround for action files from AEM
// we must download the action file and add the `.atn`
// extension to the file so Photoshop Service can
// recognize it
let photoshopAction = instructions.photoshopAction;
let ext;
try {
ext = path.extname(photoshopAction).substring(1).toLowerCase();
} catch (err) {
}
if (!ext) {
const tempActionFilename = `${uuidv4()}_temp.atn`;
const aioLibActionFilename = `${uuidv4()}/photoshopaction.atn`;
await downloadFile(photoshopAction, tempActionFilename);
await files.copy(tempActionFilename, aioLibActionFilename, { localSrc: true });
photoshopAction = aioLibActionFilename;

}
const options = {
actions: [{
href: photoshopAction
}]
}
if (options && Array.isArray(options.actions) && instructions.photoshopActionName) {
options.actions[0].actionName = instructions.photoshopActionName;
}
Expand All @@ -82,7 +107,7 @@ exports.main = worker(async (source, rendition, params) => {
const tempFilename = `${uuidv4()}/rendition.${fmt}`;

// call photoshopActions API
const options = await setupPhotoshopActionsOptions(client, rendition.instructions);
const options = await setupPhotoshopActionsOptions(client, rendition.instructions, files);
const result = await client.applyPhotoshopActions(source.url, tempFilename, options);
console.log('Response from Photoshop API', result);
if (result && result.outputs && result.outputs[0].status === 'failed') {
Expand All @@ -97,4 +122,4 @@ exports.main = worker(async (source, rendition, params) => {
await files.delete(tempFilename);
}, {
disableSourceDownload: true
});
});
2 changes: 1 addition & 1 deletion projects/worker-cc-photoshop/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion projects/worker-cc-photoshop/package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"name": "worker-cc-photoshop",
"version": "1.0.1",
"version": "1.1.1",
"private": true,
"description": "Asset Compute custom worker leveraging Photoshop Actions in the Photoshop API",
"dependencies": {
"@adobe/aio-lib-files": "^2.0.0",
"@adobe/aio-lib-photoshop-api": "0.0.4-beta.2",
"@adobe/asset-compute-sdk": "^2.2.1",
"@adobe/httptransfer": "^2.0.1",
"uuid": "^8.3.2"
},
"devDependencies": {
Expand Down