Skip to content

Commit

Permalink
Merge pull request #3760 from dpalou/MOBILE-4373
Browse files Browse the repository at this point in the history
MOBILE-4373 core: Support pages, numbers and key file extensions
  • Loading branch information
NoelDeMartin authored Jul 31, 2023
2 parents 039e715 + 58492bb commit 8c129fe
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 4 deletions.
5 changes: 4 additions & 1 deletion scripts/langindex.json
Original file line number Diff line number Diff line change
Expand Up @@ -1404,6 +1404,9 @@
"assets.mimetypes.application/json": "mimetypes",
"assets.mimetypes.application/msword": "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.document": "local_moodlemobileapp",
"assets.mimetypes.application/vnd.google-apps.drawing": "local_moodlemobileapp",
Expand Down Expand Up @@ -1587,9 +1590,9 @@
"core.course.errordownloadingsection": "local_moodlemobileapp",
"core.course.errorgetmodule": "local_moodlemobileapp",
"core.course.failed": "completion",
"core.course.guestaccess": "enrol_guest/pluginname",
"core.course.guestaccess_passwordinvalid": "enrol_guest/passwordinvalid",
"core.course.guestaccess_withpassword": "enrol_guest",
"core.course.guestaccess": "enrol_guest/pluginname",
"core.course.hiddenfromstudents": "moodle",
"core.course.hiddenoncoursepage": "moodle",
"core.course.highlighted": "moodle",
Expand Down
4 changes: 3 additions & 1 deletion src/assets/exttomime.json
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@
"jut": {"type":"image/jutvision"},
"kar": {"type":"audio/midi"},
"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"},
"kia": {"type":"application/vnd.kidspiration"},
"kml": {"type":"application/vnd.google-earth.kml+xml"},
Expand Down Expand Up @@ -670,6 +670,7 @@
"nsc": {"type":"application/x-conference"},
"nsf": {"type":"application/vnd.lotus-notes"},
"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"},
"nzb": {"type":"application/x-nzb"},
"o": {"type":"application/octet-stream"},
Expand Down Expand Up @@ -727,6 +728,7 @@
"p7r": {"type":"application/x-pkcs7-certreqresp"},
"p7s": {"type":"application/pkcs7-signature"},
"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"},
"pas": {"type":"text/x-pascal"},
"paw": {"type":"application/vnd.pawaafile"},
Expand Down
6 changes: 6 additions & 0 deletions src/assets/mimetoext.json
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,10 @@
"application/vnd.anser-web-funds-transfer-initiation": ["fti"],
"application/vnd.antix.game-component": ["atx"],
"application/vnd.apple.installer+xml": ["mpkg"],
"application/vnd.apple.keynote": ["key"],
"application/vnd.apple.mpegurl": ["m3u8"],
"application/vnd.apple.numbers": ["numbers"],
"application/vnd.apple.pages": ["pages"],
"application/vnd.aristanetworks.swi": ["swi"],
"application/vnd.astraea-software.iota": ["iota"],
"application/vnd.audiograph": ["aep"],
Expand Down Expand Up @@ -626,6 +629,9 @@
"application/x-inventor": ["iv"],
"application/x-ip2": ["ip"],
"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-commerce": ["jcm"],
"application/x-java-jnlp-file": ["jnlp"],
Expand Down
3 changes: 3 additions & 0 deletions src/assets/mimetypes.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"application/json": "{{$a.MIMETYPE2}} text",
"application/msword": "Word 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.document": "Google Docs",
"application/vnd.google-apps.drawing": "Google Drawing",
Expand Down
14 changes: 13 additions & 1 deletion src/core/services/utils/mimetype.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ interface MimeTypeInfo {
type: string;
icon?: string;
groups?: string[];

// eslint-disable-next-line id-blacklist
string?: string;
deprecated?: string; // Deprecated mimetype name.
}

interface MimeTypeGroupInfo {
Expand Down Expand Up @@ -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.
* Based on Moodle's get_mimetype_description.
Expand Down
20 changes: 19 additions & 1 deletion src/core/services/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1033,12 +1033,30 @@ export class CoreUtilsProvider {
// Error, use the original path.
}

try {
const openFile = async (mimetype?: string) => {
if (this.shouldOpenWithDialog(options)) {
await FileOpener.showOpenWithDialog(path, mimetype || '');
} else {
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) {
this.logger.error('Error opening file ' + path + ' with mimetype ' + mimetype);
this.logger.error('Error: ', JSON.stringify(error));
Expand Down

0 comments on commit 8c129fe

Please sign in to comment.