MOBILE-4640 page: Fix index file not re-downloaded when needed
parent
e181137a6a
commit
61ff5142fb
|
@ -38,28 +38,26 @@ export class AddonModPageHelperProvider {
|
||||||
* @returns The HTML of the page.
|
* @returns The HTML of the page.
|
||||||
*/
|
*/
|
||||||
async getPageHtml(contents: CoreCourseModuleContentFile[], moduleId: number): Promise<string> {
|
async getPageHtml(contents: CoreCourseModuleContentFile[], moduleId: number): Promise<string> {
|
||||||
let indexUrl: string | undefined;
|
let indexFile: CoreCourseModuleContentFile | undefined;
|
||||||
const paths: Record<string, string> = {};
|
const paths: Record<string, string> = {};
|
||||||
|
|
||||||
// Extract the information about paths from the module contents.
|
// Extract the information about paths from the module contents.
|
||||||
contents.forEach((content) => {
|
contents.forEach((content) => {
|
||||||
const url = content.fileurl;
|
|
||||||
|
|
||||||
if (this.isMainPage(content)) {
|
if (this.isMainPage(content)) {
|
||||||
// This seems to be the most reliable way to spot the index page.
|
// This seems to be the most reliable way to spot the index page.
|
||||||
indexUrl = url;
|
indexFile = content;
|
||||||
} else {
|
} else {
|
||||||
let key = content.filename;
|
let key = content.filename;
|
||||||
if (content.filepath !== '/') {
|
if (content.filepath !== '/') {
|
||||||
// Add the folders without the leading slash.
|
// Add the folders without the leading slash.
|
||||||
key = content.filepath.substring(1) + key;
|
key = content.filepath.substring(1) + key;
|
||||||
}
|
}
|
||||||
paths[CoreUrl.decodeURIComponent(key)] = url;
|
paths[CoreUrl.decodeURIComponent(key)] = content.fileurl;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Promise handling when we are in a browser.
|
// Promise handling when we are in a browser.
|
||||||
if (!indexUrl) {
|
if (!indexFile) {
|
||||||
// If ever that happens.
|
// If ever that happens.
|
||||||
throw new CoreError('Could not locate the index page');
|
throw new CoreError('Could not locate the index page');
|
||||||
}
|
}
|
||||||
|
@ -69,14 +67,15 @@ export class AddonModPageHelperProvider {
|
||||||
// The file system is available.
|
// The file system is available.
|
||||||
url = await CoreFilepool.downloadUrl(
|
url = await CoreFilepool.downloadUrl(
|
||||||
CoreSites.getCurrentSiteId(),
|
CoreSites.getCurrentSiteId(),
|
||||||
indexUrl,
|
indexFile.fileurl,
|
||||||
false,
|
false,
|
||||||
ADDON_MOD_PAGE_COMPONENT,
|
ADDON_MOD_PAGE_COMPONENT,
|
||||||
moduleId,
|
moduleId,
|
||||||
|
indexFile.timemodified,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
// We return the live URL.
|
// We return the live URL.
|
||||||
url = await CoreSites.getCurrentSite()?.checkAndFixPluginfileURL(indexUrl) || '';
|
url = await CoreSites.getCurrentSite()?.checkAndFixPluginfileURL(indexFile.fileurl) || '';
|
||||||
}
|
}
|
||||||
|
|
||||||
const content = await CoreWS.getText(url);
|
const content = await CoreWS.getText(url);
|
||||||
|
|
Loading…
Reference in New Issue