Skip to content

Commit 38cb36d

Browse files
authored
Merge pull request #619 from nextcloud/fix/oc-MimeType-getIconUrl
fix: show mime type icon for attachments in messages
2 parents 3705fda + 4e14804 commit 38cb36d

File tree

2 files changed

+187
-3
lines changed

2 files changed

+187
-3
lines changed

src/shared/globals/OC/mimetype.js

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
/*
2+
* @copyright Copyright (c) 2024 Grigorii Shartsev <[email protected]>
3+
*
4+
* @author Grigorii Shartsev <[email protected]>
5+
*
6+
* @license AGPL-3.0-or-later
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU Affero General Public License as
10+
* published by the Free Software Foundation, either version 3 of the
11+
* License, or (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU Affero General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Affero General Public License
19+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20+
*/
21+
22+
// Source: https://github.com/nextcloud/server/blob/master/tests/data/integritycheck/mimetypeListModified/core/js/mimetypelist.js
23+
export const MimeTypeList = {
24+
aliases: {
25+
'application/coreldraw': 'image',
26+
'application/epub+zip': 'text',
27+
'application/font-sfnt': 'font',
28+
'application/font-woff': 'font',
29+
'application/gpx+xml': 'location',
30+
'application/gzip': 'package/x-generic',
31+
'application/illustrator': 'image',
32+
'application/javascript': 'text/code',
33+
'application/json': 'text/code',
34+
'application/msaccess': 'file',
35+
'application/msexcel': 'x-office/spreadsheet',
36+
'application/msonenote': 'x-office/document',
37+
'application/mspowerpoint': 'x-office/presentation',
38+
'application/msword': 'x-office/document',
39+
'application/octet-stream': 'file',
40+
'application/postscript': 'image',
41+
'application/rss+xml': 'application/xml',
42+
'application/vnd.android.package-archive': 'package/x-generic',
43+
'application/vnd.lotus-wordpro': 'x-office/document',
44+
'application/vnd.garmin.tcx+xml': 'location',
45+
'application/vnd.google-earth.kml+xml': 'location',
46+
'application/vnd.google-earth.kmz': 'location',
47+
'application/vnd.ms-excel': 'x-office/spreadsheet',
48+
'application/vnd.ms-excel.addin.macroEnabled.12': 'x-office/spreadsheet',
49+
'application/vnd.ms-excel.sheet.binary.macroEnabled.12': 'x-office/spreadsheet',
50+
'application/vnd.ms-excel.sheet.macroEnabled.12': 'x-office/spreadsheet',
51+
'application/vnd.ms-excel.template.macroEnabled.12': 'x-office/spreadsheet',
52+
'application/vnd.ms-fontobject': 'font',
53+
'application/vnd.ms-powerpoint': 'x-office/presentation',
54+
'application/vnd.ms-powerpoint.addin.macroEnabled.12': 'x-office/presentation',
55+
'application/vnd.ms-powerpoint.presentation.macroEnabled.12': 'x-office/presentation',
56+
'application/vnd.ms-powerpoint.slideshow.macroEnabled.12': 'x-office/presentation',
57+
'application/vnd.ms-powerpoint.template.macroEnabled.12': 'x-office/presentation',
58+
'application/vnd.ms-visio.drawing.macroEnabled.12': 'application/vnd.visio',
59+
'application/vnd.ms-visio.drawing': 'application/vnd.visio',
60+
'application/vnd.ms-visio.stencil.macroEnabled.12': 'application/vnd.visio',
61+
'application/vnd.ms-visio.stencil': 'application/vnd.visio',
62+
'application/vnd.ms-visio.template.macroEnabled.12': 'application/vnd.visio',
63+
'application/vnd.ms-visio.template': 'application/vnd.visio',
64+
'application/vnd.ms-word.document.macroEnabled.12': 'x-office/document',
65+
'application/vnd.ms-word.template.macroEnabled.12': 'x-office/document',
66+
'application/vnd.oasis.opendocument.presentation': 'x-office/presentation',
67+
'application/vnd.oasis.opendocument.presentation-template': 'x-office/presentation',
68+
'application/vnd.oasis.opendocument.spreadsheet': 'x-office/spreadsheet',
69+
'application/vnd.oasis.opendocument.spreadsheet-template': 'x-office/spreadsheet',
70+
'application/vnd.oasis.opendocument.text': 'x-office/document',
71+
'application/vnd.oasis.opendocument.text-master': 'x-office/document',
72+
'application/vnd.oasis.opendocument.text-template': 'x-office/document',
73+
'application/vnd.oasis.opendocument.graphics': 'x-office/drawing',
74+
'application/vnd.oasis.opendocument.graphics-template': 'x-office/drawing',
75+
'application/vnd.oasis.opendocument.text-web': 'x-office/document',
76+
'application/vnd.oasis.opendocument.text-flat-xml': 'x-office/document',
77+
'application/vnd.oasis.opendocument.spreadsheet-flat-xml': 'x-office/spreadsheet',
78+
'application/vnd.oasis.opendocument.graphics-flat-xml': 'x-office/drawing',
79+
'application/vnd.oasis.opendocument.presentation-flat-xml': 'x-office/presentation',
80+
'application/vnd.openxmlformats-officedocument.presentationml.presentation': 'x-office/presentation',
81+
'application/vnd.openxmlformats-officedocument.presentationml.slideshow': 'x-office/presentation',
82+
'application/vnd.openxmlformats-officedocument.presentationml.template': 'x-office/presentation',
83+
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': 'x-office/spreadsheet',
84+
'application/vnd.openxmlformats-officedocument.spreadsheetml.template': 'x-office/spreadsheet',
85+
'application/vnd.openxmlformats-officedocument.wordprocessingml.document': 'x-office/document',
86+
'application/vnd.openxmlformats-officedocument.wordprocessingml.template': 'x-office/document',
87+
'application/vnd.visio': 'x-office/document',
88+
'application/vnd.wordperfect': 'x-office/document',
89+
'application/x-7z-compressed': 'package/x-generic',
90+
'application/x-bzip2': 'package/x-generic',
91+
'application/x-cbr': 'text',
92+
'application/x-compressed': 'package/x-generic',
93+
'application/x-dcraw': 'image',
94+
'application/x-deb': 'package/x-generic',
95+
'application/x-fictionbook+xml': 'text',
96+
'application/x-font': 'font',
97+
'application/x-gimp': 'image',
98+
'application/x-gzip': 'application/gzip',
99+
'application/x-iwork-keynote-sffkey': 'x-office/presentation',
100+
'application/x-iwork-numbers-sffnumbers': 'x-office/spreadsheet',
101+
'application/x-iwork-pages-sffpages': 'x-office/document',
102+
'application/x-mobipocket-ebook': 'text',
103+
'application/x-perl': 'text/code',
104+
'application/x-photoshop': 'image',
105+
'application/x-php': 'text/code',
106+
'application/x-rar-compressed': 'package/x-generic',
107+
'application/x-tar': 'package/x-generic',
108+
'application/x-tex': 'text',
109+
'application/xml': 'text/html',
110+
'application/yaml': 'text/code',
111+
'application/zip': 'package/x-generic',
112+
database: 'file',
113+
'httpd/unix-directory': 'dir',
114+
'text/css': 'text/code',
115+
'text/csv': 'x-office/spreadsheet',
116+
'text/html': 'text/code',
117+
'text/x-c': 'text/code',
118+
'text/x-c++src': 'text/code',
119+
'text/x-h': 'text/code',
120+
'text/x-java-source': 'text/code',
121+
'text/x-ldif': 'text/code',
122+
'text/x-python': 'text/code',
123+
'text/x-rst': 'text',
124+
'text/x-shellscript': 'text/code',
125+
web: 'text/code',
126+
'application/internet-shortcut': 'link',
127+
'application/km': 'mindmap',
128+
'application/x-freemind': 'mindmap',
129+
'application/vnd.xmind.workbook': 'mindmap',
130+
'image/targa': 'image/tga',
131+
'application/vnd.openxmlformats-officedocument.wordprocessingml.document.oform': 'x-office/form',
132+
'application/vnd.openxmlformats-officedocument.wordprocessingml.document.docxf': 'x-office/form-template',
133+
'image/x-emf': 'image/emf',
134+
'my-custom/mimetype': 'custom',
135+
},
136+
files: [
137+
'application',
138+
'application-pdf',
139+
'audio',
140+
'file',
141+
'folder',
142+
'folder-drag-accept',
143+
'folder-encrypted',
144+
'folder-external',
145+
'folder-public',
146+
'folder-shared',
147+
'folder-starred',
148+
'font',
149+
'image',
150+
'link',
151+
'location',
152+
'mindmap',
153+
'package-x-generic',
154+
'text',
155+
'text-calendar',
156+
'text-code',
157+
'text-vcard',
158+
'video',
159+
'x-office-document',
160+
'x-office-drawing',
161+
'x-office-form',
162+
'x-office-form-template',
163+
'x-office-presentation',
164+
'x-office-spreadsheet',
165+
],
166+
themes: [],
167+
}

