1 /** 2 * Workflow to Import files or folders using a REST call 3 */ 4 var REST = library.REST.REST(); 5 var myData = {}; 6 7 //Import parameters 8 var myImportParameters = null; 9 var kUpdateTypes = { 10 viewanddata: 0, 11 data: 1, 12 view: 2, 13 forceview: 3, 14 }; 15 16 /** 17 * Imports the source file or folder and adds an object containing the assetId/folderPath to myData 18 * 19 * @param theSource the file or folder to import 20 */ 21 function fileOrFolderImport(theSource) { 22 var aToImport = null; 23 var aIsFile = false; 24 if (isNaN(theSource)) { 25 if (fileManager.isFile(theSource)) { 26 aToImport = new UnmanagedFile(theSource); 27 aIsFile = true; 28 } else if (fileManager.isFolder(theSource)) { 29 aToImport = new UnmanagedFolder(theSource); 30 } 31 } else { 32 aToImport = fileManager.getFileObjectById(theSource); 33 aIsFile = true; 34 } 35 if (aToImport == null) { 36 REST.submitError(theSource, "Could not find file or folder: " + theSource); 37 return; 38 } 39 40 //Import file or folder and add data to output object 41 var aManaged; 42 if (aIsFile) { 43 aManaged = fileManager.fileImport(aToImport, myImportParameters); 44 //if the user gave us an asset id, we give them the path 45 myData[theSource] = isNaN(theSource) ? aManaged.assetId : aManaged.path; 46 } else { 47 aManaged = fileManager.folderImportWithParameters( 48 aToImport, 49 myImportParameters 50 ); 51 myData[theSource] = aManaged.path; 52 } 53 54 //Trigger asset added on new assets 55 if (aToImport instanceof UnmanagedFile && !!aManaged) { 56 workflowManager.triggerAssetAdded(aManaged); 57 } 58 } 59 60 /** 61 * Imports files or folders and returns their paths. 62 * @description Imports all of the folders and files specified by assetID in 'src' and returns their paths. These paths are parsed into a text object keyed by AssetID from the JSON file in which they are contained, and by default are displayed to the user. 63 * @example 'MBurl'/wf/restapi/1/import?src=["AssetID"] 64 * @example <a target="_blank" href=http://127.0.0.1:55555/wf/restapi/1/import?src=["12345"]>http://127.0.0.1:55555/wf/restapi/1/import?src=["12345"]</a> 65 * @example <a target="_blank" href=http://127.0.0.1:55555/wf/restapi/1/import?src=A/B/C/file.txt>http://127.0.0.1:55555/wf/restapi/1/import?src=A/B/C/file.txt</a> 66 * @example <a target="_blank" href=http://127.0.0.1:55555/wf/restapi/1/import?src=["A/B/C/","A/B/C/file.txt"]>http://127.0.0.1:55555/wf/restapi/1/import?src=["A/B/C/","A/B/C/file.txt"]</a> 67 * @class Imports files or folders and returns their paths/ids. 68 * @name Import 69 * @param src a single asset id, asset path or directory path or an array of any combination of id's/paths. src=12345 or src=["A/B/C/","A/B/C/file.txt", 123456] 70 * @param updateType Options are:<br> 71 * 'ViewAndData' - previews and metadata potentially will be updated. Does not update on demand previews.<br> 72 * 'Data' - metadata potentially will be updated.<br> 73 * 'View' - previews potentially will be updated. Does not update on demand previews.<br> 74 * 'ForceView' - the creation of a new preview request will be force regardless of the state of the cache and preview queue. 75 * On demand previews will be cleared. 76 * @returns ( {'AssetID': "path",...} ) 77 */ 78 function main() { 79 var aParameters = REST.getParametersToIterate("src"); 80 if (myData.error != null) { 81 return REST.formatResponse(); 82 } 83 var anUpdateType = REST.getParameter("updateType", false); 84 myImportParameters = new ImportParameters(); 85 var aNumUpdate = !anUpdateType 86 ? null 87 : kUpdateTypes[anUpdateType.toLowerCase()]; 88 if (!!aNumUpdate) { 89 myImportParameters.setUpdateType(aNumUpdate); 90 } 91 REST.iterateThroughParameters(aParameters, fileOrFolderImport); 92 return REST.formatResponse(); 93 } 94 main(); 95