1 /** 2 * Workflow to get completed assets. 3 */ 4 var REST = library.REST.REST(); 5 6 /** 7 * Gets the array of completed assets. 8 */ 9 function getCompletedAssets() { 10 var aTasksInfo = context.getParameter("tasksInfo"); 11 if (aTasksInfo === null || aTasksInfo.length === 0) 12 { 13 REST.pushError(REST.errors.e400, "Failed to get 'tasksInfo' request parameter"); 14 return; 15 } 16 var aCompletedAssetPaths = []; 17 for (var i = 0; i < aTasksInfo.length; i++) 18 { 19 var aStatus = fileManager.getFileActionStatus(aTasksInfo[i].actionId); 20 if (aStatus === 0 || aStatus === 1) 21 { 22 return; 23 } 24 aCompletedAssetPaths.push(aTasksInfo[i].path); 25 } 26 for (i = 0; i < aCompletedAssetPaths.length; i++) 27 { 28 try 29 { 30 var aManagedFile = new ManagedFile(REST.getFullPath(aCompletedAssetPaths[i])); 31 REST.push(aManagedFile); 32 } catch (theE) 33 { 34 REST.pushError( 35 REST.errors.e404, 36 "The file with the path does not exist: '" + aCompletedAssetPaths[i] + "'", 37 REST.errors.e404 38 ); 39 return; 40 } 41 } 42 } 43 44 /** 45 * @name GetCompletedAssets 46 * @class Gets the array of completed assets 47 * @description This endpoint gets the array of completed assets 48 * @param [{actionId: "5365EB12-63E1-4F6D-B60C-7DBADD2AFC3A", path: "asset/data/path1.txt"}, ...] 49 * @returns [{assetInfo}, ... ] 50 * 51 * @example /wf/restapi/v2/getCompletedAssets 52 * 53 * Parameters: 54 * actionIds=[{actionId: "5365EB12-63E1-4F6D-B60C-7DBADD2AFC3A", path: "asset/data/path1.txt"}, {actionId: "B437A4E7-BEF6-4750-8869-80DC4710DF86", path: "asset/data/path2.txt"}] 55 * 56 Response: 57 [ 58 { 59 "id": 201629307, 60 "name": "path1.txt", 61 "path": "asset/data/path1.txt", 62 "height": 0, 63 "width": 0, 64 "bytes": 0, 65 "lastModified": 1507845948000, 66 "mimeType": "text/plain", 67 "previews": { 68 "thumbnail": "../servlet/jb.view?table=thumbnails&col=thumbnails&id=pe_323031363239333037", 69 "viewex": "../servlet/jb.view?table=viewex&col=viewex&id=pe_323031363239333037", 70 "downloadUrl": "../servlet/dload?id=pe_323031363239333037" 71 } 72 }, 73 { 74 "id": 201629308, 75 "name": "path2.txt", 76 "path": "asset/data/path2.txt", 77 "height": 0, 78 "width": 0, 79 "bytes": 0, 80 "lastModified": 1507845948000, 81 "mimeType": "text/plain", 82 "previews": { 83 "thumbnail": "../servlet/jb.view?table=thumbnails&col=thumbnails&id=pe_323031363239333038", 84 "viewex": "../servlet/jb.view?table=viewex&col=viewex&id=pe_323031363239333038", 85 "downloadUrl": "../servlet/dload?id=pe_323031363239333038" 86 } 87 } 88 ] 89 */ 90 (function main() { 91 REST.setCallback(getCompletedAssets); 92 return REST.execute(); 93 })();