Spaces:
Runtime error
Runtime error
Create src/components/tw-security-manager-modal/download.jsx
Browse files
src/components/tw-security-manager-modal/download.jsx
ADDED
@@ -0,0 +1,125 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import React from 'react';
|
2 |
+
import PropTypes from 'prop-types';
|
3 |
+
import { FormattedMessage } from 'react-intl';
|
4 |
+
import { APP_NAME } from '../../lib/brand.js';
|
5 |
+
import styles from './download.css';
|
6 |
+
import usbStyles from './load-extension.css';
|
7 |
+
import FancyCheckbox from '../tw-fancy-checkbox/checkbox.jsx';
|
8 |
+
import { DEFINITELY_EXECUTABLE, isDefinitelyExecutable } from '../../lib/pm-security-manager-download-util.js';
|
9 |
+
|
10 |
+
const FileName = props => {
|
11 |
+
const MAX_NAME_LENGTH = 80;
|
12 |
+
const MAX_EXTENSION_LENGTH = 30;
|
13 |
+
|
14 |
+
const parts = props.name.split('.');
|
15 |
+
let extension = parts.length > 1 ? parts.pop() : null;
|
16 |
+
let name = parts.join('.');
|
17 |
+
|
18 |
+
if (name.length > MAX_NAME_LENGTH) {
|
19 |
+
name = `${name.substring(0, MAX_NAME_LENGTH)}[...]`;
|
20 |
+
}
|
21 |
+
if (extension && extension.length > MAX_EXTENSION_LENGTH) {
|
22 |
+
extension = `[...]${extension.substring(extension.length - MAX_EXTENSION_LENGTH)}`;
|
23 |
+
}
|
24 |
+
|
25 |
+
if (extension === null) {
|
26 |
+
return (
|
27 |
+
<span className={styles.fileName}>
|
28 |
+
{props.name}
|
29 |
+
</span>
|
30 |
+
);
|
31 |
+
}
|
32 |
+
|
33 |
+
return (
|
34 |
+
<span className={styles.fileName}>
|
35 |
+
<span className={styles.name}>
|
36 |
+
{name}
|
37 |
+
</span>
|
38 |
+
<span className={styles.dot}>
|
39 |
+
{'.'}
|
40 |
+
</span>
|
41 |
+
<span className={styles.extension}>
|
42 |
+
{extension}
|
43 |
+
</span>
|
44 |
+
</span>
|
45 |
+
);
|
46 |
+
};
|
47 |
+
|
48 |
+
FileName.propTypes = {
|
49 |
+
name: PropTypes.string.isRequired
|
50 |
+
};
|
51 |
+
|
52 |
+
const DownloadModal = props => (
|
53 |
+
<div>
|
54 |
+
<p>
|
55 |
+
<FormattedMessage
|
56 |
+
// eslint-disable-next-line max-len
|
57 |
+
defaultMessage="The project wants to download a file to your computer. It will be saved as {name} in your downloads folder."
|
58 |
+
description="Part of modal when a project attempts to save a file to someone's downloads folder"
|
59 |
+
id="tw.download.file"
|
60 |
+
values={{
|
61 |
+
name: (
|
62 |
+
<FileName name={props.name} />
|
63 |
+
)
|
64 |
+
}}
|
65 |
+
/>
|
66 |
+
</p>
|
67 |
+
|
68 |
+
<p>
|
69 |
+
<FormattedMessage
|
70 |
+
// eslint-disable-next-line max-len
|
71 |
+
defaultMessage="This file has not been reviewed by the {APP_NAME} developers."
|
72 |
+
description="Part of modal when a project attempts to save a file to someone's downloads folder."
|
73 |
+
id="tw.download.danger"
|
74 |
+
values={{
|
75 |
+
APP_NAME
|
76 |
+
}}
|
77 |
+
/>
|
78 |
+
</p>
|
79 |
+
|
80 |
+
{isDefinitelyExecutable(props.name) && (
|
81 |
+
<div className={usbStyles.unsandboxedWarning}>
|
82 |
+
<FormattedMessage
|
83 |
+
// eslint-disable-next-line max-len
|
84 |
+
defaultMessage="This is an executable file format that may contain malicious code if you run it."
|
85 |
+
description="Part of modal when a project attempts to save a file to someone's downloads folder."
|
86 |
+
id="tw.download.executable"
|
87 |
+
values={{
|
88 |
+
APP_NAME
|
89 |
+
}}
|
90 |
+
/>
|
91 |
+
</div>
|
92 |
+
)}
|
93 |
+
|
94 |
+
<label className={usbStyles.unsandboxedContainer}>
|
95 |
+
<FancyCheckbox
|
96 |
+
className={usbStyles.unsandboxedCheckbox}
|
97 |
+
checked={props.remember}
|
98 |
+
onChange={props.onChangeRemember}
|
99 |
+
/>
|
100 |
+
<FormattedMessage
|
101 |
+
defaultMessage="Remember my choice for all files"
|
102 |
+
description="Message that allows the user to allow or deny downloading any file in the future"
|
103 |
+
id="pm.download.downloadFuture"
|
104 |
+
/>
|
105 |
+
</label>
|
106 |
+
{props.remember && (
|
107 |
+
<div className={usbStyles.unsandboxedWarning}>
|
108 |
+
<FormattedMessage
|
109 |
+
// eslint-disable-next-line max-len
|
110 |
+
defaultMessage="Downloaded files can contain viruses, malware or other malicious content. It is possible to permanently destroy your computer or personal files if you download a virus or malicious program. You will not be asked to confirm any other download with this setting enabled."
|
111 |
+
description="Part of modal asking to allow downloading any file in the future, warning that it is unsafe"
|
112 |
+
id="pm.download.downloadFutureWarning"
|
113 |
+
/>
|
114 |
+
</div>
|
115 |
+
)}
|
116 |
+
</div>
|
117 |
+
);
|
118 |
+
|
119 |
+
DownloadModal.propTypes = {
|
120 |
+
name: PropTypes.string.isRequired,
|
121 |
+
remember: PropTypes.bool.isRequired,
|
122 |
+
onChangeRemember: PropTypes.func
|
123 |
+
};
|
124 |
+
|
125 |
+
export default DownloadModal;
|