cozy-viewer 18.0.3 → 18.1.0
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/CHANGELOG.md +11 -0
- package/dist/Footer/ForwardButton.d.ts +0 -2
- package/dist/Footer/ForwardButton.js +10 -44
- package/dist/Footer/helpers.d.ts +0 -1
- package/dist/Footer/helpers.js +5 -126
- package/package.json +3 -3
- package/src/Footer/ForwardButton.jsx +10 -21
- package/src/Footer/ForwardButton.spec.jsx +3 -35
- package/src/Footer/helpers.js +1 -68
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [18.1.0](https://github.com/cozy/cozy-libs/compare/cozy-viewer@18.0.3...cozy-viewer@18.1.0) (2025-03-07)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* Remove cordova code ([55b97c5](https://github.com/cozy/cozy-libs/commit/55b97c5623a59a383227f4c30c32e0735a5480ca))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
## [18.0.3](https://github.com/cozy/cozy-libs/compare/cozy-viewer@18.0.2...cozy-viewer@18.0.3) (2025-02-26)
|
|
7
18
|
|
|
8
19
|
**Note:** Version bump only for package cozy-viewer
|
|
@@ -6,12 +6,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
8
|
exports.default = void 0;
|
|
9
|
-
Object.defineProperty(exports, "exportFilesNative", {
|
|
10
|
-
enumerable: true,
|
|
11
|
-
get: function get() {
|
|
12
|
-
return _helpers.exportFilesNative;
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
9
|
|
|
16
10
|
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
17
11
|
|
|
@@ -41,8 +35,6 @@ var _Alerter = _interopRequireDefault(require("cozy-ui/transpiled/react/deprecat
|
|
|
41
35
|
|
|
42
36
|
var _I18n = require("cozy-ui/transpiled/react/providers/I18n");
|
|
43
37
|
|
|
44
|
-
var _helpers = require("./helpers");
|
|
45
|
-
|
|
46
38
|
var ForwardIcon = (0, _cozyDeviceHelper.isIOS)() ? _ShareIos.default : _Reply.default;
|
|
47
39
|
|
|
48
40
|
var ForwardButton = function ForwardButton(_ref) {
|
|
@@ -67,37 +59,11 @@ var ForwardButton = function ForwardButton(_ref) {
|
|
|
67
59
|
return _regenerator.default.wrap(function _callee$(_context) {
|
|
68
60
|
while (1) switch (_context.prev = _context.next) {
|
|
69
61
|
case 0:
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
break;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
_context.prev = 1;
|
|
76
|
-
_context.next = 4;
|
|
77
|
-
return (0, _helpers.exportFilesNative)(client, [file]);
|
|
78
|
-
|
|
79
|
-
case 4:
|
|
80
|
-
_context.next = 9;
|
|
81
|
-
break;
|
|
82
|
-
|
|
83
|
-
case 6:
|
|
84
|
-
_context.prev = 6;
|
|
85
|
-
_context.t0 = _context["catch"](1);
|
|
86
|
-
|
|
87
|
-
_Alerter.default.info("Viewer.error.".concat(_context.t0), {
|
|
88
|
-
fileMime: file.mime
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
case 9:
|
|
92
|
-
_context.next = 22;
|
|
93
|
-
break;
|
|
94
|
-
|
|
95
|
-
case 11:
|
|
96
|
-
_context.prev = 11;
|
|
97
|
-
_context.next = 14;
|
|
62
|
+
_context.prev = 0;
|
|
63
|
+
_context.next = 3;
|
|
98
64
|
return (0, _sharing.makeSharingLink)(client, [file.id]);
|
|
99
65
|
|
|
100
|
-
case
|
|
66
|
+
case 3:
|
|
101
67
|
url = _context.sent;
|
|
102
68
|
shareData = {
|
|
103
69
|
title: t('Viewer.share.title', {
|
|
@@ -109,22 +75,22 @@ var ForwardButton = function ForwardButton(_ref) {
|
|
|
109
75
|
url: url
|
|
110
76
|
};
|
|
111
77
|
navigator.share(shareData);
|
|
112
|
-
_context.next =
|
|
78
|
+
_context.next = 11;
|
|
113
79
|
break;
|
|
114
80
|
|
|
115
|
-
case
|
|
116
|
-
_context.prev =
|
|
117
|
-
_context.
|
|
81
|
+
case 8:
|
|
82
|
+
_context.prev = 8;
|
|
83
|
+
_context.t0 = _context["catch"](0);
|
|
118
84
|
|
|
119
85
|
_Alerter.default.error('Viewer.share.error', {
|
|
120
|
-
error: _context.
|
|
86
|
+
error: _context.t0
|
|
121
87
|
});
|
|
122
88
|
|
|
123
|
-
case
|
|
89
|
+
case 11:
|
|
124
90
|
case "end":
|
|
125
91
|
return _context.stop();
|
|
126
92
|
}
|
|
127
|
-
}, _callee, null, [[
|
|
93
|
+
}, _callee, null, [[0, 8]]);
|
|
128
94
|
}));
|
|
129
95
|
|
|
130
96
|
return function onFileOpen(_x) {
|
package/dist/Footer/helpers.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export function shouldBeForwardButton(client: any): boolean;
|
|
2
|
-
export function exportFilesNative(client: CozyClient, files: array, filename: string): Promise<void>;
|
|
3
2
|
export function mapToAllChildren(children: any, cb: any): any;
|
|
4
3
|
export function extractChildrenCompByName({ children, file, name }: {
|
|
5
4
|
children: any;
|
package/dist/Footer/helpers.js
CHANGED
|
@@ -1,24 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
3
|
Object.defineProperty(exports, "__esModule", {
|
|
6
4
|
value: true
|
|
7
5
|
});
|
|
8
|
-
exports.shouldBeForwardButton = exports.mapToAllChildren = exports.extractChildrenCompByName =
|
|
9
|
-
|
|
10
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
11
|
-
|
|
12
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
6
|
+
exports.shouldBeForwardButton = exports.mapToAllChildren = exports.extractChildrenCompByName = void 0;
|
|
13
7
|
|
|
14
8
|
var _react = require("react");
|
|
15
9
|
|
|
16
|
-
var _fsnative = require("cozy-client/dist/models/fsnative");
|
|
17
|
-
|
|
18
10
|
var _cozyDeviceHelper = require("cozy-device-helper");
|
|
19
11
|
|
|
20
|
-
var _Alerter = _interopRequireDefault(require("cozy-ui/transpiled/react/deprecated/Alerter"));
|
|
21
|
-
|
|
22
12
|
var shouldBeForwardButton = exports.shouldBeForwardButton = function shouldBeForwardButton(client) {
|
|
23
13
|
var _client$appMetadata;
|
|
24
14
|
|
|
@@ -27,117 +17,6 @@ var shouldBeForwardButton = exports.shouldBeForwardButton = function shouldBeFor
|
|
|
27
17
|
return false;
|
|
28
18
|
};
|
|
29
19
|
|
|
30
|
-
var isMissingFileError = function isMissingFileError(error) {
|
|
31
|
-
return error.status === 404;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
var downloadFileError = function downloadFileError(error) {
|
|
35
|
-
return isMissingFileError(error) ? 'Viewer.error.downloadFile.missing' : 'Viewer.error.missing';
|
|
36
|
-
};
|
|
37
|
-
/**
|
|
38
|
-
* exportFilesNative - Triggers a prompt to download a file on mobile devices
|
|
39
|
-
*
|
|
40
|
-
* @param {CozyClient} client
|
|
41
|
-
* @param {array} files One or more files to download
|
|
42
|
-
* @param {string} filename The name of the file that will be saved
|
|
43
|
-
*/
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
var exportFilesNative = exports.exportFilesNative = /*#__PURE__*/function () {
|
|
47
|
-
var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(client, files, filename) {
|
|
48
|
-
var downloadAllFiles, urls;
|
|
49
|
-
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
50
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
51
|
-
case 0:
|
|
52
|
-
downloadAllFiles = files.map( /*#__PURE__*/function () {
|
|
53
|
-
var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(file) {
|
|
54
|
-
var response, blob, filenameToUse, localFile;
|
|
55
|
-
return _regenerator.default.wrap(function _callee$(_context) {
|
|
56
|
-
while (1) switch (_context.prev = _context.next) {
|
|
57
|
-
case 0:
|
|
58
|
-
_context.next = 2;
|
|
59
|
-
return client.collection('io.cozy.files').fetchFileContentById(file.id);
|
|
60
|
-
|
|
61
|
-
case 2:
|
|
62
|
-
response = _context.sent;
|
|
63
|
-
_context.next = 5;
|
|
64
|
-
return response.blob();
|
|
65
|
-
|
|
66
|
-
case 5:
|
|
67
|
-
blob = _context.sent;
|
|
68
|
-
filenameToUse = filename ? filename : file.name;
|
|
69
|
-
_context.next = 9;
|
|
70
|
-
return (0, _fsnative.saveFileWithCordova)(blob, filenameToUse);
|
|
71
|
-
|
|
72
|
-
case 9:
|
|
73
|
-
localFile = _context.sent;
|
|
74
|
-
return _context.abrupt("return", localFile.nativeURL);
|
|
75
|
-
|
|
76
|
-
case 11:
|
|
77
|
-
case "end":
|
|
78
|
-
return _context.stop();
|
|
79
|
-
}
|
|
80
|
-
}, _callee);
|
|
81
|
-
}));
|
|
82
|
-
|
|
83
|
-
return function (_x4) {
|
|
84
|
-
return _ref2.apply(this, arguments);
|
|
85
|
-
};
|
|
86
|
-
}());
|
|
87
|
-
_context2.prev = 1;
|
|
88
|
-
|
|
89
|
-
_Alerter.default.info('Viewer.alert.preparing', {
|
|
90
|
-
duration: Math.min(downloadAllFiles.length * 2000, 6000)
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
_context2.next = 5;
|
|
94
|
-
return Promise.all(downloadAllFiles);
|
|
95
|
-
|
|
96
|
-
case 5:
|
|
97
|
-
urls = _context2.sent;
|
|
98
|
-
|
|
99
|
-
if (urls.length === 1 && (0, _cozyDeviceHelper.isIOS)()) {
|
|
100
|
-
// TODO
|
|
101
|
-
// It seems that files: is not well supported on iOS. url seems to work well
|
|
102
|
-
// at with one file. Need to check when severals
|
|
103
|
-
window.plugins.socialsharing.shareWithOptions({
|
|
104
|
-
url: urls[0]
|
|
105
|
-
}, function (result) {
|
|
106
|
-
if (result.completed === true) {
|
|
107
|
-
_Alerter.default.success('Viewer.share.success');
|
|
108
|
-
}
|
|
109
|
-
}, function (error) {
|
|
110
|
-
throw error;
|
|
111
|
-
});
|
|
112
|
-
} else {
|
|
113
|
-
window.plugins.socialsharing.shareWithOptions({
|
|
114
|
-
files: urls
|
|
115
|
-
}, null, function (error) {
|
|
116
|
-
throw error;
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
_context2.next = 12;
|
|
121
|
-
break;
|
|
122
|
-
|
|
123
|
-
case 9:
|
|
124
|
-
_context2.prev = 9;
|
|
125
|
-
_context2.t0 = _context2["catch"](1);
|
|
126
|
-
|
|
127
|
-
_Alerter.default.error(downloadFileError(_context2.t0));
|
|
128
|
-
|
|
129
|
-
case 12:
|
|
130
|
-
case "end":
|
|
131
|
-
return _context2.stop();
|
|
132
|
-
}
|
|
133
|
-
}, _callee2, null, [[1, 9]]);
|
|
134
|
-
}));
|
|
135
|
-
|
|
136
|
-
return function exportFilesNative(_x, _x2, _x3) {
|
|
137
|
-
return _ref.apply(this, arguments);
|
|
138
|
-
};
|
|
139
|
-
}();
|
|
140
|
-
|
|
141
20
|
var mapToAllChildren = exports.mapToAllChildren = function mapToAllChildren(children, cb) {
|
|
142
21
|
return _react.Children.map(children, function (child) {
|
|
143
22
|
if (! /*#__PURE__*/(0, _react.isValidElement)(child)) return child;
|
|
@@ -153,10 +32,10 @@ var mapToAllChildren = exports.mapToAllChildren = function mapToAllChildren(chil
|
|
|
153
32
|
});
|
|
154
33
|
};
|
|
155
34
|
|
|
156
|
-
var extractChildrenCompByName = exports.extractChildrenCompByName = function extractChildrenCompByName(
|
|
157
|
-
var children =
|
|
158
|
-
file =
|
|
159
|
-
name =
|
|
35
|
+
var extractChildrenCompByName = exports.extractChildrenCompByName = function extractChildrenCompByName(_ref) {
|
|
36
|
+
var children = _ref.children,
|
|
37
|
+
file = _ref.file,
|
|
38
|
+
name = _ref.name;
|
|
160
39
|
var ChildrenComp = _react.Children.toArray(children).find(function (child) {
|
|
161
40
|
return child.type.name === name || child.type.displayName === name;
|
|
162
41
|
}) || null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cozy-viewer",
|
|
3
|
-
"version": "18.0
|
|
3
|
+
"version": "18.1.0",
|
|
4
4
|
"description": "Cozy-Viewer provides a component to show files in a viewer.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"license": "MIT",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"babel-preset-cozy-app": "^2.8.1",
|
|
28
28
|
"cozy-client": "^53.1.1",
|
|
29
29
|
"cozy-device-helper": "2.0.0",
|
|
30
|
-
"cozy-harvest-lib": "^32.2.
|
|
30
|
+
"cozy-harvest-lib": "^32.2.36",
|
|
31
31
|
"cozy-intent": "^2.29.2",
|
|
32
32
|
"cozy-logger": "^1.16.1",
|
|
33
33
|
"cozy-sharing": "^22.0.0",
|
|
@@ -59,5 +59,5 @@
|
|
|
59
59
|
"react": ">=16.12.0",
|
|
60
60
|
"react-dom": ">=16.12.0"
|
|
61
61
|
},
|
|
62
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "ba5bc9fde3aef483d73266287601694011afa138"
|
|
63
63
|
}
|
|
@@ -3,7 +3,7 @@ import React from 'react'
|
|
|
3
3
|
|
|
4
4
|
import { useClient } from 'cozy-client'
|
|
5
5
|
import { makeSharingLink } from 'cozy-client/dist/models/sharing'
|
|
6
|
-
import { isIOS
|
|
6
|
+
import { isIOS } from 'cozy-device-helper'
|
|
7
7
|
import Button from 'cozy-ui/transpiled/react/Buttons'
|
|
8
8
|
import Icon from 'cozy-ui/transpiled/react/Icon'
|
|
9
9
|
import IconButton from 'cozy-ui/transpiled/react/IconButton'
|
|
@@ -12,8 +12,6 @@ import ShareIosIcon from 'cozy-ui/transpiled/react/Icons/ShareIos'
|
|
|
12
12
|
import Alerter from 'cozy-ui/transpiled/react/deprecated/Alerter'
|
|
13
13
|
import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n'
|
|
14
14
|
|
|
15
|
-
import { exportFilesNative } from './helpers'
|
|
16
|
-
|
|
17
15
|
const ForwardIcon = isIOS() ? ShareIosIcon : ReplyIcon
|
|
18
16
|
|
|
19
17
|
const ForwardButton = ({ file, variant, onClick }) => {
|
|
@@ -24,24 +22,16 @@ const ForwardButton = ({ file, variant, onClick }) => {
|
|
|
24
22
|
const label = t('Viewer.actions.forward')
|
|
25
23
|
|
|
26
24
|
const onFileOpen = async file => {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
} else {
|
|
34
|
-
try {
|
|
35
|
-
const url = await makeSharingLink(client, [file.id])
|
|
36
|
-
const shareData = {
|
|
37
|
-
title: t('Viewer.share.title', { name: file.name }),
|
|
38
|
-
text: t('Viewer.share.text', { name: file.name }),
|
|
39
|
-
url
|
|
40
|
-
}
|
|
41
|
-
navigator.share(shareData)
|
|
42
|
-
} catch (error) {
|
|
43
|
-
Alerter.error('Viewer.share.error', { error: error })
|
|
25
|
+
try {
|
|
26
|
+
const url = await makeSharingLink(client, [file.id])
|
|
27
|
+
const shareData = {
|
|
28
|
+
title: t('Viewer.share.title', { name: file.name }),
|
|
29
|
+
text: t('Viewer.share.text', { name: file.name }),
|
|
30
|
+
url
|
|
44
31
|
}
|
|
32
|
+
navigator.share(shareData)
|
|
33
|
+
} catch (error) {
|
|
34
|
+
Alerter.error('Viewer.share.error', { error: error })
|
|
45
35
|
}
|
|
46
36
|
}
|
|
47
37
|
|
|
@@ -91,5 +81,4 @@ ForwardButton.defaultProptypes = {
|
|
|
91
81
|
variant: 'default'
|
|
92
82
|
}
|
|
93
83
|
|
|
94
|
-
export { exportFilesNative }
|
|
95
84
|
export default ForwardButton
|
|
@@ -2,10 +2,8 @@ import { render, fireEvent } from '@testing-library/react'
|
|
|
2
2
|
import React from 'react'
|
|
3
3
|
|
|
4
4
|
import { makeSharingLink } from 'cozy-client/dist/models/sharing'
|
|
5
|
-
import { isMobileApp } from 'cozy-device-helper'
|
|
6
5
|
|
|
7
6
|
import ForwardButton from './ForwardButton'
|
|
8
|
-
import { exportFilesNative } from './helpers'
|
|
9
7
|
import DemoProvider from '../providers/DemoProvider'
|
|
10
8
|
|
|
11
9
|
jest.mock('cozy-device-helper')
|
|
@@ -20,8 +18,7 @@ const file = {
|
|
|
20
18
|
name: 'filename.pdf'
|
|
21
19
|
}
|
|
22
20
|
|
|
23
|
-
const setup = ({
|
|
24
|
-
isMobileApp.mockReturnValue(isMobileApplication)
|
|
21
|
+
const setup = ({ onClick }) => {
|
|
25
22
|
return render(
|
|
26
23
|
<DemoProvider>
|
|
27
24
|
<ForwardButton file={file} onClick={onClick} />
|
|
@@ -34,39 +31,10 @@ describe('ForwardButton', () => {
|
|
|
34
31
|
jest.resetAllMocks()
|
|
35
32
|
})
|
|
36
33
|
|
|
37
|
-
describe('exportFilesNative', () => {
|
|
38
|
-
it('should call it if is on native app', async () => {
|
|
39
|
-
const { findByTestId } = setup({ isMobileApplication: true })
|
|
40
|
-
|
|
41
|
-
const btn = await findByTestId('openFileButton')
|
|
42
|
-
fireEvent.click(btn)
|
|
43
|
-
|
|
44
|
-
expect(exportFilesNative).toHaveBeenCalledTimes(1)
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
it('should not call it if is on web app', async () => {
|
|
48
|
-
const { findByTestId } = setup({ isMobileApplication: false })
|
|
49
|
-
|
|
50
|
-
const btn = await findByTestId('openFileButton')
|
|
51
|
-
fireEvent.click(btn)
|
|
52
|
-
|
|
53
|
-
expect(exportFilesNative).toHaveBeenCalledTimes(0)
|
|
54
|
-
})
|
|
55
|
-
})
|
|
56
|
-
|
|
57
34
|
describe('makeSharingLink', () => {
|
|
58
|
-
it('should not call it if is on native app', async () => {
|
|
59
|
-
const { findByTestId } = setup({ isMobileApplication: true })
|
|
60
|
-
|
|
61
|
-
const btn = await findByTestId('openFileButton')
|
|
62
|
-
fireEvent.click(btn)
|
|
63
|
-
|
|
64
|
-
expect(makeSharingLink).toHaveBeenCalledTimes(0)
|
|
65
|
-
})
|
|
66
|
-
|
|
67
35
|
it('should not call it if the "onClick" prop is passed', async () => {
|
|
68
36
|
const onClick = jest.fn()
|
|
69
|
-
const { findByTestId } = setup({
|
|
37
|
+
const { findByTestId } = setup({ onClick })
|
|
70
38
|
|
|
71
39
|
const btn = await findByTestId('openFileButton')
|
|
72
40
|
fireEvent.click(btn)
|
|
@@ -76,7 +44,7 @@ describe('ForwardButton', () => {
|
|
|
76
44
|
})
|
|
77
45
|
|
|
78
46
|
it('should call it if is on web app', async () => {
|
|
79
|
-
const { findByTestId } = setup({
|
|
47
|
+
const { findByTestId } = setup({})
|
|
80
48
|
|
|
81
49
|
const btn = await findByTestId('openFileButton')
|
|
82
50
|
fireEvent.click(btn)
|
package/src/Footer/helpers.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { isValidElement, Children, cloneElement } from 'react'
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import { isIOS, isMobileApp } from 'cozy-device-helper'
|
|
5
|
-
import Alerter from 'cozy-ui/transpiled/react/deprecated/Alerter'
|
|
3
|
+
import { isMobileApp } from 'cozy-device-helper'
|
|
6
4
|
|
|
7
5
|
export const shouldBeForwardButton = client => {
|
|
8
6
|
const isDrive = client?.appMetadata?.slug === 'drive'
|
|
@@ -10,71 +8,6 @@ export const shouldBeForwardButton = client => {
|
|
|
10
8
|
return false
|
|
11
9
|
}
|
|
12
10
|
|
|
13
|
-
const isMissingFileError = error => error.status === 404
|
|
14
|
-
const downloadFileError = error => {
|
|
15
|
-
return isMissingFileError(error)
|
|
16
|
-
? 'Viewer.error.downloadFile.missing'
|
|
17
|
-
: 'Viewer.error.missing'
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* exportFilesNative - Triggers a prompt to download a file on mobile devices
|
|
22
|
-
*
|
|
23
|
-
* @param {CozyClient} client
|
|
24
|
-
* @param {array} files One or more files to download
|
|
25
|
-
* @param {string} filename The name of the file that will be saved
|
|
26
|
-
*/
|
|
27
|
-
export const exportFilesNative = async (client, files, filename) => {
|
|
28
|
-
const downloadAllFiles = files.map(async file => {
|
|
29
|
-
const response = await client
|
|
30
|
-
.collection('io.cozy.files')
|
|
31
|
-
.fetchFileContentById(file.id)
|
|
32
|
-
|
|
33
|
-
const blob = await response.blob()
|
|
34
|
-
const filenameToUse = filename ? filename : file.name
|
|
35
|
-
const localFile = await saveFileWithCordova(blob, filenameToUse)
|
|
36
|
-
return localFile.nativeURL
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
try {
|
|
40
|
-
Alerter.info('Viewer.alert.preparing', {
|
|
41
|
-
duration: Math.min(downloadAllFiles.length * 2000, 6000)
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
const urls = await Promise.all(downloadAllFiles)
|
|
45
|
-
if (urls.length === 1 && isIOS()) {
|
|
46
|
-
// TODO
|
|
47
|
-
// It seems that files: is not well supported on iOS. url seems to work well
|
|
48
|
-
// at with one file. Need to check when severals
|
|
49
|
-
window.plugins.socialsharing.shareWithOptions(
|
|
50
|
-
{
|
|
51
|
-
url: urls[0]
|
|
52
|
-
},
|
|
53
|
-
result => {
|
|
54
|
-
if (result.completed === true) {
|
|
55
|
-
Alerter.success('Viewer.share.success')
|
|
56
|
-
}
|
|
57
|
-
},
|
|
58
|
-
error => {
|
|
59
|
-
throw error
|
|
60
|
-
}
|
|
61
|
-
)
|
|
62
|
-
} else {
|
|
63
|
-
window.plugins.socialsharing.shareWithOptions(
|
|
64
|
-
{
|
|
65
|
-
files: urls
|
|
66
|
-
},
|
|
67
|
-
null,
|
|
68
|
-
error => {
|
|
69
|
-
throw error
|
|
70
|
-
}
|
|
71
|
-
)
|
|
72
|
-
}
|
|
73
|
-
} catch (error) {
|
|
74
|
-
Alerter.error(downloadFileError(error))
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
11
|
export const mapToAllChildren = (children, cb) => {
|
|
79
12
|
return Children.map(children, child => {
|
|
80
13
|
if (!isValidElement(child)) return child
|