MOBILE-4373 core: Support pages, numbers and key file extensions

main
Dani Palou 2023-07-28 15:03:02 +02:00
parent 5d1ec85bdd
commit 58492bb08c
6 changed files with 48 additions and 4 deletions

View File

@ -1404,6 +1404,9 @@
"assets.mimetypes.application/json": "mimetypes", "assets.mimetypes.application/json": "mimetypes",
"assets.mimetypes.application/msword": "mimetypes", "assets.mimetypes.application/msword": "mimetypes",
"assets.mimetypes.application/pdf": "mimetypes", "assets.mimetypes.application/pdf": "mimetypes",
"assets.mimetypes.application/vnd.apple.keynote": "local_moodlemobileapp",
"assets.mimetypes.application/vnd.apple.numbers": "local_moodlemobileapp",
"assets.mimetypes.application/vnd.apple.pages": "local_moodlemobileapp",
"assets.mimetypes.application/vnd.google-apps.audio": "local_moodlemobileapp", "assets.mimetypes.application/vnd.google-apps.audio": "local_moodlemobileapp",
"assets.mimetypes.application/vnd.google-apps.document": "local_moodlemobileapp", "assets.mimetypes.application/vnd.google-apps.document": "local_moodlemobileapp",
"assets.mimetypes.application/vnd.google-apps.drawing": "local_moodlemobileapp", "assets.mimetypes.application/vnd.google-apps.drawing": "local_moodlemobileapp",
@ -1587,9 +1590,9 @@
"core.course.errordownloadingsection": "local_moodlemobileapp", "core.course.errordownloadingsection": "local_moodlemobileapp",
"core.course.errorgetmodule": "local_moodlemobileapp", "core.course.errorgetmodule": "local_moodlemobileapp",
"core.course.failed": "completion", "core.course.failed": "completion",
"core.course.guestaccess": "enrol_guest/pluginname",
"core.course.guestaccess_passwordinvalid": "enrol_guest/passwordinvalid", "core.course.guestaccess_passwordinvalid": "enrol_guest/passwordinvalid",
"core.course.guestaccess_withpassword": "enrol_guest", "core.course.guestaccess_withpassword": "enrol_guest",
"core.course.guestaccess": "enrol_guest/pluginname",
"core.course.hiddenfromstudents": "moodle", "core.course.hiddenfromstudents": "moodle",
"core.course.hiddenoncoursepage": "moodle", "core.course.hiddenoncoursepage": "moodle",
"core.course.highlighted": "moodle", "core.course.highlighted": "moodle",

View File

@ -471,7 +471,7 @@
"jut": {"type":"image/jutvision"}, "jut": {"type":"image/jutvision"},
"kar": {"type":"audio/midi"}, "kar": {"type":"audio/midi"},
"karbon": {"type":"application/vnd.kde.karbon"}, "karbon": {"type":"application/vnd.kde.karbon"},
"key": {"type":"application/pkcs8"}, "key": {"type":"application/vnd.apple.keynote","icon":"powerpoint","groups":["presentation"],"deprecated":"application/x-iwork-keynote-sffkey"},
"kfo": {"type":"application/vnd.kde.kformula"}, "kfo": {"type":"application/vnd.kde.kformula"},
"kia": {"type":"application/vnd.kidspiration"}, "kia": {"type":"application/vnd.kidspiration"},
"kml": {"type":"application/vnd.google-earth.kml+xml"}, "kml": {"type":"application/vnd.google-earth.kml+xml"},
@ -670,6 +670,7 @@
"nsc": {"type":"application/x-conference"}, "nsc": {"type":"application/x-conference"},
"nsf": {"type":"application/vnd.lotus-notes"}, "nsf": {"type":"application/vnd.lotus-notes"},
"ntf": {"type":"application/vnd.nitf"}, "ntf": {"type":"application/vnd.nitf"},
"numbers": {"type":"application/vnd.apple.numbers","icon":"spreadsheet","groups":["spreadsheet"],"deprecated":"application/x-iwork-numbers-sffnumbers"},
"nvd": {"type":"application/x-navidoc"}, "nvd": {"type":"application/x-navidoc"},
"nzb": {"type":"application/x-nzb"}, "nzb": {"type":"application/x-nzb"},
"o": {"type":"application/octet-stream"}, "o": {"type":"application/octet-stream"},
@ -727,6 +728,7 @@
"p7r": {"type":"application/x-pkcs7-certreqresp"}, "p7r": {"type":"application/x-pkcs7-certreqresp"},
"p7s": {"type":"application/pkcs7-signature"}, "p7s": {"type":"application/pkcs7-signature"},
"p8": {"type":"application/pkcs8"}, "p8": {"type":"application/pkcs8"},
"pages": {"type":"application/vnd.apple.pages","icon":"document","groups":["document"],"deprecated":"application/x-iwork-pages-sffpages"},
"part": {"type":"application/pro_eng"}, "part": {"type":"application/pro_eng"},
"pas": {"type":"text/x-pascal"}, "pas": {"type":"text/x-pascal"},
"paw": {"type":"application/vnd.pawaafile"}, "paw": {"type":"application/vnd.pawaafile"},

