|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * @copyright Copyright (c) 2023 John Molakvoæ <skjnldsv@protonmail.com> |
| 4 | + * |
| 5 | + * @author John Molakvoæ <skjnldsv@protonmail.com> |
| 6 | + * |
| 7 | + * @license AGPL-3.0-or-later |
| 8 | + * |
| 9 | + * This code is free software: you can redistribute it and/or modify |
| 10 | + * it under the terms of the GNU Affero General Public License, version 3, |
| 11 | + * as published by the Free Software Foundation. |
| 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, version 3, |
| 19 | + * along with this program. If not, see <http://www.gnu.org/licenses/> |
| 20 | + * |
| 21 | + */ |
| 22 | +namespace OC\Preview; |
| 23 | + |
| 24 | +use OCP\Files\IMimeTypeDetector; |
| 25 | +use OCP\Preview\IMimeIconProvider; |
| 26 | + |
| 27 | +class MimeIconProvider implements IMimeIconProvider { |
| 28 | + |
| 29 | + public function __construct( |
| 30 | + protected IMimeTypeDetector $mimetypeDetector, |
| 31 | + ) {} |
| 32 | + |
| 33 | + public function getMimeIconUrl(string $mime): string|null { |
| 34 | + if (!$mime) { |
| 35 | + return null; |
| 36 | + } |
| 37 | + |
| 38 | + // Fetch all the aliases |
| 39 | + $aliases = $this->mimetypeDetector->getAllAliases(); |
| 40 | + |
| 41 | + // Remove comments |
| 42 | + $aliases = array_filter($aliases, static function ($key) { |
| 43 | + return !($key === '' || $key[0] === '_'); |
| 44 | + }, ARRAY_FILTER_USE_KEY); |
| 45 | + |
| 46 | + // Map all the aliases recursively |
| 47 | + foreach ($aliases as $alias) { |
| 48 | + if ($alias === $mime) { |
| 49 | + $mime = $alias; |
| 50 | + } |
| 51 | + } |
| 52 | + } |
| 53 | +} |
0 commit comments