Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 117 additions & 0 deletions LICENSES/GPL-2.0-only.txt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class GenerateMimetypeFileBuilder {
* @param array<string,string> $aliases
* @return string
*/
public function generateFile(array $aliases): string {
public function generateFile(array $aliases, array $names): string {
// Remove comments
$aliases = array_filter($aliases, static function ($key) {
// Single digit extensions will be treated as integers
Expand Down Expand Up @@ -71,6 +71,15 @@ public function generateFile(array $aliases): string {
sort($themes[$theme]);
}

$namesOutput = '';
foreach ($names as $key => $name) {
if (str_starts_with($key, '_')) {
// Skip internal names
continue;
}
$namesOutput .= "'$key': t('core', " . json_encode($name) . "),\n";
}

//Generate the JS
return '/**
* This file is automatically generated
Expand All @@ -83,7 +92,8 @@ public function generateFile(array $aliases): string {
OC.MimeTypeList={
aliases: ' . json_encode($aliases, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . ',
files: ' . json_encode($files, JSON_PRETTY_PRINT) . ',
themes: ' . json_encode($themes, JSON_PRETTY_PRINT) . '
themes: ' . json_encode($themes, JSON_PRETTY_PRINT) . ',
names: {' . $namesOutput . '},
};
';
}
Expand Down
3 changes: 2 additions & 1 deletion core/Command/Maintenance/Mimetype/UpdateJS.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int

// Output the JS
$generatedMimetypeFile = new GenerateMimetypeFileBuilder();
file_put_contents(\OC::$SERVERROOT . '/core/js/mimetypelist.js', $generatedMimetypeFile->generateFile($aliases));
$namings = $this->mimetypeDetector->getAllNamings();
file_put_contents(\OC::$SERVERROOT . '/core/js/mimetypelist.js', $generatedMimetypeFile->generateFile($aliases, $namings));

$output->writeln('<info>mimetypelist.js is updated');
return 0;
Expand Down
109 changes: 107 additions & 2 deletions core/js/mimetypelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ OC.MimeTypeList={
"application/x-7z-compressed": "package/x-generic",
"application/x-bzip2": "package/x-generic",
"application/x-cbr": "text",
"application/x-compressed": "package/x-generic",
"application/x-dcraw": "image",
"application/x-deb": "package/x-generic",
"application/x-fictionbook+xml": "text",
Expand Down Expand Up @@ -115,6 +114,7 @@ OC.MimeTypeList={
"text/x-h": "text/code",
"text/x-java-source": "text/code",
"text/x-ldif": "text/code",
"text/x-nfo": "text/code",
"text/x-python": "text/code",
"text/x-rst": "text",
"text/x-shellscript": "text/code",
Expand Down Expand Up @@ -151,5 +151,110 @@ OC.MimeTypeList={
"x-office-presentation",
"x-office-spreadsheet"
],
themes: []
themes: [],
names: {'application/epub+zip': t('core', "Electronic book document"),
'application/gpx+xml': t('core', "GPX geographic data"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want to group these translations in under core or have it under a separate "app"?

'application/gzip': t('core', "Gzip archive"),
'application/illustrator': t('core', "Adobe Illustrator document"),
'application/json': t('core', "JSON document"),
'application/msword': t('core', "Word document"),
'application/octet-stream': t('core', "Unknown"),
'application/pdf': t('core', "PDF document"),
'application/postscript': t('core', "PostScript document"),
'application/rss+xml': t('core', "RSS summary"),
'application/vnd.android.package-archive': t('core', "Android package"),
'application/vnd.google-earth.kml+xml': t('core', "KML geographic data"),
'application/vnd.google-earth.kmz': t('core', "KML geographic compressed data"),
'application/vnd.lotus-wordpro': t('core', "Lotus Word Pro document"),
'application/vnd.ms-excel': t('core', "Excel spreadsheet"),
'application/vnd.ms-excel.addin.macroEnabled.12': t('core', "Excel add-in"),
'application/vnd.ms-excel.sheet.binary.macroEnabled.12': t('core', "Excel 2007 binary spreadsheet"),
'application/vnd.ms-excel.sheet.macroEnabled.12': t('core', "Excel spreadsheet"),
'application/vnd.ms-excel.template.macroEnabled.12': t('core', "Excel spreadsheet template"),
'application/vnd.ms-powerpoint': t('core', "PowerPoint presentation"),
'application/vnd.ms-powerpoint.addin.macroEnabled.12': t('core', "PowerPoint add-in"),
'application/vnd.ms-powerpoint.presentation.macroEnabled.12': t('core', "PowerPoint presentation"),
'application/vnd.ms-powerpoint.slideshow.macroEnabled.12': t('core', "PowerPoint presentation"),
'application/vnd.ms-powerpoint.template.macroEnabled.12': t('core', "PowerPoint presentation template"),
'application/vnd.ms-word.document.macroEnabled.12': t('core', "Word document"),
'application/vnd.oasis.opendocument.formula': t('core', "ODF formula"),
'application/vnd.oasis.opendocument.graphics': t('core', "ODG drawing"),
'application/vnd.oasis.opendocument.graphics-flat-xml': t('core', "ODG drawing (Flat XML)"),
'application/vnd.oasis.opendocument.graphics-template': t('core', "ODG template"),
'application/vnd.oasis.opendocument.presentation': t('core', "ODP presentation"),
'application/vnd.oasis.opendocument.presentation-flat-xml': t('core', "ODP presentation (Flat XML)"),
'application/vnd.oasis.opendocument.presentation-template': t('core', "ODP template"),
'application/vnd.oasis.opendocument.spreadsheet': t('core', "ODS spreadsheet"),
'application/vnd.oasis.opendocument.spreadsheet-flat-xml': t('core', "ODS spreadsheet (Flat XML)"),
'application/vnd.oasis.opendocument.spreadsheet-template': t('core', "ODS template"),
'application/vnd.oasis.opendocument.text': t('core', "ODT document"),
'application/vnd.oasis.opendocument.text-flat-xml': t('core', "ODT document (Flat XML)"),
'application/vnd.oasis.opendocument.text-template': t('core', "ODT template"),
'application/vnd.openxmlformats-officedocument.presentationml.presentation': t('core', "PowerPoint 2007 presentation"),
'application/vnd.openxmlformats-officedocument.presentationml.slideshow': t('core', "PowerPoint 2007 show"),
'application/vnd.openxmlformats-officedocument.presentationml.template': t('core', "PowerPoint 2007 presentation template"),
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': t('core', "Excel 2007 spreadsheet"),
'application/vnd.openxmlformats-officedocument.spreadsheetml.template': t('core', "Excel 2007 spreadsheet template"),
'application/vnd.openxmlformats-officedocument.wordprocessingml.document': t('core', "Word 2007 document"),
'application/vnd.openxmlformats-officedocument.wordprocessingml.template': t('core', "Word 2007 document template"),
'application/vnd.visio': t('core', "Microsoft Visio document"),
'application/vnd.wordperfect': t('core', "WordPerfect document"),
'application/x-7z-compressed': t('core', "7-zip archive"),
'application/x-blender': t('core', "Blender scene"),
'application/x-bzip2': t('core', "Bzip2 archive"),
'application/x-fictionbook+xml': t('core', "FictionBook document"),
'application/x-krita': t('core', "Krita document"),
'application/x-mobipocket-ebook': t('core', "Mobipocket e-book"),
'application/x-msi': t('core', "Windows Installer package"),
'application/x-perl': t('core', "Perl script"),
'application/x-php': t('core', "PHP script"),
'application/x-tar': t('core', "Tar archive"),
'application/xml': t('core', "XML document"),
'application/yaml': t('core', "YAML document"),
'application/zip': t('core', "Zip archive"),
'application/zstd': t('core', "Zstandard archive"),
'audio/aac': t('core', "AAC audio"),
'audio/flac': t('core', "FLAC audio"),
'audio/mp4': t('core', "MPEG-4 audio"),
'audio/mpeg': t('core', "MP3 audio"),
'audio/ogg': t('core', "Ogg audio"),
'audio/webm': t('core', "WebM audio"),
'audio/x-scpls': t('core', "MP3 ShoutCast playlist"),
'image/bmp': t('core', "Windows BMP image"),
'image/emf': t('core', "EMF image"),
'image/gif': t('core', "GIF image"),
'image/heif': t('core', "HEIF image"),
'image/jp2': t('core', "JPEG-2000 JP2 image"),
'image/jpeg': t('core', "JPEG image"),
'image/png': t('core', "PNG image"),
'image/svg+xml': t('core', "SVG image"),
'image/tiff': t('core', "TIFF image"),
'image/webp': t('core', "WebP image"),
'image/x-dcraw': t('core', "Digital raw image"),
'message/rfc822': t('core', "Email message"),
'text/calendar': t('core', "VCS\/ICS calendar"),
'text/css': t('core', "CSS stylesheet"),
'text/csv': t('core', "CSV document"),
'text/html': t('core', "HTML document"),
'text/markdown': t('core', "Markdown document"),
'text/org': t('core', "Org-mode file"),
'text/plain': t('core', "Plain text document"),
'text/vcard': t('core', "Electronic business card"),
'text/x-c++src': t('core', "C++ source code"),
'text/x-ldif': t('core', "LDIF address book"),
'text/x-nfo': t('core', "NFO document"),
'text/x-python': t('core', "Python script"),
'text/x-rst': t('core', "ReStructuredText document"),
'video/3gpp': t('core', "3GPP multimedia file"),
'video/dv': t('core', "DV video"),
'video/mp2t': t('core', "MPEG-2 transport stream"),
'video/mp4': t('core', "MPEG-4 video"),
'video/mpeg': t('core', "MPEG video"),
'video/ogg': t('core', "Ogg video"),
'video/quicktime': t('core', "QuickTime video"),
'video/webm': t('core', "WebM video"),
'video/x-flv': t('core', "Flash video"),
'video/x-matroska': t('core', "Matroska video"),
'video/x-ms-wmv': t('core', "Windows Media video"),
},
};
22 changes: 22 additions & 0 deletions lib/private/Files/Type/Detection.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
class Detection implements IMimeTypeDetector {
private const CUSTOM_MIMETYPEMAPPING = 'mimetypemapping.json';
private const CUSTOM_MIMETYPEALIASES = 'mimetypealiases.json';
private const CUSTOM_MIMETYPENAMES = 'mimetypenames.json';

/** @var array<list{string, string|null}> */
protected array $mimeTypes = [];
Expand All @@ -31,6 +32,8 @@ class Detection implements IMimeTypeDetector {
protected array $mimeTypeIcons = [];
/** @var array<string,string> */
protected array $mimeTypeAlias = [];
/** @var array<string,string> */
protected array $mimeTypesNames = [];

public function __construct(
private IURLGenerator $urlGenerator,
Expand Down Expand Up @@ -148,6 +151,25 @@ public function getAllMappings(): array {
return $this->mimeTypes;
}

private function loadNamings(): void {
if (!empty($this->mimeTypesNames)) {
return;
}

$mimeTypeMapping = json_decode(file_get_contents($this->defaultConfigDir . '/mimetypenames.dist.json'), true);
$mimeTypeMapping = $this->loadCustomDefinitions(self::CUSTOM_MIMETYPENAMES, $mimeTypeMapping);

$this->mimeTypesNames = $mimeTypeMapping;
}

/**
* @return array<string,string>
*/
public function getAllNamings(): array {
$this->loadNamings();
return $this->mimeTypesNames;
}

/**
* detect MIME type only based on filename, content of file is not used
*
Expand Down
4 changes: 2 additions & 2 deletions lib/private/IntegrityCheck/Checker.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,10 @@ private function generateHashes(\RecursiveIteratorIterator $iterator,
}
if ($filename === $this->environmentHelper->getServerRoot() . '/core/js/mimetypelist.js') {
$oldMimetypeList = new GenerateMimetypeFileBuilder();
$newFile = $oldMimetypeList->generateFile($this->mimeTypeDetector->getAllAliases());
$newFile = $oldMimetypeList->generateFile($this->mimeTypeDetector->getAllAliases(), $this->mimeTypeDetector->getAllNamings());
$oldFile = $this->fileAccessHelper->file_get_contents($filename);
if ($newFile === $oldFile) {
$hashes[$relativeFileName] = hash('sha512', $oldMimetypeList->generateFile($this->mimeTypeDetector->getOnlyDefaultAliases()));
$hashes[$relativeFileName] = hash('sha512', $oldMimetypeList->generateFile($this->mimeTypeDetector->getOnlyDefaultAliases(), $this->mimeTypeDetector->getAllNamings()));
continue;
}
}
Expand Down
8 changes: 8 additions & 0 deletions lib/public/Files/IMimeTypeDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,12 @@ public function getAllAliases(): array;
* @since 32.0.0
*/
public function getAllMappings(): array;

/**
* Get all human readable mime names
*
* @return array<string,string>
* @since 32.0.0
*/
public function getAllNamings(): array;
}
Loading
Loading