Skip to content

Commit

Permalink
Merge pull request #3774 from crazyserver/MOBILE-4407
Browse files Browse the repository at this point in the history
Mobile 4407
  • Loading branch information
NoelDeMartin authored Aug 31, 2023
2 parents 475975f + 634447d commit 3e1ded1
Show file tree
Hide file tree
Showing 78 changed files with 256 additions and 56 deletions.
6 changes: 1 addition & 5 deletions src/addons/mod/resource/services/handlers/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { CoreCourseModuleData } from '@features/course/services/course-helper';
import { CoreCourseModuleHandler, CoreCourseModuleHandlerData } from '@features/course/services/module-delegate';
import { CoreCourseModulePrefetchDelegate } from '@features/course/services/module-prefetch-delegate';
import { CoreFileHelper } from '@services/file-helper';
import { CoreSites } from '@services/sites';
import { CoreMimetypeUtils } from '@services/utils/mimetype';
import { CoreTextUtils } from '@services/utils/text';
import { CoreTimeUtils } from '@services/utils/time';
Expand Down Expand Up @@ -229,9 +228,6 @@ export class AddonModResourceModuleHandlerService extends CoreModuleHandlerBase
return;
}

if (CoreSites.getCurrentSite()?.isVersionGreaterEqualThan('4.0')) {
return CoreCourse.getModuleIconSrc(module.modname, module.modicon);
}
let mimetypeIcon = '';

if (module.contentsinfo) {
Expand Down Expand Up @@ -264,7 +260,7 @@ export class AddonModResourceModuleHandlerService extends CoreModuleHandlerBase
iconIsShape(module?: CoreCourseModuleData | undefined, modicon?: string | undefined): boolean | undefined {
const iconUrl = module?.modicon ?? modicon;

return !iconUrl?.startsWith('assets/img/files/');
return !iconUrl?.startsWith('assets/img/files_legacy/') && !iconUrl?.endsWith('.png');
}

}
Expand Down
53 changes: 47 additions & 6 deletions src/addons/mod/url/services/handlers/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,57 @@ export class AddonModUrlModuleHandlerService extends CoreModuleHandlerBase imple

if (handlerData.buttons && hideButton !== undefined) {
handlerData.buttons[0].hidden = hideButton;
}

try {
handlerData.icon = await this.getIconSrc(module);
} catch {
// Ignore errors.
}

return handlerData;
}

