1 var REST = library.REST.REST(); 2 var myData = {}; 3 var myType; 4 var myTranscodings; 5 6 function convertToHex(str) { 7 var hex = ""; 8 for (var i = 0; i < str.length; i++) { 9 hex += "" + str.charCodeAt(i).toString(16); 10 } 11 return hex; 12 } 13 14 function getTranscodingsPath(theFile) { 15 var aPathMinusFileName = theFile.path.substring( 16 0, 17 theFile.path.indexOf(theFile.name) 18 ); 19 var aNameMinusExt = theFile.name.substring(0, theFile.name.lastIndexOf(".")); 20 var aTransCodingsFileName = "m-transcodings"; 21 if (args("mb.prefix.transcodings.folder", "false") === "true") { 22 aTransCodingsFileName = "~$" + aTransCodingsFileName; 23 } 24 var aFolder = new UnmanagedFolder(aPathMinusFileName + aTransCodingsFileName); 25 var aContents = aFolder.getContents(1); 26 while (aContents.hasNext()) { 27 var aFile = aContents.next(); 28 if ( 29 aFile.name.indexOf(aNameMinusExt) >= 0 && 30 aFile.name.indexOf(".mp4") >= 0 31 ) { 32 var aPath = aFile.getRelativePath(); 33 if (aPath[aPath.length - 1] == system.getFileSeparator()) { 34 aPath = aPath.substring(0, aPath.length - 1); 35 } 36 return "pe_" + convertToHex(aPath); 37 } 38 } 39 REST.submitError(theFile.assetId, "Failed to find asset mp4 transcodings"); 40 return; 41 } 42 43 function getPreviewUrl(theAssetId) { 44 var anAsset = fileManager.getFileObjectById(theAssetId); 45 if (anAsset == null) { 46 REST.submitError(theAssetId, "Failed to find asset"); 47 return; 48 } 49 if (myType == "thumbnail") { 50 myData[theAssetId] = 51 context.getBaseUrl() + 52 "/servlet/jb.view?table=" + 53 myType + 54 "s" + 55 "&col=" + 56 myType + 57 "&id=" + 58 anAsset.encodedAssetId + 59 "&" + 60 REST.getAuthParam(); 61 } else if (myType == "viewex") { 62 myData[theAssetId] = 63 context.getBaseUrl() + 64 "/servlet/jb.view?table=" + 65 myType + 66 "&col=" + 67 myType + 68 "&id=" + 69 anAsset.encodedAssetId + 70 "&" + 71 REST.getAuthParam(); 72 } else { 73 if (myTranscodings) { 74 var aPath = getTranscodingsPath(anAsset); 75 if (myData.error != null) { 76 return; 77 } 78 myData[theAssetId] = 79 context.getBaseUrl() + 80 "/servlet/dload/mb_video.mp4?id=" + 81 anAsset.encodedAssetId + 82 "&" + 83 REST.getAuthParam() + 84 "&path=" + 85 aPath; 86 } else { 87 myData[theAssetId] = 88 context.getBaseUrl() + 89 "/servlet/dload/" + anAsset.name + "?id=" + 90 anAsset.encodedAssetId + 91 "&" + 92 REST.getAuthParam(); 93 } 94 } 95 } 96 /** 97 * Returns the url of the asset previews 98 * @description Locates assets by the list of AssetIDs in 'src' and returns a url to their images. These values 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. 99 * @example 'MBurl'/wf/restapi/1/getPreviews?src=["AssetID"] 100 * @example <a target="_blank" href=http://127.0.0.1:55555/wf/restapi/1/getPreviews?src=["12345"]&type=thumbnails>http://127.0.0.1:55555/wf/restapi/1/getPreviews?src=["12345"]&type=thumbnails</a> 101 * @class Returns the url of the asset previews 102 * @name GetPreviews 103 * @param src AssetID/list of assetIDs to get the paths from. 104 * @param type 'thumbnail' or 'viewex' or empty for full image 105 * @param trans set to true to download mp4 transcodings else false for original (default is false 106 * @returns ( {'AssetID': "path",...} ) 107 */ 108 function main() { 109 myType = REST.getParameter("type", false); 110 myTranscodings = REST.getParameter("trans", false); 111 var aParameters = REST.getParametersToIterate("src"); 112 if (myData.error != null) { 113 return REST.formatResponse(); 114 } 115 REST.iterateThroughParameters(aParameters, getPreviewUrl); 116 return REST.formatResponse(); 117 } 118 main(); 119