1 /** 2 * Workflow to move a list of assets/folders given their assetID/Path and their destination path using a REST call 3 */ 4 var REST = library.REST.REST(); 5 6 /** 7 * Moves the files or folders pushes them to the response 8 *@param theMoveJSON {"directory":<path to folder> "dest": <path to destination folder>} or {"id" : <assetID>, "dest":<path to destination folder>} 9 */ 10 function move(theMoveJSON) { 11 var aDest = REST.getFullPath(theMoveJSON.dest); 12 try { 13 var aFolderDest = new ManagedFolder(aDest); 14 } catch (err) { 15 REST.pushError( 16 REST.errors.e404, 17 "The dest folder does not exist: " + myDest 18 ); 19 return; 20 } 21 22 if (!!theMoveJSON.directory) { 23 var aFolder = null; 24 try { 25 aFolder = new ManagedFolder(REST.getFullPath(theMoveJSON.directory)); 26 } catch (err) { 27 REST.pushError( 28 REST.errors.e404, 29 "The src folder does not exist: " + theMoveJSON.directory 30 ); 31 return; 32 } 33 aFolder = fileManager.folderMove(aFolder, aFolderDest, aFolder.name); 34 REST.push(aFolder); 35 } else if (!!theMoveJSON.id) { 36 var aFile = fileManager.getFileObjectById(theMoveJSON.id); 37 if (!aFile) { 38 REST.pushError( 39 REST.errors.e404, 40 "The src file does not exist: " + theMoveJSON.id 41 ); 42 return; 43 } 44 aFile = fileManager.fileMove(aFile, aFolderDest); 45 REST.push(aFile); 46 } 47 } 48 49 /** 50 * @name Move 51 * @class Moves files and directories. 52 * @description Given the files/directories in "data" , this endpoint moves them to their destination directory 53 * @param data an array of files/directories and their destinations [{"directory":"To/Move/, "dest": "Destination/Folder"}, {"id" : 123456, "dest":"Destination/Folder"}, ...] 54 * @param [verbose=false] Setting this to true will collect a variety of default values for each asset. 55 * @param [fields] An array of field id's to collect the values for each asset 56 * @returns [{assetInfo},{directoryInfo}, ... ] 57 * 58 * @example /wf/restapi/v2/move 59 * 60 * Parameters: 61 * data=[{"directory":"To/Move/","dest":"Destination/Folder/"},{"id":201628784,"dest":"Destination/Folder/"}] 62 * verbose=true 63 * 64 * Response: 65 [ 66 { 67 "path": "Destination/Folder/Move/", 68 "name": "Move", 69 "resolver": "directory://261" 70 }, 71 { 72 "id": 201628784, 73 "name": "test.xmp", 74 "path": "Destination/Folder/test.xmp", 75 "height": 1, 76 "width": 1, 77 "bytes": 2048, 78 "lastModified": 1507578488000, 79 "mimeType": "application/octet-stream", 80 "previews": { 81 "thumbnail": "../servlet/jb.view?table=thumbnails&col=thumbnails&id=pe_323031363238373834", 82 "viewex": "../servlet/jb.view?table=viewex&col=viewex&id=pe_323031363238373834", 83 "downloadUrl": "../servlet/dload?id=pe_323031363238373834" 84 } 85 } 86 ] 87 */ 88 function main() { 89 REST.setCallback(move); 90 return REST.execute("data"); 91 } 92 main(); 93