@scaleflex/widget-tus 4.8.6 → 4.8.7
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/lib/getFingerprint.js +25 -0
- package/lib/index.js +983 -0
- package/package.json +25 -25
- package/CHANGELOG.md +0 -6353
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { defaultOptions } from 'tus-js-client';
|
|
2
|
+
function isCordova() {
|
|
3
|
+
return typeof window !== 'undefined' && (typeof window.PhoneGap !== 'undefined' || typeof window.Cordova !== 'undefined' || typeof window.cordova !== 'undefined');
|
|
4
|
+
}
|
|
5
|
+
function isReactNative() {
|
|
6
|
+
return typeof navigator !== 'undefined' && typeof navigator.product === 'string' && navigator.product.toLowerCase() === 'reactnative';
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
// We override tus fingerprint to filerobot’s `file.id`, since the `file.id`
|
|
10
|
+
// now also includes `relativePath` for files added from folders.
|
|
11
|
+
// This means you can add 2 identical files, if one is in folder a,
|
|
12
|
+
// the other in folder b — `a/file.jpg` and `b/file.jpg`, when added
|
|
13
|
+
// together with a folder, will be treated as 2 separate files.
|
|
14
|
+
//
|
|
15
|
+
// For React Native and Cordova, we let tus-js-client’s default
|
|
16
|
+
// fingerprint handling take charge.
|
|
17
|
+
export default function getFingerprint(filerobotFileObj) {
|
|
18
|
+
return function (file, options) {
|
|
19
|
+
if (isCordova() || isReactNative()) {
|
|
20
|
+
return defaultOptions.fingerprint(file, options);
|
|
21
|
+
}
|
|
22
|
+
var filerobotFingerprint = ['tus', filerobotFileObj.id, options.endpoint].join('-');
|
|
23
|
+
return Promise.resolve(filerobotFingerprint);
|
|
24
|
+
};
|
|
25
|
+
}
|