src/shared/globals/globals.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { translate, translatePlural } from '@nextcloud/l10n'
2424

2525
import { appData } from '../../app/AppData.js'
2626
import { dialogs } from './OC/dialogs.js'
27+
import { MimeTypeList } from './OC/mimetype.js'
2728
import { getDesktopMediaSource } from '../../talk/renderer/getDesktopMediaSource.js'
2829

2930
let enabledAbsoluteWebroot = false
@@ -53,10 +54,26 @@ const OC = {
5354
spreed: '/apps/spreed',
5455
},
5556

56-
// TODO: Add OC.MimeType
57+
MimeTypeList,
5758
MimeType: {
58-
getIconUrl() {
59-
return undefined
59+
// TODO: better to move this function from global to @nextcloud/files or @nextcloud/router
60+
getIconUrl(mimeType) {
61+
if (!mimeType) {
62+
return undefined
63+
}
64+
65+
while (MimeTypeList.aliases[mimeType]) {
66+
mimeType = MimeTypeList.aliases[mimeType]
67+
}
68+
69+
let icon = mimeType.replaceAll('/', '-')
70+
icon = MimeTypeList.files.includes(icon) ? icon : mimeType.split('/')[0]
71+
72+
try {
73+
return require(`../assets/default/img/filetypes/${icon}.svg`)
74+
} catch {
75+
return undefined
76+
}
6077
},
6178
},
6279

0 commit comments

Comments
 (0)