@scaleflex/widget-tus 0.0.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 scaleflex
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # @scaleflex/widget-tus
2
+
3
+ [![Plugins][plugins-image]](#plugins)
4
+ [![Website][filerobot-image]][sfx-url]
5
+ [![Version][filerobot-version]][version-url]
6
+ [![Scaleflex team][made-by-image]][sfx-url]
7
+ [![License][license-image]][license-url]
8
+ [![CodeSandbox][codeSandbox-image]][codeSandbox-url]
9
+
10
+
11
+ <div align='center'>
12
+ <img title="Scaleflex Widget logo" alt="Scaleflex Widget logo" src="https://cdn.scaleflex.com/plugins/filerobot-widget/assets/filerobot_widget_logo_with_fire.png?vh=b2ff09" width="140"/>
13
+ </div>
14
+
15
+ <!-- Variables -->
16
+
17
+ [npm-url]: https://www.npmjs.com/package/@scaleflex/widget-tus
18
+ [license-url]: https://opensource.org/licenses/MIT
19
+ [sfx-url]: https://www.scaleflex.com/
20
+ [version-url]: https://www.npmjs.com/package/@scaleflex/widget-tus
21
+ [codeSandbox-url]: https://codesandbox.io/s/filerobot-widget-v3-c5l9th
22
+
23
+ [npm-image]: https://img.shields.io/npm/v/@telus/remark-config.svg?style=for-the-badge&logo=npm
24
+ [license-image]: https://img.shields.io/badge/license-MIT-blue.svg?style=for-the-badge
25
+ [made-by-image]: https://img.shields.io/badge/%3C%2F%3E%20with%20%E2%99%A5%20by-the%20Scaleflex%20team-6986fa.svg?style=for-the-badge
26
+ [plugins-image]: https://img.shields.io/static/v1?label=Scaleflex&message=Plugins&color=yellow&style=for-the-badge
27
+ [filerobot-image]: https://img.shields.io/static/v1?label=Scaleflex&message=website&color=orange&style=for-the-badge
28
+ [filerobot-version]: https://img.shields.io/npm/v/@scaleflex/widget-tus?label=Version&style=for-the-badge&logo=npm
29
+ [codeSandbox-image]: https://img.shields.io/badge/CodeSandbox-black?style=for-the-badge&logo=CodeSandbox
@@ -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
+ }