/**
* @inheritdoc
*/
async getIconSrc(module?: CoreCourseModuleData): Promise<string | undefined> {
if (!module) {
return;
}

let mainFile = module.contents?.[0];

if (module.contents && module.contents[0]) {
const icon = AddonModUrl.guessIcon(module.contents[0].fileurl);
if (!mainFile) {
try {
// Try to get module contents, it's needed to get the URL with parameters.
const contents = await CoreCourse.getModuleContents(
module,
undefined,
undefined,
true,
false,
undefined,
'url',
);

// Calculate the icon to use.
handlerData.icon = CoreCourse.getModuleIconSrc(module.modname, module.modicon, icon);
mainFile = contents[0];
} catch {
// Fallback in case is not prefetched.
const mod = await CoreCourse.getModule(module.id, module.course, undefined, true, false, undefined, 'url');

mainFile = mod.contents?.[0];
}
}

return handlerData;
if (!mainFile) {
return;
}

const icon = AddonModUrl.guessIcon(mainFile.fileurl);

// Calculate the icon to use.
return CoreCourse.getModuleIconSrc(module.modname, module.modicon, icon);
}

/**
Expand Down Expand Up @@ -187,7 +228,7 @@ export class AddonModUrlModuleHandlerService extends CoreModuleHandlerBase imple
iconIsShape(module?: CoreCourseModuleData | undefined, modicon?: string | undefined): boolean | undefined {
const iconUrl = module?.modicon ?? modicon;

return !iconUrl?.startsWith('assets/img/files/');
return !iconUrl?.startsWith('assets/img/files_legacy/') && !iconUrl?.endsWith('.png');
}

/**
Expand Down
84 changes: 42 additions & 42 deletions src/assets/exttomime.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"3dml": {"type":"text/vnd.in3d.3dml"},
"3ds": {"type":"image/x-3ds"},
"3g2": {"type":"video/3gpp2"},
"3gp": {"type":"video/3gpp","icon":"quicktime","string":"video","groups":["video"]},
"3gpp": {"type":"video/3gpp","icon":"quicktime","string":"video","groups":["video"]},
"3gp": {"type":"video/3gpp","icon":"video","string":"video","groups":["video"]},
"3gpp": {"type":"video/3gpp","icon":"video","string":"video","groups":["video"]},
"7z": {"type":"application/x-7z-compressed","icon":"archive","string":"archive","groups":["archive"]},
"a": {"type":"application/octet-stream"},
"aab": {"type":"application/x-authorware-bin"},
Expand All @@ -17,7 +17,7 @@
"abw": {"type":"application/x-abiword"},
"ac": {"type":"application/pkix-attr-cert"},
"acc": {"type":"application/vnd.americandynamics.acc"},
"accdb": {"type":"application/msaccess","icon":"base"},
"accdb": {"type":"application/msaccess","icon":"database"},
"ace": {"type":"application/x-ace-compressed","icon":"archive"},
"acgi": {"type":"text/html"},
"acu": {"type":"application/vnd.acucobol"},
Expand Down Expand Up @@ -53,7 +53,7 @@
"asax": {"type":"application/octet-stream"},
"asc": {"type":"text/plain","icon":"sourcecode"},
"ascx": {"type":"text/plain"},
"asf": {"type":"video/x-ms-asf","icon":"wmv","string":"video","groups":["video"]},
"asf": {"type":"video/x-ms-asf","icon":"video","string":"video","groups":["video"]},
"ashx": {"type":"text/plain"},
"asm": {"type":"text/plain","icon":"sourcecode"},
"asmx": {"type":"text/plain"},
Expand All @@ -67,7 +67,7 @@
"atomsvc": {"type":"application/atomsvc+xml","icon":"markup"},
"atx": {"type":"application/vnd.antix.game-component"},
"au": {"type":"audio/au","icon":"audio","string":"audio","groups":["audio"]},
"avi": {"type":"video/x-ms-wm","icon":"avi","string":"video","groups":["video","web_video"]},
"avi": {"type":"video/x-ms-wm","icon":"video","string":"video","groups":["video","web_video"]},
"avs": {"type":"video/avs-video"},
"aw": {"type":"application/applixware"},
"axd": {"type":"text/plain"},
Expand All @@ -84,9 +84,9 @@
"bin": {"type":"application/octet-stream"},
"blb": {"type":"application/x-blorb"},
"blorb": {"type":"application/x-blorb"},
"bm": {"type":"image/bmp","icon":"bmp","string":"image","groups":["image","web_image"]},
"bm": {"type":"image/bmp","icon":"image","string":"image","groups":["image","web_image"]},
"bmi": {"type":"application/vnd.bmi"},
"bmp": {"type":"image/bmp","icon":"bmp","string":"image","groups":["image","web_image"]},
"bmp": {"type":"image/bmp","icon":"image","string":"image","groups":["image","web_image"]},
"boo": {"type":"application/book"},
"book": {"type":"application/vnd.framemaker"},
"box": {"type":"application/vnd.previewsystems.box"},
Expand Down Expand Up @@ -200,7 +200,7 @@
"dfac": {"type":"application/vnd.dreamfactory"},
"dgc": {"type":"application/x-dgc-compressed"},
"dic": {"type":"text/x-c"},
"dif": {"type":"video/x-dv","icon":"quicktime","string":"video","groups":["video"]},
"dif": {"type":"video/x-dv","icon":"video","string":"video","groups":["video"]},
"dir": {"type":"application/x-director","icon":"flash"},
"dis": {"type":"application/vnd.mobius.dis"},
"dist": {"type":"application/octet-stream"},
Expand Down Expand Up @@ -230,7 +230,7 @@
"dts": {"type":"audio/vnd.dts"},
"dtshd": {"type":"audio/vnd.dts.hd"},
"dump": {"type":"application/octet-stream"},
"dv": {"type":"video/x-dv","icon":"quicktime","string":"video","groups":["video"]},
"dv": {"type":"video/x-dv","icon":"video","string":"video","groups":["video"]},
"dvb": {"type":"video/vnd.dvb.file"},
"dvi": {"type":"application/x-dvi"},
"dwf": {"type":"model/vnd.dwf"},
Expand Down Expand Up @@ -299,7 +299,7 @@
"fly": {"type":"text/vnd.fly"},
"fm": {"type":"application/vnd.framemaker"},
"fmf": {"type":"video/x-atomic3d-feature"},
"fmp4": {"type":"video/mp4","icon":"mpeg","string":"video","groups":["html_video","video","web_video"]},
"fmp4": {"type":"video/mp4","icon":"video","string":"video","groups":["html_video","video","web_video"]},
"fnc": {"type":"application/vnd.frogans.fnc"},
"for": {"type":"text/x-fortran"},
"fpx": {"type":"image/vnd.fpx"},
Expand Down Expand Up @@ -333,7 +333,7 @@
"ggb": {"type":"application/vnd.geogebra.file","icon":"archive"},
"ggt": {"type":"application/vnd.geogebra.tool","icon":"archive"},
"ghf": {"type":"application/vnd.groove-help"},
"gif": {"type":"image/gif","icon":"gif","string":"image","groups":["image","web_image"]},
"gif": {"type":"image/gif","icon":"gif","string":"image","groups":["image","web_image","optimised_image"]},
"gim": {"type":"application/vnd.groove-identity-message"},
"gl": {"type":"video/gl"},
"gml": {"type":"application/gml+xml"},
Expand Down Expand Up @@ -385,8 +385,8 @@
"hta": {"type":"application/octet-stream"},
"htc": {"type":"text/x-component","icon":"markup"},
"htke": {"type":"application/vnd.kenameaapp"},
"htm": {"type":"text/html","icon":"html","groups":["web_file"]},
"html": {"type":"text/html","icon":"html","groups":["web_file"]},
"htm": {"type":"text/html","icon":"markup","groups":["web_file"]},
"html": {"type":"text/html","icon":"markup","groups":["web_file"]},
"htmls": {"type":"text/html"},
"htt": {"type":"text/webviewhtml"},
"htx": {"type":"text/html"},
Expand Down Expand Up @@ -457,9 +457,9 @@
"jmx": {"type":"text/xml","icon":"markup"},
"jnlp": {"type":"application/x-java-jnlp-file","icon":"markup"},
"joda": {"type":"application/vnd.joost.joda-archive"},
"jpe": {"type":"image/jpeg","icon":"jpeg","string":"image","groups":["image","web_image"]},
"jpeg": {"type":"image/jpeg","icon":"jpeg","string":"image","groups":["image","web_image"]},
"jpg": {"type":"image/jpeg","icon":"jpeg","string":"image","groups":["image","web_image"]},
"jpe": {"type":"image/jpeg","icon":"image","string":"image","groups":["image","web_image","optimised_image"]},
"jpeg": {"type":"image/jpeg","icon":"image","string":"image","groups":["image","web_image","optimised_image"]},
"jpg": {"type":"image/jpeg","icon":"image","string":"image","groups":["image","web_image","optimised_image"]},
"jpgm": {"type":"video/jpm"},
"jpgv": {"type":"video/jpeg"},
"jpm": {"type":"video/jpm"},
Expand Down Expand Up @@ -528,11 +528,11 @@
"m2a": {"type":"audio/mpeg"},
"m2v": {"type":"video/mpeg"},
"m3a": {"type":"audio/mpeg"},
"m3u": {"type":"audio/x-mpegurl","icon":"mp3","string":"audio","groups":["audio"]},
"m3u8": {"type":"application/x-mpegURL","icon":"mpeg","groups":["media_source"]},
"m4a": {"type":"audio/mp4","icon":"mp3","string":"audio","groups":["audio","html_audio","web_audio"]},
"m3u": {"type":"audio/x-mpegurl","icon":"audio","string":"audio","groups":["audio"]},
"m3u8": {"type":"application/x-mpegURL","icon":"video","groups":["media_source"]},
"m4a": {"type":"audio/mp4","icon":"audio","string":"audio","groups":["audio","html_audio","web_audio"]},
"m4u": {"type":"video/vnd.mpegurl"},
"m4v": {"type":"video/mp4","icon":"mpeg","string":"video","groups":["html_video","video","web_video"]},
"m4v": {"type":"video/mp4","icon":"video","string":"video","groups":["html_video","video","web_video"]},
"ma": {"type":"application/mathematica","string":"math"},
"mads": {"type":"application/mads+xml"},
"mag": {"type":"application/vnd.ecowin.chart"},
Expand All @@ -552,7 +552,7 @@
"mcf": {"type":"image/vasa"},
"mcp": {"type":"application/netmc"},
"mcurl": {"type":"text/vnd.curl.mcurl"},
"mdb": {"type":"application/x-msaccess","icon":"base"},
"mdb": {"type":"application/x-msaccess","icon":"database"},
"mdi": {"type":"image/vnd.ms-modi"},
"me": {"type":"text/troff"},
"mesh": {"type":"model/mesh"},
Expand Down Expand Up @@ -590,22 +590,22 @@
"mod": {"type":"audio/mod"},
"mods": {"type":"application/mods+xml"},
"moov": {"type":"video/quicktime"},
"mov": {"type":"video/quicktime","icon":"quicktime","string":"video","groups":["video","web_video","html_video"]},
"movie": {"type":"video/x-sgi-movie","icon":"quicktime","string":"video","groups":["video"]},
"mov": {"type":"video/quicktime","icon":"video","string":"video","groups":["video","web_video","html_video"]},
"movie": {"type":"video/x-sgi-movie","icon":"video","string":"video","groups":["video"]},
"mp2": {"type":"audio/mpeg"},
"mp21": {"type":"application/mp21"},
"mp2a": {"type":"audio/mpeg"},
"mp3": {"type":"audio/mp3","icon":"mp3","string":"audio","groups":["audio","html_audio","web_audio"]},
"mp4": {"type":"video/mp4","icon":"mpeg","string":"video","groups":["html_video","video","web_video"]},
"mp3": {"type":"audio/mp3","icon":"audio","string":"audio","groups":["audio","html_audio","web_audio"]},
"mp4": {"type":"video/mp4","icon":"video","string":"video","groups":["html_video","video","web_video"]},
"mp4a": {"type":"audio/mp4","icon":"audio","string":"audio","groups":["audio","html_audio","web_audio"]},
"mp4s": {"type":"application/mp4"},
"mp4v": {"type":"video/mp4","icon":"mpeg","string":"video","groups":["video","web_video"]},
"mp4v": {"type":"video/mp4","icon":"video","string":"video","groups":["video","web_video"]},
"mpa": {"type":"audio/mpeg"},
"mpc": {"type":"application/vnd.mophun.certificate"},
"mpd": {"type":"application/dash+xml","icon":"mpeg","groups":["media_source"]},
"mpe": {"type":"video/mpeg","icon":"mpeg","string":"video","groups":["video","web_video"]},
"mpeg": {"type":"video/mpeg","icon":"mpeg","string":"video","groups":["video","web_video"]},
"mpg": {"type":"video/mpeg","icon":"mpeg","string":"video","groups":["video","web_video"]},
"mpd": {"type":"application/dash+xml","icon":"video","groups":["media_source"]},
"mpe": {"type":"video/mpeg","icon":"video","string":"video","groups":["video","web_video"]},
"mpeg": {"type":"video/mpeg","icon":"video","string":"video","groups":["video","web_video"]},
"mpg": {"type":"video/mpeg","icon":"video","string":"video","groups":["video","web_video"]},
"mpg4": {"type":"video/mp4"},
"mpga": {"type":"audio/mpeg"},
"mpkg": {"type":"application/vnd.apple.installer+xml"},
Expand Down Expand Up @@ -680,7 +680,7 @@
"obd": {"type":"application/x-msbinder"},
"obj": {"type":"application/x-tgif"},
"oda": {"type":"application/oda"},
"odb": {"type":"application/vnd.oasis.opendocument.database","icon":"base"},
"odb": {"type":"application/vnd.oasis.opendocument.database","icon":"database"},
"odc": {"type":"application/vnd.oasis.opendocument.chart","icon":"chart"},
"odf": {"type":"application/vnd.oasis.opendocument.formula","icon":"math"},
"odft": {"type":"application/vnd.oasis.opendocument.formula-template","icon":"math"},
Expand Down Expand Up @@ -773,7 +773,7 @@
"pm4": {"type":"application/x-pagemaker"},
"pm5": {"type":"application/x-pagemaker"},
"pml": {"type":"application/vnd.ctc-posml"},
"png": {"type":"image/png","icon":"png","string":"image","groups":["image","web_image"]},
"png": {"type":"image/png","icon":"image","string":"image","groups":["image","web_image","optimised_image"]},
"pnm": {"type":"image/x-portable-anymap"},
"portpkg": {"type":"application/vnd.macports.portpkg"},
"pot": {"type":"application/vnd.ms-powerpoint","icon":"powerpoint","groups":["presentation"]},
Expand Down Expand Up @@ -819,7 +819,7 @@
"qfx": {"type":"application/vnd.intu.qfx"},
"qif": {"type":"image/x-quicktime"},
"qps": {"type":"application/vnd.publishare-delta-tree"},
"qt": {"type":"video/quicktime","icon":"quicktime","string":"video","groups":["video","web_video"]},
"qt": {"type":"video/quicktime","icon":"video","string":"video","groups":["video","web_video"]},
"qtc": {"type":"video/x-qtc"},
"qti": {"type":"image/x-quicktime"},
"qtif": {"type":"image/x-quicktime"},
Expand Down Expand Up @@ -992,8 +992,8 @@
"svgz": {"type":"image/svg+xml","icon":"image","string":"image","groups":["image","web_image"]},
"svr": {"type":"application/x-world"},
"swa": {"type":"application/x-director","icon":"flash"},
"swf": {"type":"application/x-shockwave-flash","icon":"flash","groups":["video"]},
"swfl": {"type":"application/x-shockwave-flash","icon":"flash","groups":["video"]},
"swf": {"type":"application/x-shockwave-flash","icon":"flash"},
"swfl": {"type":"application/x-shockwave-flash","icon":"flash"},
"swi": {"type":"application/vnd.aristanetworks.swi"},
"sxc": {"type":"application/vnd.sun.xml.calc","icon":"calc"},
"sxd": {"type":"application/vnd.sun.xml.draw","icon":"draw"},
Expand Down Expand Up @@ -1023,16 +1023,16 @@
"tga": {"type":"image/x-tga"},
"tgz": {"type":"application/g-zip","icon":"archive","string":"archive","groups":["archive"]},
"thmx": {"type":"application/vnd.ms-officetheme"},
"tif": {"type":"image/tiff","icon":"tiff","string":"image","groups":["image"]},
"tiff": {"type":"image/tiff","icon":"tiff","string":"image","groups":["image"]},
"tif": {"type":"image/tiff","icon":"image","string":"image","groups":["image"]},
"tiff": {"type":"image/tiff","icon":"image","string":"image","groups":["image"]},
"tmo": {"type":"application/vnd.tmobile-livetv"},
"torrent": {"type":"application/x-bittorrent"},
"tpl": {"type":"application/vnd.groove-tool-template"},
"tpt": {"type":"application/vnd.trid.tpt"},
"tr": {"type":"text/troff"},
"tra": {"type":"application/vnd.trueapp"},
"trm": {"type":"application/x-msterminal"},
"ts": {"type":"video/MP2T","icon":"mpeg","string":"video","groups":["video","web_video"]},
"ts": {"type":"video/MP2T","icon":"video","string":"video","groups":["video","web_video"]},
"tsd": {"type":"application/timestamped-data"},
"tsi": {"type":"audio/tsp-audio"},
"tsp": {"type":"application/dsptype"},
Expand Down Expand Up @@ -1129,7 +1129,7 @@
"w61": {"type":"application/wordperfect6.1"},
"w6w": {"type":"application/msword"},
"wad": {"type":"application/x-doom"},
"wav": {"type":"audio/wav","icon":"wav","string":"audio","groups":["audio","html_audio","web_audio"]},
"wav": {"type":"audio/wav","icon":"audio","string":"audio","groups":["audio","html_audio","web_audio"]},
"wax": {"type":"audio/x-ms-wax"},
"wb1": {"type":"application/x-qpro"},
"wbmp": {"type":"image/vnd.wap.wbmp"},
Expand All @@ -1155,7 +1155,7 @@
"wmlc": {"type":"application/vnd.wap.wmlc"},
"wmls": {"type":"text/vnd.wap.wmlscript"},
"wmlsc": {"type":"application/vnd.wap.wmlscriptc"},
"wmv": {"type":"video/x-ms-wmv","icon":"wmv","string":"video","groups":["video"]},
"wmv": {"type":"video/x-ms-wmv","icon":"video","string":"video","groups":["video"]},
"wmx": {"type":"video/x-ms-wmx"},
"wmz": {"type":"application/x-ms-wmz"},
"woff": {"type":"application/x-font-woff"},
Expand All @@ -1178,7 +1178,7 @@
"wtb": {"type":"application/vnd.webturbo"},
"wtk": {"type":"application/x-wintalk"},
"wvx": {"type":"video/x-ms-wvx"},
"x-png": {"type":"image/png","icon":"png","string":"image","groups":["image","web_image"]},
"x-png": {"type":"image/png","icon":"image","string":"image","groups":["image","web_image"]},
"x3d": {"type":"model/x3d+xml"},
"x3db": {"type":"model/x3d+binary"},
"x3dbz": {"type":"model/x3d+binary"},
Expand All @@ -1205,7 +1205,7 @@
"xfdl": {"type":"application/vnd.xfdl"},
"xgz": {"type":"xgl/drawing"},
"xht": {"type":"application/xhtml+xml"},
"xhtml": {"type":"application/xhtml+xml","icon":"html","groups":["web_file"]},
"xhtml": {"type":"application/xhtml+xml","icon":"markup","groups":["web_file"]},
"xhvml": {"type":"application/xv+xml"},
"xif": {"type":"image/vnd.xiff"},
"xl": {"type":"application/excel"},
Expand Down
3 changes: 3 additions & 0 deletions src/assets/img/files/archive.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 3e1ded1

Please sign in to comment.