UNPKG

fluro

Version:

Promise based HTTP Fluro client for the browser and node.js

771 lines (554 loc) 31.8 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>fluro.asset.js - Documentation</title> <script src="scripts/prettify/prettify.js"></script> <script src="scripts/prettify/lang-css.js"></script> <!--[if lt IE 9]> <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <link type="text/css" rel="stylesheet" href="styles/prettify.css"> <link type="text/css" rel="stylesheet" href="styles/jsdoc.css"> <script src="scripts/nav.js" defer></script> <meta name="viewport" content="width=device-width, initial-scale=1.0"> </head> <body> <input type="checkbox" id="nav-trigger" class="nav-trigger" /> <label for="nav-trigger" class="navicon-button x"> <div class="navicon"></div> </label> <label for="nav-trigger" class="overlay"></label> <nav > <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="access.html">access</a><ul class='methods'><li data-type='method'><a href="access.html#.addEventListener">addEventListener</a></li><li data-type='method'><a href="access.html#.can">can</a></li><li data-type='method'><a href="access.html#.canDeleteItem">canDeleteItem</a></li><li data-type='method'><a href="access.html#.canEditItem">canEditItem</a></li><li data-type='method'><a href="access.html#.canKnowOf">canKnowOf</a></li><li data-type='method'><a href="access.html#.canViewItem">canViewItem</a></li><li data-type='method'><a href="access.html#.has">has</a></li><li data-type='method'><a href="access.html#.isAuthor">isAuthor</a></li><li data-type='method'><a href="access.html#.removeAllListeners">removeAllListeners</a></li><li data-type='method'><a href="access.html#.removeEventListener">removeEventListener</a></li><li data-type='method'><a href="access.html#.retrieveActionableRealms">retrieveActionableRealms</a></li><li data-type='method'><a href="access.html#.retrieveCurrentSession">retrieveCurrentSession</a></li><li data-type='method'><a href="access.html#.setDefaultApplication">setDefaultApplication</a></li></ul></li><li><a href="api.html">api</a><ul class='methods'><li data-type='method'><a href="api.html#.delete">delete</a></li><li data-type='method'><a href="api.html#.generateEndpointURL">generateEndpointURL</a></li><li data-type='method'><a href="api.html#.get">get</a></li><li data-type='method'><a href="api.html#.post">post</a></li><li data-type='method'><a href="api.html#.put">put</a></li></ul></li><li><a href="app.device.html">device</a></li><li><a href="asset.html">asset</a><ul class='methods'><li data-type='method'><a href="asset.html#.avatarUrl">avatarUrl</a></li><li data-type='method'><a href="asset.html#.downloadUrl">downloadUrl</a></li><li data-type='method'><a href="asset.html#.filesize">filesize</a></li><li data-type='method'><a href="asset.html#.getUrl">getUrl</a></li><li data-type='method'><a href="asset.html#.imageUrl">imageUrl</a></li><li data-type='method'><a href="asset.html#.playerUrl">playerUrl</a></li><li data-type='method'><a href="asset.html#.posterUrl">posterUrl</a></li><li data-type='method'><a href="asset.html#.typeFromMime">typeFromMime</a></li></ul></li><li><a href="auth.html">auth</a><ul class='methods'><li data-type='method'><a href="auth.html#.addEventListener">addEventListener</a></li><li data-type='method'><a href="auth.html#.changeAccount">changeAccount</a></li><li data-type='method'><a href="auth.html#.getCurrentToken">getCurrentToken</a></li><li data-type='method'><a href="auth.html#.getCurrentUser">getCurrentUser</a></li><li data-type='method'><a href="auth.html#.impersonate">impersonate</a></li><li data-type='method'><a href="auth.html#.login">login</a></li><li data-type='method'><a href="auth.html#.logout">logout</a></li><li data-type='method'><a href="auth.html#.refreshAccessToken">refreshAccessToken</a></li><li data-type='method'><a href="auth.html#.removeAllListeners">removeAllListeners</a></li><li data-type='method'><a href="auth.html#.removeEventListener">removeEventListener</a></li><li data-type='method'><a href="auth.html#.retrieveUserFromResetToken">retrieveUserFromResetToken</a></li><li data-type='method'><a href="auth.html#.sendResetPasswordRequest">sendResetPasswordRequest</a></li><li data-type='method'><a href="auth.html#.set">set</a></li><li data-type='method'><a href="auth.html#.signup">signup</a></li><li data-type='method'><a href="auth.html#.updateUserWithToken">updateUserWithToken</a></li></ul></li><li><a href="cache.html">cache</a><ul class='methods'><li data-type='method'><a href="cache.html#.get">get</a></li><li data-type='method'><a href="cache.html#.reset">reset</a></li></ul></li><li><a href="components.html">components</a><ul class='methods'><li data-type='method'><a href="components.html#.hydrateModel">hydrateModel</a></li></ul></li><li><a href="content.html">content</a><ul class='methods'><li data-type='method'><a href="content.html#.duplicate">duplicate</a></li><li data-type='method'><a href="content.html#.external">external</a></li><li data-type='method'><a href="content.html#.filter">filter</a></li><li data-type='method'><a href="content.html#.form">form</a></li><li data-type='method'><a href="content.html#.get">get</a></li><li data-type='method'><a href="content.html#.getMultiple">getMultiple</a></li><li data-type='method'><a href="content.html#.keys">keys</a></li><li data-type='method'><a href="content.html#.list">list</a></li><li data-type='method'><a href="content.html#.query">query</a></li><li data-type='method'><a href="content.html#.related">related</a></li><li data-type='method'><a href="content.html#.retrieve">retrieve</a></li><li data-type='method'><a href="content.html#.slug">slug</a></li><li data-type='method'><a href="content.html#.submitInteraction">submitInteraction</a></li><li data-type='method'><a href="content.html#.submitPost">submitPost</a></li><li data-type='method'><a href="content.html#.thread">thread</a></li><li data-type='method'><a href="content.html#.values">values</a></li></ul></li><li><a href="date.html">date</a><ul class='methods'><li data-type='method'><a href="date.html#.countdown">countdown</a></li><li data-type='method'><a href="date.html#.dateFromID">dateFromID</a></li><li data-type='method'><a href="date.html#.formatDate">formatDate</a></li><li data-type='method'><a href="date.html#.getAge">getAge</a></li><li data-type='method'><a href="date.html#.groupEventByDate">groupEventByDate</a></li><li data-type='method'><a href="date.html#.isDifferentTimezoneThanUser">isDifferentTimezoneThanUser</a></li><li data-type='method'><a href="date.html#.isMultiDayEvent">isMultiDayEvent</a></li><li data-type='method'><a href="date.html#.localDate">localDate</a></li><li data-type='method'><a href="date.html#.militaryTimestamp">militaryTimestamp</a></li><li data-type='method'><a href="date.html#.readableEventDate">readableEventDate</a></li><li data-type='method'><a href="date.html#.readableEventTime">readableEventTime</a></li><li data-type='method'><a href="date.html#.timeago">timeago</a></li><li data-type='method'><a href="date.html#.timeline">timeline</a></li><li data-type='method'><a href="date.html#.timestampToAmPm">timestampToAmPm</a></li><li data-type='method'><a href="date.html#.timezones">timezones</a></li></ul></li><li><a href="fluro.html">fluro</a></li><li><a href="types.html">types</a><ul class='methods'><li data-type='method'><a href="types.html#.all">all</a></li><li data-type='method'><a href="types.html#.basicTypes">basicTypes</a></li><li data-type='method'><a href="types.html#.get">get</a></li><li data-type='method'><a href="types.html#.mapDefinitionItems">mapDefinitionItems</a></li><li data-type='method'><a href="types.html#.parentType">parentType</a></li><li data-type='method'><a href="types.html#.postableTypes">postableTypes</a></li><li data-type='method'><a href="types.html#.readable">readable</a></li><li data-type='method'><a href="types.html#.reloadTerminology">reloadTerminology</a></li><li data-type='method'><a href="types.html#.retrieve">retrieve</a></li><li data-type='method'><a href="types.html#.subTypes">subTypes</a></li><li data-type='method'><a href="types.html#.term">term</a></li></ul></li><li><a href="utils.html">utils</a><ul class='methods'><li data-type='method'><a href="utils.html#.arrayIDs">arrayIDs</a></li><li data-type='method'><a href="utils.html#.comma">comma</a></li><li data-type='method'><a href="utils.html#.currencySymbol">currencySymbol</a></li><li data-type='method'><a href="utils.html#.errorMessage">errorMessage</a></li><li data-type='method'><a href="utils.html#.extractFromArray">extractFromArray</a></li><li data-type='method'><a href="utils.html#.formatCurrency">formatCurrency</a></li><li data-type='method'><a href="utils.html#.getDefaultValueForField">getDefaultValueForField</a></li><li data-type='method'><a href="utils.html#.getFlattenedFields">getFlattenedFields</a></li><li data-type='method'><a href="utils.html#.getStringID">getStringID</a></li><li data-type='method'><a href="utils.html#.guid">guid</a></li><li data-type='method'><a href="utils.html#.hash">hash</a></li><li data-type='method'><a href="utils.html#.injectScript">injectScript</a></li><li data-type='method'><a href="utils.html#.machineName">machineName</a></li><li data-type='method'><a href="utils.html#.mapParameters">mapParameters</a></li><li data-type='method'><a href="utils.html#.matchInArray">matchInArray</a></li><li data-type='method'><a href="utils.html#.processCardPrioritySort">processCardPrioritySort</a></li></ul></li><li><a href="video.html">video</a><ul class='methods'><li data-type='method'><a href="video.html#.hhmmss">hhmmss</a></li><li data-type='method'><a href="video.html#.readableMilliseconds">readableMilliseconds</a></li><li data-type='method'><a href="video.html#.readableSeconds">readableSeconds</a></li></ul></li></ul> </nav> <div id="main"> <h1 class="page-title">fluro.asset.js</h1> <section> <article> <pre class="prettyprint source linenums"><code>/** * Creates a new FluroAsset instance. * This module provides a number of helper functions for managing asset, image, video and audio items in Fluro * @alias asset * @constructor * @hideconstructor * @param {FluroCore} fluro A reference to the parent instance of the FluroCore module. The FluroAsset module is usually created by a FluroCore instance that passes itself in as the first argument. */ var FluroAsset = function(Fluro) { var isRetina; var defaultWindowSettings = { screen: { width: 1920, height: 1080, }, } /////////////////////////////////////////////////// // if (process.browser) { if (this.window) { defaultWindowSettings = this.window; isRetina = this.window.devicePixelRatio > 1; } // } /////////////////////////////////////////////////// var service = {}; /////////////////////////////////////////////////// function parameterDefaults(url, params) { //////////////////////////////////// //If an extension was provided add it to the url if (params.extension &amp;&amp; params.extension.length) { if (params.title &amp;&amp; params.title.length) { url += `/file/${params.title}.${params.extension}`; delete params.title; } else { if (params.filename &amp;&amp; params.filename.length) { url += `/file/${params.filename}.${params.extension}`; delete params.filename; } else { url += `/file/file.${params.extension}`; } } //Dont need to include it anymore delete params.extension; } else { if (params.filename &amp;&amp; params.filename.length) { url += `/file/${params.filename}`; delete params.filename; } } //////////////////////////////////// //If we haven't requested without token if (!params.withoutToken) { //Get the current token from FluroAuth var CurrentFluroToken = Fluro.auth.getCurrentToken(); //Check to see if we have a token and none has been explicity set if (!params['access_token'] &amp;&amp; CurrentFluroToken) { //Use the current token by default params['access_token'] = CurrentFluroToken; } } //////////////////////////////////// if (Fluro.app &amp;&amp; Fluro.app.uuid) { params['did'] = Fluro.app.uuid; } return url; } /////////////////////////////////////////////////// /** * * This function generates a url for the binary data of an * asset, image, audio, or video file that has been uploaded to Fluro * @alias asset.getUrl * @param {string} assetID The _id of the item you want to retrieve * @param {object} params * @return {string} A valid Fluro URL * @example * // returns 'https://api.fluro.io/get/5be504eabf33991239599d63' * fluro.asset.getUrl('5be504eabf33991239599d63') * * // returns 'https://api.fluro.io/get/5be504eabf33991239599d63/file/MyFile.pdf' * fluro.asset.getUrl('5be504eabf33991239599d63', {filename:'MyFile.pdf'}) */ service.getUrl = function(assetID, params) { //Get the asset id as a pure string assetID = Fluro.utils.getStringID(assetID); if (!assetID || !String(assetID).length) { return; } if (!params) { params = {}; } var url = `${Fluro.apiURL}/get/${assetID}`; //////////////////////////////////////// url = parameterDefaults(url, params); //////////////////////////////////////// //Map the parameters to a query string var queryParameters = Fluro.utils.mapParameters(params); if (queryParameters.length) { url += '?' + queryParameters; } return url; } /////////////////////////////////////////////////// /** * * This function generates a player url for a video file that has been uploaded to Fluro * This is useful to force browsers to renderer a html5 video player instead of downloading the video file on desktop * @alias asset.playerUrl * @param {string} videoID The _id of the video you want to play * @param {object} params * @return {string} A valid Fluro URL * @example * // returns 'https://api.fluro.io/get/player?url=https://api.fluro.io/get/5be504eabf33991239599d63' * fluro.asset.playerUrl('5be504eabf33991239599d63') */ service.playerUrl = function(videoID, params) { //Get the asset id as a pure string videoID = Fluro.utils.getStringID(videoID); if (!videoID || !String(videoID).length) { return; } if (!params) { params = {}; } var url = `${Fluro.apiURL}/get/player?url=${Fluro.apiURL}/get/${videoID}`; //////////////////////////////////////// url = parameterDefaults(url, params); //////////////////////////////////////// //Map the parameters to a query string var queryParameters = Fluro.utils.mapParameters(params); if (queryParameters.length) { url += '?' + queryParameters; } return url; } /////////////////////////////////////////////////// /** * A helper function to generate a url for retrieving a user, persona or contact's avatar * @alias asset.avatarUrl * @param {string} personID The id of the person you want to retrieve the avatar for * @param {string} style Can be 'contact', 'persona' or 'user' * @param {object} params * @param {number} params.w The width of the image you are requesting from Fluro * @param {number} params.h The height of the image you are requesting from Fluro * @return {string} A full URL that links to the image the user is requesting * @example * // returns 'https://api.fluro.io/get/avatar/contact/5be504eabf33991239599d63?w=100&amp;h=100' * fluro.asset.avatarUrl('5be504eabf33991239599d63', 'contact', {w:100, h:100}) * */ service.avatarUrl = function(personID, style, params) { //Get the id as a pure string personID = Fluro.utils.getStringID(personID); if (!personID || !String(personID).length) { return; } if (!params) { params = {}; } if (!style) { style = 'contact'; } var url = `${Fluro.apiURL}/get/avatar/${style}/${personID}`; //////////////////////////////////////// url = parameterDefaults(url, params); //////////////////////////////////////// //Map the parameters to a query string var queryParameters = Fluro.utils.mapParameters(params); if (queryParameters.length) { url += '?' + queryParameters; } return url; } /////////////////////////////////////////////////// /** * A helper function to retrieve the main image for an event, group, realm or other content * @alias asset.coverUrl * @param {string} contentID The id of the item you want to retrieve the image for * @param {string} style Can be 'event', 'group', 'tag' or 'realm' * @param {object} params * @param {number} params.w The width of the image to request from Fluro * @param {number} params.h The height of the image to request from Fluro * @return {string} A full URL that links to the image the user is requesting * @example * // returns 'https://api.fluro.io/get/event/5be504eabf33991239599d63?w=100&amp;h=100' * fluro.asset.coverUrl('5be504eabf33991239599d63', 'event', {w:100, h:100}) * */ //Get the cover image for an event, group or realm service.coverUrl = service.coverImage = function(contentID, style, params) { //Get the id as a pure string contentID = Fluro.utils.getStringID(contentID); if (!contentID || !String(contentID).length) { return; } if (!params) { params = {}; } if (!style) { style = 'event'; } var url = `${Fluro.apiURL}/get/${style}/${contentID}`; //////////////////////////////////////// url = parameterDefaults(url, params); //////////////////////////////////////// //Map the parameters to a query string var queryParameters = Fluro.utils.mapParameters(params); if (queryParameters.length) { url += '?' + queryParameters; } return url; } /////////////////////////////////////////////////// /** * A helper function that returns a download url for a specific asset * @param {string} assetID The id of the asset, or the asset object you want to download * @alias asset.downloadUrl * @param {object} params * @param {string} params.filename The filename you want to download the file as * @param {string} params.extension The extension of the file you want to download, eg. 'pdf' * @return {string} A full URL that will download the file * @example * // returns 'https://api.fluro.io/download/5be504eabf33991239599d63' * fluro.asset.downloadUrl('5be504eabf33991239599d63') * * // returns 'https://api.fluro.io/download/5be504eabf33991239599d63/file/MyFile.docx' * fluro.asset.downloadUrl('5be504eabf33991239599d63', {filename:'MyFile.docx'}) * */ service.downloadUrl = function(assetID, params) { //Get the id as a pure string assetID = Fluro.utils.getStringID(assetID); if (!assetID || !String(assetID).length) { return; } if (!params) { params = {}; } var url = `${Fluro.apiURL}/download/${assetID}`; //////////////////////////////////////// url = parameterDefaults(url, params); //////////////////////////////////////// //Map the parameters to a query string var queryParameters = Fluro.utils.mapParameters(params); if (queryParameters.length) { url += '?' + queryParameters; } return url; } /////////////////////////////////////////////////// /** * A helper function that returns what type of content Fluro will attribute a specified mimetype to * @alias asset.typeFromMime * @param {string} mimetype The mimetype of a file * @return {string} Whether this mimetype is an 'asset', 'video', 'image', or 'audio' file * @example * // returns 'audio' * fluro.asset.typeFromMime('audio/aac') * // returns 'video' * fluro.asset.typeFromMime('video/ogg') * // returns 'asset' * fluro.asset.typeFromMime('application/pdf') * */ service.typeFromMime = function(mimetype) { switch (mimetype) { case 'image/jpeg': case 'image/png': case 'image/gif': case 'image/bmp': case 'image/svg+xml': return 'image' break; case 'video/mp4': case 'video/quicktime': case 'video/ogg': case 'video/webm': return 'video' break; case 'audio/aac': case 'audio/aiff': case 'audio/mp3': case 'audio/x-m4a': case 'audio/mpeg': case 'audio/ogg': case 'audio/wav': case 'audio/webm': return 'audio' break; default: // if(_.startsWith(mimetype, 'image/')) { // return 'image'; // } if (_.startsWith(mimetype, 'video/')) { return 'video'; } if (_.startsWith(mimetype, 'audio/')) { return 'audio'; } break; } return 'asset'; } /////////////////////////////////////////////////// /** * A helper function that returns a poster image for a specified video * @alias asset.posterUrl * @param {string} videoID The id of the video, or a video object that has an _id property * @param {number} width The width of the poster image. If none specified will default to 16:9 based on the requesting user's screen size * @param {number} height The height of the poster image. If none specified will default to 16:9 based on the requesting user's screen size * @param {object} params * @return {string} A full URL of the poster image * @example * // returns 'https://api.fluro.io/get/poster/5be504eabf33991239599d63?w=1920&amp;h=1080' * fluro.asset.posterUrl('5be504eabf33991239599d63', 1920, 1080) * * // returns 'https://api.fluro.io/get/poster/5be504eabf33991239599d63/file/file.jpg?w=1920&amp;h=1080' * fluro.asset.posterUrl('5be504eabf33991239599d63', 1920, 1080, {extension:'jpg'}) * * //Not providing a height property will default to 16:9 ratio inferred from the width * //returns 'https://api.fluro.io/get/poster/5be504eabf33991239599d63/file/MyPoster.jpg?w=1920&amp;h=1080' * fluro.asset.posterUrl('5be504eabf33991239599d63', 1920, null, {filename:'MyPoster.jpg'}) * * */ //Helper function for retrieving the poster image for a video service.posterUrl = function(videoID, w, h, params) { //Get the id as a pure string videoID = Fluro.utils.getStringID(videoID); if (!videoID || !String(videoID).length) { return; } if (!params) { params = {}; } ////////////////////////////////////// var reducer = 0.5; ////////////////////////////////////// var screenWidth = defaultWindowSettings.screen.width || 1920; var screenHeight = defaultWindowSettings.screen.width || 1080; ////////////////////////////////////// //Setup our usual width limit var limitWidth; //By default, limit the width if (isRetina) { limitWidth = 1920 * reducer; } else { limitWidth = 1200 * reducer; } ////////////////////////////////////// //If the screen is smaller then 768 use an optimised image if (screenWidth &lt;= 768) { if (isRetina) { limitWidth = 1536 * reducer; } else { limitWidth = 768 * reducer; } } //If using mobile then use a smaller optimised image if (screenWidth &lt;= 320) { if (isRetina) { limitWidth = 640 * reducer; } else { limitWidth = 320 * reducer; } } ////////////////////////////////////////////////// //If no width or height was specified if (!w &amp;&amp; !h) { //Use our default width based on screen size params['w'] = limitWidth; params['h'] = Math.round(limitWidth * (9 / 16)); } else { //If a width was specified if (w) { params['w'] = w; if (!h) { //If no height specified calculate based on aspect ratio params['h'] = Math.round(w * (9 / 16)); } } //If a height was specified if (h) { params['h'] = h; } } ////////////////////////////////////////////////// if (!params.hasOwnProperty('quality')) { params.quality = 80; } ////////////////////////////////////////////////// //Create the basic url var url = `${Fluro.apiURL}/get/${videoID}/poster`; //////////////////////////////////////// url = parameterDefaults(url, params); //////////////////////////////////////// //Map the parameters to a query string var queryParameters = Fluro.utils.mapParameters(params); if (queryParameters.length) { url += '?' + queryParameters; } //////////////////////////////////////// return url; } /////////////////////////////////////////////////// /** * A helper function that creates a url image for a specified image * @alias asset.imageUrl * @param {string} imageID The id of the image or an object representing the image that has an _id property * @param {Integer} width The width of the image to retrieve from Fluro. If none is specified then will default to a size based on the requesting user's screen dimensions. * @param {Integer} height The height of the image to retrieve from Fluro. If none is specified then will default to a size based on the requesting user's screen dimensions. * @param {object} params * @param {Integer} params.quality The quality of the image to retrieve from Fluro as a percent eg. 85 * @param {String} params.filename The filename to use for the image url * @param {String} params.extension An extension to use for the url if no filename is specified * @return {string} A full URL of the image * @example * // returns 'https://api.fluro.io/get/5be504eabf33991239599d63?w=800' * fluro.asset.imageUrl('5be504eabf33991239599d63', 800) * * // returns 'https://api.fluro.io/get/5be504eabf33991239599d63/file/image.jpg?w=800' * fluro.asset.imageUrl('5be504eabf33991239599d63', 800, null, {filename:'MyFile.pdf'}) */ //Helper function for retrieving the poster image for a video service.imageUrl = function(imageID, w, h, params) { //Get the id as a pure string imageID = Fluro.utils.getStringID(imageID); if (!imageID || !String(imageID).length) { return; } ////////////////////////////////////// if (!params) { params = {}; } //Create the basic url var url = Fluro.apiURL + '/get/' + imageID; ////////////////////////////////////// //Setup our usual width limit var limitWidth; //By default, limit the width if (isRetina) { limitWidth = 1920; } else { limitWidth = 1200; } ////////////////////////////////////// //If the screen is smaller then 768 use an optimised image if (defaultWindowSettings.screen.width &lt;= 768) { if (isRetina) { limitWidth = 1536; } else { limitWidth = 768; } } //If using mobile then use a smaller optimised image if (defaultWindowSettings.screen.width &lt;= 320) { if (isRetina) { limitWidth = 640; } else { limitWidth = 320; } } //////////////////////////////////// //If no width or height was specified if (!w &amp;&amp; !h) { //Use our default limits params['w'] = limitWidth; } else { //If a width was specified if (w) { params['w'] = w; } //If a height was specified if (h) { params['h'] = h; } } //////////////////////////////////////// //Default to 90% quality huge compression gains if (!params.quality) { params.quality = 90; } //////////////////////////////////////// url = parameterDefaults(url, params); //////////////////////////////////////// //Map the parameters to a query string var queryParameters = Fluro.utils.mapParameters(params); if (queryParameters.length) { url += '?' + queryParameters; } //////////////////////////////////////// return url; } /////////////////////////////////////// /** * Helper function to translate bytes into a human readable format * @alias asset.filesize * @param {Integer} bytes The number of bytes * @return {String} The human readable filesize * @example * // returns '1mb' * fluro.asset.filesize(1000000) */ service.filesize = function(bytes) { var sizes = ['Bytes', 'kb', 'mb', 'gb', 'tb']; if (bytes == 0) return '0 Byte'; var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024))); return Math.round(bytes / Math.pow(1024, i), 2) + '' + sizes[i]; } /////////////////////////////////////////////////// return service; } export default FluroAsset;</code></pre> </article> </section> </div> <br class="clear"> <footer> Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a> on Tue Jun 29 2021 08:38:17 GMT+1000 (Australian Eastern Standard Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme. </footer> <script>prettyPrint();</script> <script src="scripts/polyfill.js"></script> <script src="scripts/linenumber.js"></script> </body> </html>