1 import { c } from 'ttag';
3 import { DOCS_APP_NAME } from '@proton/shared/lib/constants';
4 import { LinkURLType, SupportedMimeTypes } from '@proton/shared/lib/drive/constants';
5 import isTruthy from '@proton/utils/isTruthy';
7 import type { DecryptedLink } from '../../store';
8 import type { SharedWithMeItem } from './SharedWithMe/SharedWithMe';
10 export const selectMessageForItemList = (
18 const allFiles = isFiles.every((isFile) => isFile);
19 const allFolders = isFiles.every((isFile) => !isFile);
20 const message = (allFiles && messages.allFiles) || (allFolders && messages.allFolders) || messages.mixed;
25 export const toLinkURLType = (isFile: boolean) => {
26 return isFile ? LinkURLType.FILE : LinkURLType.FOLDER;
29 export const getLocalizedDescription = (mimeType: string): string | undefined => {
31 case 'application/vnd.proton.doc':
34 // Compressed archives
35 case 'application/java-archive':
36 return c('Mimetype').t`Java Archive (JAR)`;
37 case 'application/x-bzip':
38 return c('Mimetype').t`BZip archive`;
39 case SupportedMimeTypes.bzip2:
40 return c('Mimetype').t`BZip2 archive`;
41 case 'application/x-freearc':
42 return c('Mimetype').t`Archive document`;
43 case SupportedMimeTypes.gzip:
44 return c('Mimetype').t`GZip Archive`;
45 case SupportedMimeTypes.rar:
46 return c('Mimetype').t`RAR archive`;
47 case SupportedMimeTypes.zip:
48 return c('Mimetype').t`ZIP archive`;
49 case SupportedMimeTypes.tar:
50 return c('Mimetype').t`Tape Archive (TAR)`;
51 case SupportedMimeTypes.x7zip:
52 return c('Mimetype').t`7-zip archive`;
56 return c('Mimetype').t`Text`;
57 case 'application/javascript':
58 case 'text/javascript':
59 return c('Mimetype').t`JavaScript`;
60 case 'application/typescript':
61 return c('Mimetype').t`TypeScript`;
62 case 'application/json':
63 return c('Mimetype').t`JSON`;
64 case 'application/ld+json':
65 return c('Mimetype').t`JSON-LD`;
66 case 'application/vnd.mozilla.xul+xml':
67 return c('Mimetype').t`XUL`;
68 case 'application/x-csh':
70 return c('Mimetype').t`C-Shell script`;
71 case 'application/x-sh':
72 return c('Mimetype').t`Bourne shell script`;
73 case 'application/x-httpd-php':
74 return c('Mimetype').t`Hypertext Preprocessor (Personal Home Page)`;
75 case 'application/xhtml+xml':
76 return c('Mimetype').t`XHTML`;
77 case 'application/xml':
78 case SupportedMimeTypes.xml:
79 return c('Mimetype').t`XML`;
81 return c('Mimetype').t`Cascading Style Sheets (CSS)`;
83 return c('Mimetype').t`Comma-separated values (CSV)`;
85 return c('Mimetype').t`HyperText Markup Language (HTML)`;
87 return c('Mimetype').t`Python`;
90 case SupportedMimeTypes.docx:
91 return c('Mimetype').t`Microsoft Word (OpenXML)`;
92 case 'application/msword':
93 return c('Mimetype').t`Microsoft Word`;
94 case SupportedMimeTypes.xlsx:
95 return c('Mimetype').t`Microsoft Excel (OpenXML)`;
96 case 'application/vnd.ms-excel':
97 return c('Mimetype').t`Microsoft Excel`;
98 case SupportedMimeTypes.pptx:
99 return c('Mimetype').t`Microsoft PowerPoint (OpenXML)`;
100 case 'application/vnd.ms-powerpoint':
101 return c('Mimetype').t`Microsoft PowerPoint`;
102 case 'application/vnd.visio':
103 return c('Mimetype').t`Microsoft Visio`;
104 case 'application/x-abiword':
105 return c('Mimetype').t`AbiWord document`;
106 case 'application/vnd.amazon.ebook':
107 return c('Mimetype').t`Amazon Kindle eBook format`;
108 case SupportedMimeTypes.epub:
109 return c('Mimetype').t`Electronic publication (EPUB)`;
110 case SupportedMimeTypes.keynote:
111 return c('Mimetype').t`Apple Keynote`;
112 case SupportedMimeTypes.numbers:
113 return c('Mimetype').t`Apple Numbers`;
114 case SupportedMimeTypes.odp:
115 return c('Mimetype').t`OpenDocument presentation document`;
116 case SupportedMimeTypes.ods:
117 return c('Mimetype').t`OpenDocument spreadsheet document`;
118 case SupportedMimeTypes.odt:
119 return c('Mimetype').t`OpenDocument text document`;
120 case SupportedMimeTypes.pages:
121 return c('Mimetype').t`Apple Pages`;
122 case SupportedMimeTypes.pdf:
123 case 'application/x-pdf':
124 return c('Mimetype').t`Adobe Portable Document Format (PDF)`;
125 case SupportedMimeTypes.rtf:
126 return c('Mimetype').t`Rich Text Format (RTF)`;
129 case 'application/octet-stream':
130 return c('Mimetype').t`Binary data`;
131 case 'application/vnd.apple.installer+xml':
132 return c('Mimetype').t`Apple Installer Package`;
133 case SupportedMimeTypes.apk:
134 return c('Mimetype').t`Android Package`;
138 return c('Mimetype').t`3GPP audio/video container`;
140 return c('Mimetype').t`3GPP2 audio/video container`;
142 return c('Mimetype').t`WEBM audio`;
144 case SupportedMimeTypes.midi:
145 return c('Mimetype').t`Musical Instrument Digital Interface (MIDI)`;
146 case SupportedMimeTypes.vdnMicrosoftIcon:
147 return c('Mimetype').t`Icon format`;
149 return c('Mimetype').t`WEBM video`;
150 case SupportedMimeTypes.aac:
151 return c('Mimetype').t`AAC audio`;
152 case SupportedMimeTypes.apng:
153 return c('Mimetype').t`Animated Portable Network Graphics`;
154 case SupportedMimeTypes.avi:
155 return c('Mimetype').t`AVI video`;
156 case SupportedMimeTypes.bmp:
157 return c('Mimetype').t`Windows OS/2 Bitmap Graphics`;
158 case SupportedMimeTypes.flv:
159 return c('Mimetype').t`Flash Video`;
160 case SupportedMimeTypes.gif:
161 return c('Mimetype').t`Graphics Interchange Format (GIF)`;
162 case SupportedMimeTypes.ico:
163 return c('Mimetype').t`Icon format`;
164 case SupportedMimeTypes.jpg:
165 return c('Mimetype').t`JPEG image`;
166 case SupportedMimeTypes.mp2t:
167 return c('Mimetype').t`MPEG transport stream`;
168 case SupportedMimeTypes.mpeg:
169 return c('Mimetype').t`MP3 audio`;
170 case SupportedMimeTypes.mpg:
171 return c('Mimetype').t`MPEG Video`;
172 case SupportedMimeTypes.oga:
173 return c('Mimetype').t`OGG audio`;
174 case SupportedMimeTypes.ogg:
175 return c('Mimetype').t`OGG`;
176 case SupportedMimeTypes.ogv:
177 return c('Mimetype').t`OGG video`;
178 case SupportedMimeTypes.opus:
179 return c('Mimetype').t`Opus audio`;
180 case SupportedMimeTypes.png:
181 return c('Mimetype').t`Portable Network Graphics (PNG)`;
182 case SupportedMimeTypes.svg:
183 return c('Mimetype').t`Scalable Vector Graphics (SVG)`;
184 case SupportedMimeTypes.tiff:
185 return c('Mimetype').t`Tagged Image File Format (TIFF)`;
186 case SupportedMimeTypes.v3g2:
187 return c('Mimetype').t`3GPP2 audio/video container`;
188 case SupportedMimeTypes.v3gp:
189 return c('Mimetype').t`3GPP audio/video container`;
190 case SupportedMimeTypes.wav:
191 return c('Mimetype').t`Waveform Audio Format`;
192 case SupportedMimeTypes.webp:
193 return c('Mimetype').t`WEBP image`;
194 case SupportedMimeTypes.avif:
195 return c('Mimetype').t`AV1 Image File Format (AVIF)`;
198 case 'text/calendar':
199 return c('Mimetype').t`iCalendar format`;
200 case SupportedMimeTypes.eot:
201 return c('Mimetype').t`MS Embedded OpenType fonts`;
202 case SupportedMimeTypes.otf:
203 return c('Mimetype').t`OpenType font`;
204 case SupportedMimeTypes.woff:
205 return c('Mimetype').t`Web Open Font Format (WOFF)`;
206 case SupportedMimeTypes.woff2:
207 return c('Mimetype').t`Web Open Font Format (WOFF)`;
208 case SupportedMimeTypes.ttf:
209 return c('Mimetype').t`TrueType Font`;
210 case SupportedMimeTypes.swf:
211 return c('Mimetype').t`Small web format (SWF)`;
215 export const getMimeTypeDescription = (mimeType: string) => {
216 const description = getLocalizedDescription(mimeType);
221 if (mimeType.startsWith('audio/')) {
222 return c('Mimetype').t`Audio file`;
224 if (mimeType.startsWith('video/')) {
225 return c('Mimetype').t`Video file`;
227 if (mimeType.startsWith('text/')) {
228 return c('Mimetype').t`Text`;
230 if (mimeType.startsWith('image/')) {
231 return c('Mimetype').t`Image`;
234 return c('Mimetype').t`Unknown file`;
237 export const getSelectedItems = (
238 items: DecryptedLink[],
239 selectedItemIds: string[],
240 key: 'linkId' | 'rootShareId' = 'linkId'
241 ): DecryptedLink[] => {
243 return selectedItemIds
244 .map((selectedItemId) => items.find(({ isLocked, ...item }) => !isLocked && selectedItemId === item[key]))
245 .filter(isTruthy) as DecryptedLink[];
251 export const getSelectedSharedWithMeItems = (
252 items: SharedWithMeItem[],
253 selectedItemIds: string[]
254 ): SharedWithMeItem[] => {
256 return selectedItemIds
257 .map((selectedItemId) =>
258 items.find(({ isLocked, ...item }) => !isLocked && selectedItemId === item.rootShareId)
260 .filter(isTruthy) as SharedWithMeItem[];