1 /** 2 * Workflow to create folders given paths using a REST call 3 */ 4 var myData = {}; 5 var REST = library.REST.REST(); 6 /** 7 * Creates a new folder with the given path and adds an object to myData with the path 8 * @param theSource the path to the new folder 9 * @returns {*} 10 */ 11 function createFolder(theSource) { 12 if (fileManager.isFolder(theSource)) { 13 REST.submitError(theSource, "Folder already exists"); 14 return JSON.stringify(myData, null, 2); 15 } else { 16 var aCreatedFolder = fileManager.folderNewByPath(theSource); 17 myData[theSource] = aCreatedFolder.path; 18 } 19 } 20 21 function createFile(theSource) { 22 if (fileManager.isFile(theSource)) { 23 REST.submitError(theSource, "File already exists"); 24 } else { 25 var aNewFile = fileManager.fileNewByPath(theSource); 26 myData[aNewFile.assetId] = theSource; 27 } 28 } 29 30 function create(thePath) { 31 if (thePath[thePath.length - 1] != "/") { 32 createFile(thePath); 33 } else { 34 createFolder(thePath); 35 } 36 } 37 /** 38 * Creates new folders and returns the paths to them. 39 * @description Creates new folders for the list of paths in 'src' and returns the paths to the new folders. These 40 * path values are parsed into a text object keyed by AssetID from the JSON file in which they are contained, and by 41 * default are displayed to the user. 42 * @example 'MBurl'/wf/restapi/1/create?src=["FolderPath/FilePath"] 43 * @example <a target="_blank" href=http://127.0.0.1:55555/wf/restapi/1/create?src=["Assets/Library/test.txt"]>http://127.0.0.1:55555/wf/restapi/1/create?src=["Assets/Library/test.txt"]</a> 44 * @class Creates new folders and returns the paths to them. 45 * @name Create 46 * @param src Path or paths of the new folders. 47 * @returns ( {'AssetID': "path",...} ) 48 */ 49 function main() { 50 var aParameters = REST.getParametersToIterate("src"); 51 if (myData.error != null) { 52 return REST.formatResponse(); 53 } 54 REST.iterateThroughParameters(aParameters, create); 55 return REST.formatResponse(); 56 } 57 main(); 58