View File

@ -192,7 +192,10 @@
"application/vnd.anser-web-funds-transfer-initiation": ["fti"], "application/vnd.anser-web-funds-transfer-initiation": ["fti"],
"application/vnd.antix.game-component": ["atx"], "application/vnd.antix.game-component": ["atx"],
"application/vnd.apple.installer+xml": ["mpkg"], "application/vnd.apple.installer+xml": ["mpkg"],
"application/vnd.apple.keynote": ["key"],
"application/vnd.apple.mpegurl": ["m3u8"], "application/vnd.apple.mpegurl": ["m3u8"],
"application/vnd.apple.numbers": ["numbers"],
"application/vnd.apple.pages": ["pages"],
"application/vnd.aristanetworks.swi": ["swi"], "application/vnd.aristanetworks.swi": ["swi"],
"application/vnd.astraea-software.iota": ["iota"], "application/vnd.astraea-software.iota": ["iota"],
"application/vnd.audiograph": ["aep"], "application/vnd.audiograph": ["aep"],
@ -626,6 +629,9 @@
"application/x-inventor": ["iv"], "application/x-inventor": ["iv"],
"application/x-ip2": ["ip"], "application/x-ip2": ["ip"],
"application/x-iso9660-image": ["iso"], "application/x-iso9660-image": ["iso"],
"application/x-iwork-keynote-sffkey": ["key"],
"application/x-iwork-numbers-sffnumbers": ["numbers"],
"application/x-iwork-pages-sffpages": ["pages"],
"application/x-java-class": ["class"], "application/x-java-class": ["class"],
"application/x-java-commerce": ["jcm"], "application/x-java-commerce": ["jcm"],
"application/x-java-jnlp-file": ["jnlp"], "application/x-java-jnlp-file": ["jnlp"],

View File

@ -4,6 +4,9 @@
"application/json": "{{$a.MIMETYPE2}} text", "application/json": "{{$a.MIMETYPE2}} text",
"application/msword": "Word document", "application/msword": "Word document",
"application/pdf": "PDF document", "application/pdf": "PDF document",
"application/vnd.apple.keynote": "Apple Keynote presentation",
"application/vnd.apple.numbers": "Apple Numbers spreadsheet",
"application/vnd.apple.pages": "Apple Pages document",
"application/vnd.google-apps.audio": "Google Drive audio", "application/vnd.google-apps.audio": "Google Drive audio",
"application/vnd.google-apps.document": "Google Docs", "application/vnd.google-apps.document": "Google Docs",
"application/vnd.google-apps.drawing": "Google Drawing", "application/vnd.google-apps.drawing": "Google Drawing",

View File

@ -31,9 +31,9 @@ interface MimeTypeInfo {
type: string; type: string;
icon?: string; icon?: string;
groups?: string[]; groups?: string[];
// eslint-disable-next-line id-blacklist // eslint-disable-next-line id-blacklist
string?: string; string?: string;
deprecated?: string; // Deprecated mimetype name.
} }
interface MimeTypeGroupInfo { interface MimeTypeGroupInfo {
@ -394,6 +394,18 @@ export class CoreMimetypeUtilsProvider {
} }
} }
/**
* Get the deprecated mimetype of an extension. Returns undefined if not found or no deprecated mimetype.
*
* @param extension Extension.
* @returns Deprecated mimetype.
*/
getDeprecatedMimeType(extension: string): string | undefined {
extension = this.cleanExtension(extension);
return this.extToMime[extension]?.deprecated;
}
/** /**
* Obtains descriptions for file types (e.g. 'Microsoft Word document') from the language file. * Obtains descriptions for file types (e.g. 'Microsoft Word document') from the language file.
* Based on Moodle's get_mimetype_description. * Based on Moodle's get_mimetype_description.

View File

@ -1033,12 +1033,30 @@ export class CoreUtilsProvider {
// Error, use the original path. // Error, use the original path.
} }
try { const openFile = async (mimetype?: string) => {
if (this.shouldOpenWithDialog(options)) { if (this.shouldOpenWithDialog(options)) {
await FileOpener.showOpenWithDialog(path, mimetype || ''); await FileOpener.showOpenWithDialog(path, mimetype || '');
} else { } else {
await FileOpener.open(path, mimetype || ''); await FileOpener.open(path, mimetype || '');
} }
};
try {
try {
await openFile(mimetype);
} catch (error) {
if (!extension || !error || Number(error.status) !== 9) {
throw error;
}
// Cannot open mimetype. Check if there is a deprecated mimetype for the extension.
const deprecatedMimetype = CoreMimetypeUtils.getDeprecatedMimeType(extension);
if (!deprecatedMimetype || deprecatedMimetype === mimetype) {
throw error;
}
await openFile(deprecatedMimetype);
}
} catch (error) { } catch (error) {
this.logger.error('Error opening file ' + path + ' with mimetype ' + mimetype); this.logger.error('Error opening file ' + path + ' with mimetype ' + mimetype);
this.logger.error('Error: ', JSON.stringify(error)); this.logger.error('Error: ', JSON.stringify(error));