@qikdev/sdk 1.0.2 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/{docs/access.html → access.html} +353 -20
- package/dist/api.html +444 -0
- package/dist/{docs/auth.html → auth.html} +14 -14
- package/dist/cache.html +351 -0
- package/dist/{docs/content.html → content.html} +46 -21
- package/dist/{docs/files.html → files.html} +147 -6
- package/dist/{docs/filter.html → filter.html} +9 -9
- package/dist/geo.html +1029 -0
- package/dist/global.html +240 -0
- package/dist/index.html +96 -0
- package/dist/main.js +2 -3
- package/dist/module-QikStorage-CookieStorageAdapter.html +407 -0
- package/dist/module-QikStorage-LocalStorageAdapter.html +193 -0
- package/dist/module-QikStorage-StorageAdapter.html +977 -0
- package/dist/module-QikStorage.html +433 -0
- package/dist/qik.access.js.html +904 -0
- package/dist/qik.api.js.html +409 -0
- package/dist/{docs/qik.auth.js.html → qik.auth.js.html} +142 -104
- package/dist/qik.cache.js.html +125 -0
- package/dist/qik.content.js.html +967 -0
- package/dist/qik.core.js.html +322 -0
- package/dist/qik.files.js.html +249 -0
- package/dist/{docs/qik.filter.js.html → qik.filter.js.html} +3 -3
- package/dist/qik.geo.js.html +963 -0
- package/dist/{docs/qik.socket.js.html → qik.socket.js.html} +53 -12
- package/dist/qik.storage.js.html +375 -0
- package/dist/qik.system.js.html +117 -0
- package/dist/qik.utils.js.html +1548 -0
- package/dist/{docs/socket.html → socket.html} +7 -7
- package/dist/{docs/styles → styles}/jsdoc.css +2 -2
- package/dist/system.html +197 -0
- package/dist/utils.html +4422 -0
- package/package.json +2 -2
- package/src/api/qik.filter.js +1 -1
- package/src/api/qik.geo.js +1 -1
- package/src/api/qik.socket.js +18 -12
- package/src/api/qik.utils.js +6 -0
- package/src/version.js +1 -1
- package/dist/docs/api.html +0 -1356
- package/dist/docs/cache.html +0 -351
- package/dist/docs/index.html +0 -96
- package/dist/docs/qik.access.js.html +0 -790
- package/dist/docs/qik.api.js.html +0 -511
- package/dist/docs/qik.cache.js.html +0 -131
- package/dist/docs/qik.content.js.html +0 -918
- package/dist/docs/qik.core.js.html +0 -301
- package/dist/docs/qik.files.js.html +0 -219
- package/dist/docs/qik.system.js.html +0 -117
- package/dist/docs/qik.utils.js.html +0 -1467
- package/dist/docs/system.html +0 -197
- /package/dist/{docs/fonts → fonts}/Montserrat/Montserrat-Bold.eot +0 -0
- /package/dist/{docs/fonts → fonts}/Montserrat/Montserrat-Bold.ttf +0 -0
- /package/dist/{docs/fonts → fonts}/Montserrat/Montserrat-Bold.woff +0 -0
- /package/dist/{docs/fonts → fonts}/Montserrat/Montserrat-Bold.woff2 +0 -0
- /package/dist/{docs/fonts → fonts}/Montserrat/Montserrat-Regular.eot +0 -0
- /package/dist/{docs/fonts → fonts}/Montserrat/Montserrat-Regular.ttf +0 -0
- /package/dist/{docs/fonts → fonts}/Montserrat/Montserrat-Regular.woff +0 -0
- /package/dist/{docs/fonts → fonts}/Montserrat/Montserrat-Regular.woff2 +0 -0
- /package/dist/{docs/fonts → fonts}/Source-Sans-Pro/sourcesanspro-light-webfont.eot +0 -0
- /package/dist/{docs/fonts → fonts}/Source-Sans-Pro/sourcesanspro-light-webfont.svg +0 -0
- /package/dist/{docs/fonts → fonts}/Source-Sans-Pro/sourcesanspro-light-webfont.ttf +0 -0
- /package/dist/{docs/fonts → fonts}/Source-Sans-Pro/sourcesanspro-light-webfont.woff +0 -0
- /package/dist/{docs/fonts → fonts}/Source-Sans-Pro/sourcesanspro-light-webfont.woff2 +0 -0
- /package/dist/{docs/fonts → fonts}/Source-Sans-Pro/sourcesanspro-regular-webfont.eot +0 -0
- /package/dist/{docs/fonts → fonts}/Source-Sans-Pro/sourcesanspro-regular-webfont.svg +0 -0
- /package/dist/{docs/fonts → fonts}/Source-Sans-Pro/sourcesanspro-regular-webfont.ttf +0 -0
- /package/dist/{docs/fonts → fonts}/Source-Sans-Pro/sourcesanspro-regular-webfont.woff +0 -0
- /package/dist/{docs/fonts → fonts}/Source-Sans-Pro/sourcesanspro-regular-webfont.woff2 +0 -0
- /package/dist/{docs/scripts → scripts}/collapse.js +0 -0
- /package/dist/{docs/scripts → scripts}/linenumber.js +0 -0
- /package/dist/{docs/scripts → scripts}/nav.js +0 -0
- /package/dist/{docs/scripts → scripts}/polyfill.js +0 -0
- /package/dist/{docs/scripts → scripts}/prettify/Apache-License-2.0.txt +0 -0
- /package/dist/{docs/scripts → scripts}/prettify/lang-css.js +0 -0
- /package/dist/{docs/scripts → scripts}/prettify/prettify.js +0 -0
- /package/dist/{docs/scripts → scripts}/search.js +0 -0
- /package/dist/{docs/styles → styles}/prettify.css +0 -0
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
|
|
5
|
+
<meta charset="utf-8">
|
|
6
|
+
<title>qik.core.js - Documentation</title>
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
<script src="scripts/prettify/prettify.js"></script>
|
|
10
|
+
<script src="scripts/prettify/lang-css.js"></script>
|
|
11
|
+
<!--[if lt IE 9]>
|
|
12
|
+
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
|
13
|
+
<![endif]-->
|
|
14
|
+
<link type="text/css" rel="stylesheet" href="styles/prettify.css">
|
|
15
|
+
<link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
|
|
16
|
+
<script src="scripts/nav.js" defer></script>
|
|
17
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
18
|
+
</head>
|
|
19
|
+
<body>
|
|
20
|
+
|
|
21
|
+
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
|
|
22
|
+
<label for="nav-trigger" class="navicon-button x">
|
|
23
|
+
<div class="navicon"></div>
|
|
24
|
+
</label>
|
|
25
|
+
|
|
26
|
+
<label for="nav-trigger" class="overlay"></label>
|
|
27
|
+
|
|
28
|
+
<nav >
|
|
29
|
+
|
|
30
|
+
<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#.actionableScopes">actionableScopes</a></li><li data-type='method'><a href="access.html#.allPermissions">allPermissions</a></li><li data-type='method'><a href="access.html#.allPermissionTypes">allPermissionTypes</a></li><li data-type='method'><a href="access.html#.allUserScopes">allUserScopes</a></li><li data-type='method'><a href="access.html#.canCreate">canCreate</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#.canEraseItem">canEraseItem</a></li><li data-type='method'><a href="access.html#.canKnowOf">canKnowOf</a></li><li data-type='method'><a href="access.html#.canListItem">canListItem</a></li><li data-type='method'><a href="access.html#.canRestoreItem">canRestoreItem</a></li><li data-type='method'><a href="access.html#.canViewItem">canViewItem</a></li><li data-type='method'><a href="access.html#.checkActionAccess">checkActionAccess</a></li><li data-type='method'><a href="access.html#.getAllDescendants">getAllDescendants</a></li><li data-type='method'><a href="access.html#.has">has</a></li><li data-type='method'><a href="access.html#.hasFeature">hasFeature</a></li><li data-type='method'><a href="access.html#.hashPermissions">hashPermissions</a></li><li data-type='method'><a href="access.html#.isAdministrator">isAdministrator</a></li><li data-type='method'><a href="access.html#.isAssignee">isAssignee</a></li><li data-type='method'><a href="access.html#.isOwner">isOwner</a></li></ul></li><li><a href="api.html">api</a><ul class='methods'><li data-type='method'><a href="api.html#.generateEndpointURL">generateEndpointURL</a></li></ul></li><li><a href="auth.html">auth</a><ul class='methods'><li data-type='method'><a href="auth.html#.changeOrganisation">changeOrganisation</a></li><li data-type='method'><a href="auth.html#.ensureValidToken">ensureValidToken</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#.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#.sync">sync</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="content.html">content</a><ul class='methods'><li data-type='method'><a href="content.html#.create">create</a></li><li data-type='method'><a href="content.html#.delete">delete</a></li><li data-type='method'><a href="content.html#.get">get</a></li><li data-type='method'><a href="content.html#.getFromSlug">getFromSlug</a></li><li data-type='method'><a href="content.html#.glossary">glossary</a></li><li data-type='method'><a href="content.html#.list">list</a></li><li data-type='method'><a href="content.html#.patch">patch</a></li><li data-type='method'><a href="content.html#.restore">restore</a></li><li data-type='method'><a href="content.html#.scopeGlossary">scopeGlossary</a></li><li data-type='method'><a href="content.html#.update">update</a></li><li data-type='method'><a href="content.html#.validateField">validateField</a></li><li data-type='method'><a href="content.html#.variables">variables</a></li></ul></li><li><a href="files.html">files</a><ul class='methods'><li data-type='method'><a href="files.html#.downloadUrl">downloadUrl</a></li><li data-type='method'><a href="files.html#.duration">duration</a></li><li data-type='method'><a href="files.html#.filesize">filesize</a></li><li data-type='method'><a href="files.html#.getBinaryTypeFromMime">getBinaryTypeFromMime</a></li><li data-type='method'><a href="files.html#.mediaUrl">mediaUrl</a></li></ul></li><li><a href="filter.html">filter</a><ul class='methods'><li data-type='method'><a href="filter.html#.activeFilterComparators">activeFilterComparators</a></li><li data-type='method'><a href="filter.html#.activeFilterKeys">activeFilterKeys</a></li><li data-type='method'><a href="filter.html#.activeFilterOperators">activeFilterOperators</a></li><li data-type='method'><a href="filter.html#.activeFilters">activeFilters</a></li><li data-type='method'><a href="filter.html#.activeFilterValues">activeFilterValues</a></li><li data-type='method'><a href="filter.html#.filterChangeString">filterChangeString</a></li><li data-type='method'><a href="filter.html#.isValidFilter">isValidFilter</a></li></ul></li><li><a href="geo.html">geo</a><ul class='methods'><li data-type='method'><a href="geo.html#.distance">distance</a></li><li data-type='method'><a href="geo.html#.getDefaultCountry">getDefaultCountry</a></li><li data-type='method'><a href="geo.html#.getDefaultTimezone">getDefaultTimezone</a></li><li data-type='method'><a href="geo.html#.getPosition">getPosition</a></li><li data-type='method'><a href="geo.html#.stopWatchPosition">stopWatchPosition</a></li><li data-type='method'><a href="geo.html#.watchPosition">watchPosition</a></li></ul></li><li><a href="module-QikStorage-CookieStorageAdapter.html">CookieStorageAdapter</a><ul class='methods'><li data-type='method'><a href="module-QikStorage-CookieStorageAdapter.html#getCookieOptions">getCookieOptions</a></li><li data-type='method'><a href="module-QikStorage-CookieStorageAdapter.html#isCookieMode">isCookieMode</a></li></ul></li><li><a href="module-QikStorage-LocalStorageAdapter.html">LocalStorageAdapter</a></li><li><a href="module-QikStorage-StorageAdapter.html">StorageAdapter</a><ul class='methods'><li data-type='method'><a href="module-QikStorage-StorageAdapter.html#clearUser">clearUser</a></li><li data-type='method'><a href="module-QikStorage-StorageAdapter.html#getAccessToken">getAccessToken</a></li><li data-type='method'><a href="module-QikStorage-StorageAdapter.html#getRefreshToken">getRefreshToken</a></li><li data-type='method'><a href="module-QikStorage-StorageAdapter.html#getTokenExpiry">getTokenExpiry</a></li><li data-type='method'><a href="module-QikStorage-StorageAdapter.html#getUser">getUser</a></li><li data-type='method'><a href="module-QikStorage-StorageAdapter.html#isAvailable">isAvailable</a></li><li data-type='method'><a href="module-QikStorage-StorageAdapter.html#setUser">setUser</a></li></ul></li><li><a href="socket.html">socket</a><ul class='methods'><li data-type='method'><a href="socket.html#.channel">channel</a></li><li data-type='method'><a href="socket.html#.close">close</a></li><li data-type='method'><a href="socket.html#.connect">connect</a></li><li data-type='method'><a href="socket.html#.reconnect">reconnect</a></li><li data-type='method'><a href="socket.html#.subscribe">subscribe</a></li><li data-type='method'><a href="socket.html#.unsubscribe">unsubscribe</a></li></ul></li><li><a href="system.html">system</a><ul class='methods'><li data-type='method'><a href="system.html#.countries">countries</a></li></ul></li><li><a href="utils.html">utils</a><ul class='methods'><li data-type='method'><a href="utils.html#.cleanValue">cleanValue</a></li><li data-type='method'><a href="utils.html#.comma">comma</a></li><li data-type='method'><a href="utils.html#.errorMessage">errorMessage</a></li><li data-type='method'><a href="utils.html#.exists">exists</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#.getTypeFromID">getTypeFromID</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#.id">id</a></li><li data-type='method'><a href="utils.html#.ids">ids</a></li><li data-type='method'><a href="utils.html#.isValidEmailAddress">isValidEmailAddress</a></li><li data-type='method'><a href="utils.html#.loadExternalScript">loadExternalScript</a></li><li data-type='method'><a href="utils.html#.loadExternalStyle">loadExternalStyle</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#.parseBoolean">parseBoolean</a></li><li data-type='method'><a href="utils.html#.parseDate">parseDate</a></li><li data-type='method'><a href="utils.html#.parseEmail">parseEmail</a></li><li data-type='method'><a href="utils.html#.parseInt">parseInt</a></li><li data-type='method'><a href="utils.html#.parseNumber">parseNumber</a></li><li data-type='method'><a href="utils.html#.parseURL">parseURL</a></li></ul></li></ul><h3>Modules</h3><ul><li><a href="module-QikStorage.html">QikStorage</a><ul class='methods'><li data-type='method'><a href="module-QikStorage.html#.createStorageAdapter">createStorageAdapter</a></li></ul></li></ul><h3>Global</h3><ul><li><a href="global.html#EventDispatcher">EventDispatcher</a></li></ul>
|
|
31
|
+
</nav>
|
|
32
|
+
|
|
33
|
+
<div id="main">
|
|
34
|
+
|
|
35
|
+
<h1 class="page-title">qik.core.js</h1>
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
<section>
|
|
44
|
+
<article>
|
|
45
|
+
<pre class="prettyprint source linenums"><code>import QikAPI from './qik.api.js';
|
|
46
|
+
import QikAuth from './qik.auth.js';
|
|
47
|
+
import QikUtils from './qik.utils.js';
|
|
48
|
+
import QikFilter from './qik.filter.js';
|
|
49
|
+
import QikFiles from './qik.files.js';
|
|
50
|
+
import QikCache from './qik.cache.js';
|
|
51
|
+
import QikAccess from './qik.access.js';
|
|
52
|
+
import QikContent from './qik.content.js';
|
|
53
|
+
import QikSystem from './qik.system.js';
|
|
54
|
+
import QikGeo from './qik.geo.js';
|
|
55
|
+
import QikSocket from './qik.socket.js';
|
|
56
|
+
import { EventDispatcher } from './qik.utils.js';
|
|
57
|
+
|
|
58
|
+
///////////////////////////////////////
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Creates a new QikCore instance including all of the default sub modules
|
|
62
|
+
* @alias qik
|
|
63
|
+
* @constructor
|
|
64
|
+
* @param {Object} options
|
|
65
|
+
* @param {String} options.apiURL The remote URL of the Qik API you want to connect to. Options are 'staging', 'production' or you may set a specific URL eg. 'https://api.qik.io' (do not include trailing slash). If no value is provided, will default to 'production'.
|
|
66
|
+
* @param {String} options.applicationToken When running as a static application, (for example a website) you may set the application's access token before you initialize the Qik instance here.
|
|
67
|
+
* @param {Boolean} options.useHttpOnlyCookies When set to true, authentication tokens will be stored in secure httpOnly cookies instead of localStorage. This provides enhanced security against XSS attacks. Requires backend support for cookie-based authentication.
|
|
68
|
+
* @param {Object} options.cookieConfig Configuration options for cookie storage when useHttpOnlyCookies is true.
|
|
69
|
+
* @param {String} options.cookieConfig.domain Cookie domain (auto-detected if not specified).
|
|
70
|
+
* @param {Boolean} options.cookieConfig.secure Whether cookies should only be sent over HTTPS (default: true).
|
|
71
|
+
* @param {String} options.cookieConfig.sameSite SameSite cookie attribute ('strict', 'lax', or 'none', default: 'lax').
|
|
72
|
+
* @example
|
|
73
|
+
*
|
|
74
|
+
* //Import the Qik package
|
|
75
|
+
* import Qik from '@qikdev/sdk';
|
|
76
|
+
*
|
|
77
|
+
* //Create a new Qik instance with localStorage (default)
|
|
78
|
+
* var qik = new Qik();
|
|
79
|
+
*
|
|
80
|
+
* //Create a new Qik instance with httpOnly cookies
|
|
81
|
+
* var qik = new Qik({
|
|
82
|
+
* apiURL: 'production',
|
|
83
|
+
* useHttpOnlyCookies: true
|
|
84
|
+
* });
|
|
85
|
+
*
|
|
86
|
+
* //Request the current user session endpoint from the Qik API
|
|
87
|
+
* qik.api.get('/session').then(function(res) {
|
|
88
|
+
* console.log('User session is ', res.data);
|
|
89
|
+
* })
|
|
90
|
+
* .catch(function(err) {
|
|
91
|
+
* console.log('There was an error', err);
|
|
92
|
+
* });
|
|
93
|
+
*
|
|
94
|
+
* //Use the QikAsset package to generate an image url
|
|
95
|
+
* var link = qik.asset.imageUrl('5ca3d64dd2bb085eb9d450db', 1920, 1080)
|
|
96
|
+
*/
|
|
97
|
+
|
|
98
|
+
import { version } from '../version.js';
|
|
99
|
+
|
|
100
|
+
export default function(options) {
|
|
101
|
+
if (!options) {
|
|
102
|
+
options = {
|
|
103
|
+
// apiURL,
|
|
104
|
+
// applicationToken,
|
|
105
|
+
// api:{}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
///////////////////////////////////////
|
|
110
|
+
|
|
111
|
+
if (!options.apiURL || !options.apiURL.length) {
|
|
112
|
+
options.apiURL = 'staging';
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
///////////////////////////////////////
|
|
116
|
+
|
|
117
|
+
switch (String(options.apiURL).toLowerCase()) {
|
|
118
|
+
case 'production':
|
|
119
|
+
options.apiURL = 'https://api.qik.dev';
|
|
120
|
+
break;
|
|
121
|
+
case 'staging':
|
|
122
|
+
options.apiURL = 'https://api.staging.qik.dev';
|
|
123
|
+
break;
|
|
124
|
+
case 'local':
|
|
125
|
+
options.apiURL = 'http://api.qik.localhost:4001';
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
///////////////////////////////////////
|
|
130
|
+
|
|
131
|
+
const core = Object.assign(options, {
|
|
132
|
+
version,
|
|
133
|
+
global:{},
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
///////////////////////////////////////
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Provides a cache service, used for creating, clearing
|
|
141
|
+
* and storing API requests and other information in memory
|
|
142
|
+
* @type {QikCache}
|
|
143
|
+
*/
|
|
144
|
+
const cache = QikCache;
|
|
145
|
+
Object.defineProperty(core, 'cache', {
|
|
146
|
+
value: cache,
|
|
147
|
+
writable: false,
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
///////////////////////////////////////
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Provides helper functions for working
|
|
154
|
+
* with Qik data
|
|
155
|
+
* @type {QikUtils}
|
|
156
|
+
*/
|
|
157
|
+
const utils = QikUtils;
|
|
158
|
+
Object.defineProperty(core, 'utils', {
|
|
159
|
+
value: utils,
|
|
160
|
+
writable: false,
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
///////////////////////////////////////
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Provides helper functions for working
|
|
167
|
+
* with Qik filters
|
|
168
|
+
* @type {QikFilter}
|
|
169
|
+
*/
|
|
170
|
+
const filter = QikFilter;
|
|
171
|
+
Object.defineProperty(core, 'filter', {
|
|
172
|
+
value: filter,
|
|
173
|
+
writable: false,
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
///////////////////////////////////////
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Provides helper functions for working
|
|
182
|
+
* with Qik files
|
|
183
|
+
* @type {QikFiles}
|
|
184
|
+
*/
|
|
185
|
+
const files = new QikFiles(core);
|
|
186
|
+
Object.defineProperty(core, 'files', {
|
|
187
|
+
value: files,
|
|
188
|
+
writable: false,
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
///////////////////////////////////////
|
|
192
|
+
|
|
193
|
+
//Create a new global dispatcher so we can trigger events
|
|
194
|
+
const dispatcher = new EventDispatcher();
|
|
195
|
+
dispatcher.bootstrap(core);
|
|
196
|
+
|
|
197
|
+
//Set the function
|
|
198
|
+
core.error = function(err) {
|
|
199
|
+
//Dispatch an error event
|
|
200
|
+
return core.dispatch('error', utils.errorMessage(err));
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
//And enable notifications with a short message
|
|
204
|
+
core.notify = function(message, options) {
|
|
205
|
+
return core.dispatch('notification', { message, options });
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
///////////////////////////////////////
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* The default service for interacting with
|
|
212
|
+
* the Qik REST API, it's a wrapper around the axios library
|
|
213
|
+
* that works in conjunction with the other Qik modules
|
|
214
|
+
* @type {QikAPI}
|
|
215
|
+
*/
|
|
216
|
+
const api = new QikAPI(core);
|
|
217
|
+
Object.defineProperty(core, 'api', {
|
|
218
|
+
value: api,
|
|
219
|
+
writable: false,
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* The default service for managing authentication
|
|
224
|
+
* handles automatic refreshing of access tokens, and provides login, logout
|
|
225
|
+
* and other user/application specific functionality
|
|
226
|
+
* @type {QikAuth}
|
|
227
|
+
*/
|
|
228
|
+
const auth = new QikAuth(core);
|
|
229
|
+
Object.defineProperty(core, 'auth', {
|
|
230
|
+
value: auth,
|
|
231
|
+
writable: false,
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* The default service for connecting, subscribing and unsubscribing sockets
|
|
236
|
+
* @type {QikSocket}
|
|
237
|
+
*/
|
|
238
|
+
const socket = new QikSocket(core);
|
|
239
|
+
Object.defineProperty(core, 'socket', {
|
|
240
|
+
value: socket,
|
|
241
|
+
writable: false,
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
///////////////////////////////////////
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* A helper service for understanding a user's access permissions
|
|
248
|
+
* @type {QikAccess}
|
|
249
|
+
*/
|
|
250
|
+
const access = new QikAccess(core);
|
|
251
|
+
Object.defineProperty(core, 'access', {
|
|
252
|
+
value: access,
|
|
253
|
+
writable: false,
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
///////////////////////////////////////
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* A helper service for system functions and features
|
|
260
|
+
* @type {QikSystem}
|
|
261
|
+
*/
|
|
262
|
+
const system = new QikSystem(core);
|
|
263
|
+
Object.defineProperty(core, 'system', {
|
|
264
|
+
value: system,
|
|
265
|
+
writable: false,
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
///////////////////////////////////////
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* A helper service for geolocation features
|
|
272
|
+
* @type {QikGeo}
|
|
273
|
+
*/
|
|
274
|
+
const geo = new QikGeo(core);
|
|
275
|
+
Object.defineProperty(core, 'geo', {
|
|
276
|
+
value: geo,
|
|
277
|
+
writable: false,
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
///////////////////////////////////////
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* A helper service for content create, update, read and delete operations.
|
|
285
|
+
* @type {QikContent}
|
|
286
|
+
*/
|
|
287
|
+
const content = new QikContent(core);
|
|
288
|
+
Object.defineProperty(core, 'content', {
|
|
289
|
+
value: content,
|
|
290
|
+
writable: false,
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
///////////////////////////////////////
|
|
294
|
+
|
|
295
|
+
return core;
|
|
296
|
+
|
|
297
|
+
}
|
|
298
|
+
</code></pre>
|
|
299
|
+
</article>
|
|
300
|
+
</section>
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
</div>
|
|
308
|
+
|
|
309
|
+
<br class="clear">
|
|
310
|
+
|
|
311
|
+
<footer>
|
|
312
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.11</a> on Mon Jul 13 2026 18:47:22 GMT+1000 (Australian Eastern Standard Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
313
|
+
</footer>
|
|
314
|
+
|
|
315
|
+
<script>prettyPrint();</script>
|
|
316
|
+
<script src="scripts/polyfill.js"></script>
|
|
317
|
+
<script src="scripts/linenumber.js"></script>
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
</body>
|
|
322
|
+
</html>
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
|
|
5
|
+
<meta charset="utf-8">
|
|
6
|
+
<title>qik.files.js - Documentation</title>
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
<script src="scripts/prettify/prettify.js"></script>
|
|
10
|
+
<script src="scripts/prettify/lang-css.js"></script>
|
|
11
|
+
<!--[if lt IE 9]>
|
|
12
|
+
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
|
13
|
+
<![endif]-->
|
|
14
|
+
<link type="text/css" rel="stylesheet" href="styles/prettify.css">
|
|
15
|
+
<link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
|
|
16
|
+
<script src="scripts/nav.js" defer></script>
|
|
17
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
18
|
+
</head>
|
|
19
|
+
<body>
|
|
20
|
+
|
|
21
|
+
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
|
|
22
|
+
<label for="nav-trigger" class="navicon-button x">
|
|
23
|
+
<div class="navicon"></div>
|
|
24
|
+
</label>
|
|
25
|
+
|
|
26
|
+
<label for="nav-trigger" class="overlay"></label>
|
|
27
|
+
|
|
28
|
+
<nav >
|
|
29
|
+
|
|
30
|
+
<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#.actionableScopes">actionableScopes</a></li><li data-type='method'><a href="access.html#.allPermissions">allPermissions</a></li><li data-type='method'><a href="access.html#.allPermissionTypes">allPermissionTypes</a></li><li data-type='method'><a href="access.html#.allUserScopes">allUserScopes</a></li><li data-type='method'><a href="access.html#.canCreate">canCreate</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#.canEraseItem">canEraseItem</a></li><li data-type='method'><a href="access.html#.canKnowOf">canKnowOf</a></li><li data-type='method'><a href="access.html#.canListItem">canListItem</a></li><li data-type='method'><a href="access.html#.canRestoreItem">canRestoreItem</a></li><li data-type='method'><a href="access.html#.canViewItem">canViewItem</a></li><li data-type='method'><a href="access.html#.checkActionAccess">checkActionAccess</a></li><li data-type='method'><a href="access.html#.getAllDescendants">getAllDescendants</a></li><li data-type='method'><a href="access.html#.has">has</a></li><li data-type='method'><a href="access.html#.hasFeature">hasFeature</a></li><li data-type='method'><a href="access.html#.hashPermissions">hashPermissions</a></li><li data-type='method'><a href="access.html#.isAdministrator">isAdministrator</a></li><li data-type='method'><a href="access.html#.isAssignee">isAssignee</a></li><li data-type='method'><a href="access.html#.isOwner">isOwner</a></li></ul></li><li><a href="api.html">api</a><ul class='methods'><li data-type='method'><a href="api.html#.generateEndpointURL">generateEndpointURL</a></li></ul></li><li><a href="auth.html">auth</a><ul class='methods'><li data-type='method'><a href="auth.html#.changeOrganisation">changeOrganisation</a></li><li data-type='method'><a href="auth.html#.ensureValidToken">ensureValidToken</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#.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#.sync">sync</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="content.html">content</a><ul class='methods'><li data-type='method'><a href="content.html#.create">create</a></li><li data-type='method'><a href="content.html#.delete">delete</a></li><li data-type='method'><a href="content.html#.get">get</a></li><li data-type='method'><a href="content.html#.getFromSlug">getFromSlug</a></li><li data-type='method'><a href="content.html#.glossary">glossary</a></li><li data-type='method'><a href="content.html#.list">list</a></li><li data-type='method'><a href="content.html#.patch">patch</a></li><li data-type='method'><a href="content.html#.restore">restore</a></li><li data-type='method'><a href="content.html#.scopeGlossary">scopeGlossary</a></li><li data-type='method'><a href="content.html#.update">update</a></li><li data-type='method'><a href="content.html#.validateField">validateField</a></li><li data-type='method'><a href="content.html#.variables">variables</a></li></ul></li><li><a href="files.html">files</a><ul class='methods'><li data-type='method'><a href="files.html#.downloadUrl">downloadUrl</a></li><li data-type='method'><a href="files.html#.duration">duration</a></li><li data-type='method'><a href="files.html#.filesize">filesize</a></li><li data-type='method'><a href="files.html#.getBinaryTypeFromMime">getBinaryTypeFromMime</a></li><li data-type='method'><a href="files.html#.mediaUrl">mediaUrl</a></li></ul></li><li><a href="filter.html">filter</a><ul class='methods'><li data-type='method'><a href="filter.html#.activeFilterComparators">activeFilterComparators</a></li><li data-type='method'><a href="filter.html#.activeFilterKeys">activeFilterKeys</a></li><li data-type='method'><a href="filter.html#.activeFilterOperators">activeFilterOperators</a></li><li data-type='method'><a href="filter.html#.activeFilters">activeFilters</a></li><li data-type='method'><a href="filter.html#.activeFilterValues">activeFilterValues</a></li><li data-type='method'><a href="filter.html#.filterChangeString">filterChangeString</a></li><li data-type='method'><a href="filter.html#.isValidFilter">isValidFilter</a></li></ul></li><li><a href="geo.html">geo</a><ul class='methods'><li data-type='method'><a href="geo.html#.distance">distance</a></li><li data-type='method'><a href="geo.html#.getDefaultCountry">getDefaultCountry</a></li><li data-type='method'><a href="geo.html#.getDefaultTimezone">getDefaultTimezone</a></li><li data-type='method'><a href="geo.html#.getPosition">getPosition</a></li><li data-type='method'><a href="geo.html#.stopWatchPosition">stopWatchPosition</a></li><li data-type='method'><a href="geo.html#.watchPosition">watchPosition</a></li></ul></li><li><a href="module-QikStorage-CookieStorageAdapter.html">CookieStorageAdapter</a><ul class='methods'><li data-type='method'><a href="module-QikStorage-CookieStorageAdapter.html#getCookieOptions">getCookieOptions</a></li><li data-type='method'><a href="module-QikStorage-CookieStorageAdapter.html#isCookieMode">isCookieMode</a></li></ul></li><li><a href="module-QikStorage-LocalStorageAdapter.html">LocalStorageAdapter</a></li><li><a href="module-QikStorage-StorageAdapter.html">StorageAdapter</a><ul class='methods'><li data-type='method'><a href="module-QikStorage-StorageAdapter.html#clearUser">clearUser</a></li><li data-type='method'><a href="module-QikStorage-StorageAdapter.html#getAccessToken">getAccessToken</a></li><li data-type='method'><a href="module-QikStorage-StorageAdapter.html#getRefreshToken">getRefreshToken</a></li><li data-type='method'><a href="module-QikStorage-StorageAdapter.html#getTokenExpiry">getTokenExpiry</a></li><li data-type='method'><a href="module-QikStorage-StorageAdapter.html#getUser">getUser</a></li><li data-type='method'><a href="module-QikStorage-StorageAdapter.html#isAvailable">isAvailable</a></li><li data-type='method'><a href="module-QikStorage-StorageAdapter.html#setUser">setUser</a></li></ul></li><li><a href="socket.html">socket</a><ul class='methods'><li data-type='method'><a href="socket.html#.channel">channel</a></li><li data-type='method'><a href="socket.html#.close">close</a></li><li data-type='method'><a href="socket.html#.connect">connect</a></li><li data-type='method'><a href="socket.html#.reconnect">reconnect</a></li><li data-type='method'><a href="socket.html#.subscribe">subscribe</a></li><li data-type='method'><a href="socket.html#.unsubscribe">unsubscribe</a></li></ul></li><li><a href="system.html">system</a><ul class='methods'><li data-type='method'><a href="system.html#.countries">countries</a></li></ul></li><li><a href="utils.html">utils</a><ul class='methods'><li data-type='method'><a href="utils.html#.cleanValue">cleanValue</a></li><li data-type='method'><a href="utils.html#.comma">comma</a></li><li data-type='method'><a href="utils.html#.errorMessage">errorMessage</a></li><li data-type='method'><a href="utils.html#.exists">exists</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#.getTypeFromID">getTypeFromID</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#.id">id</a></li><li data-type='method'><a href="utils.html#.ids">ids</a></li><li data-type='method'><a href="utils.html#.isValidEmailAddress">isValidEmailAddress</a></li><li data-type='method'><a href="utils.html#.loadExternalScript">loadExternalScript</a></li><li data-type='method'><a href="utils.html#.loadExternalStyle">loadExternalStyle</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#.parseBoolean">parseBoolean</a></li><li data-type='method'><a href="utils.html#.parseDate">parseDate</a></li><li data-type='method'><a href="utils.html#.parseEmail">parseEmail</a></li><li data-type='method'><a href="utils.html#.parseInt">parseInt</a></li><li data-type='method'><a href="utils.html#.parseNumber">parseNumber</a></li><li data-type='method'><a href="utils.html#.parseURL">parseURL</a></li></ul></li></ul><h3>Modules</h3><ul><li><a href="module-QikStorage.html">QikStorage</a><ul class='methods'><li data-type='method'><a href="module-QikStorage.html#.createStorageAdapter">createStorageAdapter</a></li></ul></li></ul><h3>Global</h3><ul><li><a href="global.html#EventDispatcher">EventDispatcher</a></li></ul>
|
|
31
|
+
</nav>
|
|
32
|
+
|
|
33
|
+
<div id="main">
|
|
34
|
+
|
|
35
|
+
<h1 class="page-title">qik.files.js</h1>
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
<section>
|
|
44
|
+
<article>
|
|
45
|
+
<pre class="prettyprint source linenums"><code>/**
|
|
46
|
+
* Creates a new Files Module instance.
|
|
47
|
+
* This module provides a number of helper functions for interacting with binary file and media content via the REST API
|
|
48
|
+
* @alias files
|
|
49
|
+
* @constructor
|
|
50
|
+
* @hideconstructor
|
|
51
|
+
* @param {QikCore} qik A reference to the parent instance of the QikCore module. This module is usually created by a QikCore instance that passes itself in as the first argument.
|
|
52
|
+
*/
|
|
53
|
+
export default function (qik) {
|
|
54
|
+
///////////////////////
|
|
55
|
+
|
|
56
|
+
var service = {};
|
|
57
|
+
|
|
58
|
+
///////////////////////
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
*
|
|
62
|
+
* Get a valid download url for a specified record
|
|
63
|
+
* @alias files.downloadUrl
|
|
64
|
+
* @param {String} type The type or definition of the item we want to generate the url for
|
|
65
|
+
* @param {(Object|String)} id The id or object with an _id property that we want to generate the url for
|
|
66
|
+
* @param {Object} params Additional parameters and options for the url
|
|
67
|
+
* @example
|
|
68
|
+
* const url = sdk.files.downloadUrl('image', '61eca4746971e75c1fc670cf', {w:100, h:100});
|
|
69
|
+
* // https://api.qik.dev/image/61eca4746971e75c1fc670cf?w=100&h=100&download=true
|
|
70
|
+
*
|
|
71
|
+
* const url = sdk.files.downloadUrl('image', {_id:'61eca4746971e75c1fc670cf'...}, {f:'png'});
|
|
72
|
+
* // https://api.qik.dev/image/61eca4746971e75c1fc670cf?w=100&h=100&download=true
|
|
73
|
+
*/
|
|
74
|
+
service.downloadUrl = function (type, id, params, options) {
|
|
75
|
+
options = options || {};
|
|
76
|
+
params = params || {};
|
|
77
|
+
params.download = true;
|
|
78
|
+
id = qik.utils.id(id);
|
|
79
|
+
return qik.api.generateEndpointURL(`/${type}/${id}`, params, options);
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
*
|
|
84
|
+
* Format a number of (seconds) as timecode (01:35)
|
|
85
|
+
* @alias files.duration
|
|
86
|
+
* @param {Number} seconds The number of seconds
|
|
87
|
+
* @example
|
|
88
|
+
* const timecode = sdk.files.formatDuration(392.6)
|
|
89
|
+
*/
|
|
90
|
+
service.duration = function (seconds) {
|
|
91
|
+
// Round to handle floating point values
|
|
92
|
+
const totalSeconds = Math.round(seconds);
|
|
93
|
+
|
|
94
|
+
// Calculate hours, minutes, and remaining seconds
|
|
95
|
+
const hours = Math.floor(totalSeconds / 3600);
|
|
96
|
+
const minutes = Math.floor((totalSeconds % 3600) / 60);
|
|
97
|
+
const remainingSeconds = totalSeconds % 60;
|
|
98
|
+
|
|
99
|
+
// Format the output with padding
|
|
100
|
+
if (hours > 0) {
|
|
101
|
+
return `${hours}:${minutes.toString().padStart(2, "0")}:${remainingSeconds.toString().padStart(2, "0")}`;
|
|
102
|
+
} else {
|
|
103
|
+
return `${minutes}:${remainingSeconds.toString().padStart(2, "0")}`;
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
*
|
|
109
|
+
* Get a valid media url for a specified image, video or audio item
|
|
110
|
+
* @alias files.mediaUrl
|
|
111
|
+
* @param {String} type The type or definition of the item we want to generate the url for
|
|
112
|
+
* @param {(Object|String)} id The id or object with an _id property that we want to generate the url for
|
|
113
|
+
* @param {Object} params Additional parameters and options for the url
|
|
114
|
+
* @example
|
|
115
|
+
* const url = sdk.files.mediaUrl('image', '61eca4746971e75c1fc670cf', {w:100, h:100});
|
|
116
|
+
* // https://api.qik.dev/image/61eca4746971e75c1fc670cf?w=100&h=100&download=true
|
|
117
|
+
*
|
|
118
|
+
* const url = sdk.files.mediaUrl('image', {_id:'61eca4746971e75c1fc670cf'...}, {f:'png'});
|
|
119
|
+
* // https://api.qik.dev/image/61eca4746971e75c1fc670cf?w=100&h=100&download=true
|
|
120
|
+
*/
|
|
121
|
+
service.mediaUrl = function (type, id, params, options) {
|
|
122
|
+
options = options || {};
|
|
123
|
+
params = params || {};
|
|
124
|
+
id = qik.utils.id(id);
|
|
125
|
+
|
|
126
|
+
let path = `/${type}/${id}`;
|
|
127
|
+
if (options.extension?.length) {
|
|
128
|
+
if (options.extension.includes(".")) {
|
|
129
|
+
path = `${path}/${options.extension}`;
|
|
130
|
+
} else {
|
|
131
|
+
path = `${path}/${type}.${options.extension}`;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return qik.api.generateEndpointURL(path, params, options);
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
///////////////////////
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
*
|
|
142
|
+
* Convert bytes to a human readable file size
|
|
143
|
+
* @alias files.filesize
|
|
144
|
+
* @param {Integer} bytes The number of bytes
|
|
145
|
+
* @example
|
|
146
|
+
* const size = sdk.files.filesize(1500);
|
|
147
|
+
* // 1.5kb
|
|
148
|
+
*/
|
|
149
|
+
service.filesize = function (bytes, decimals) {
|
|
150
|
+
if (bytes == 0) return "0 Bytes";
|
|
151
|
+
var k = 1024,
|
|
152
|
+
dm = decimals || 2,
|
|
153
|
+
sizes = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"],
|
|
154
|
+
i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
155
|
+
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + " " + sizes[i];
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
///////////////////////
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
*
|
|
162
|
+
* Get the basic primitive type of a file from it's mime type value
|
|
163
|
+
* @alias files.getBinaryTypeFromMime
|
|
164
|
+
* @param {String} fileMime The mime type of the file
|
|
165
|
+
* @example
|
|
166
|
+
* const type = sdk.files.getBinaryTypeFromMime('image/svg+xml');
|
|
167
|
+
* // 'image'
|
|
168
|
+
*
|
|
169
|
+
* const type = sdk.files.getBinaryTypeFromMime('video/webm');
|
|
170
|
+
* // 'video'
|
|
171
|
+
*/
|
|
172
|
+
service.getBinaryTypeFromMime = function (fileMime) {
|
|
173
|
+
if (!fileMime) {
|
|
174
|
+
return "file";
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
////////////////////////////////
|
|
178
|
+
|
|
179
|
+
switch (fileMime) {
|
|
180
|
+
case "image/jpeg":
|
|
181
|
+
case "image/png":
|
|
182
|
+
case "image/gif":
|
|
183
|
+
case "image/bmp":
|
|
184
|
+
case "image/tiff":
|
|
185
|
+
case "image/svg+xml":
|
|
186
|
+
return "image";
|
|
187
|
+
break;
|
|
188
|
+
case "video/mp4":
|
|
189
|
+
case "video/quicktime":
|
|
190
|
+
case "video/ogg":
|
|
191
|
+
case "video/webm":
|
|
192
|
+
return "video";
|
|
193
|
+
break;
|
|
194
|
+
case "audio/aac":
|
|
195
|
+
case "audio/aiff":
|
|
196
|
+
case "audio/mp3":
|
|
197
|
+
case "audio/x-m4a":
|
|
198
|
+
case "audio/mpeg":
|
|
199
|
+
case "audio/ogg":
|
|
200
|
+
case "audio/wav":
|
|
201
|
+
case "audio/webm":
|
|
202
|
+
return "audio";
|
|
203
|
+
break;
|
|
204
|
+
default:
|
|
205
|
+
//See if we can guess it from the first part of the mimetype
|
|
206
|
+
var prefix = fileMime.split("/")[0];
|
|
207
|
+
switch (prefix) {
|
|
208
|
+
case "image":
|
|
209
|
+
case "video":
|
|
210
|
+
case "audio":
|
|
211
|
+
return prefix;
|
|
212
|
+
break;
|
|
213
|
+
default:
|
|
214
|
+
return "file";
|
|
215
|
+
break;
|
|
216
|
+
}
|
|
217
|
+
break;
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
////////////////////////////////
|
|
222
|
+
|
|
223
|
+
return service;
|
|
224
|
+
}
|
|
225
|
+
</code></pre>
|
|
226
|
+
</article>
|
|
227
|
+
</section>
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
</div>
|
|
235
|
+
|
|
236
|
+
<br class="clear">
|
|
237
|
+
|
|
238
|
+
<footer>
|
|
239
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.11</a> on Mon Jul 13 2026 18:47:22 GMT+1000 (Australian Eastern Standard Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
240
|
+
</footer>
|
|
241
|
+
|
|
242
|
+
<script>prettyPrint();</script>
|
|
243
|
+
<script src="scripts/polyfill.js"></script>
|
|
244
|
+
<script src="scripts/linenumber.js"></script>
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
</body>
|
|
249
|
+
</html>
|