MOBILE-3213 resource: Fix PTR on mod resource
parent
72a2b571cd
commit
5053274a85
|
@ -661,7 +661,6 @@ export class CoreCourseHelperProvider {
|
||||||
|
|
||||||
const mainFile = files[0],
|
const mainFile = files[0],
|
||||||
fileUrl = this.fileHelper.getFileUrl(mainFile),
|
fileUrl = this.fileHelper.getFileUrl(mainFile),
|
||||||
timemodified = this.fileHelper.getFileTimemodified(mainFile),
|
|
||||||
result = {
|
result = {
|
||||||
fixedUrl: undefined,
|
fixedUrl: undefined,
|
||||||
path: undefined,
|
path: undefined,
|
||||||
|
@ -678,23 +677,60 @@ export class CoreCourseHelperProvider {
|
||||||
return this.filepoolProvider.getPackageStatus(siteId, component, componentId).then((status) => {
|
return this.filepoolProvider.getPackageStatus(siteId, component, componentId).then((status) => {
|
||||||
result.status = status;
|
result.status = status;
|
||||||
|
|
||||||
const isWifi = this.appProvider.isWifi(),
|
|
||||||
isOnline = this.appProvider.isOnline();
|
|
||||||
|
|
||||||
if (status === CoreConstants.DOWNLOADED) {
|
if (status === CoreConstants.DOWNLOADED) {
|
||||||
// Get the local file URL.
|
// Get the local file URL.
|
||||||
return this.filepoolProvider.getInternalUrlByUrl(siteId, fileUrl).catch((error) => {
|
return this.filepoolProvider.getInternalUrlByUrl(siteId, fileUrl).catch((error) => {
|
||||||
// File not found, mark the module as not downloaded and reject.
|
// File not found, mark the module as not downloaded and try again.
|
||||||
return this.filepoolProvider.storePackageStatus(siteId, CoreConstants.NOT_DOWNLOADED, component,
|
return this.filepoolProvider.storePackageStatus(siteId, CoreConstants.NOT_DOWNLOADED, component,
|
||||||
componentId).then(() => {
|
componentId).then(() => {
|
||||||
|
|
||||||
return Promise.reject(error);
|
return this.downloadModuleWithMainFile(module, courseId, fixedUrl, files, status, component,
|
||||||
|
componentId, siteId);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
} else if (status === CoreConstants.DOWNLOADING && !this.appProvider.isDesktop()) {
|
} else if (status === CoreConstants.DOWNLOADING && !this.appProvider.isDesktop()) {
|
||||||
// Return the online URL.
|
// Return the online URL.
|
||||||
return fixedUrl;
|
return fixedUrl;
|
||||||
} else {
|
} else {
|
||||||
|
return this.downloadModuleWithMainFile(module, courseId, fixedUrl, files, status, component, componentId,
|
||||||
|
siteId);
|
||||||
|
}
|
||||||
|
}).then((path) => {
|
||||||
|
result.path = path;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// We use the live URL.
|
||||||
|
result.path = fixedUrl;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convenience function to download a module that has a main file and return the local file's path and other info.
|
||||||
|
* This is meant for modules like mod_resource.
|
||||||
|
*
|
||||||
|
* @param module The module to download.
|
||||||
|
* @param courseId The course ID of the module.
|
||||||
|
* @param fixedUrl Main file's fixed URL.
|
||||||
|
* @param files List of files of the module.
|
||||||
|
* @param status The package status.
|
||||||
|
* @param component The component to link the files to.
|
||||||
|
* @param componentId An ID to use in conjunction with the component.
|
||||||
|
* @param siteId The site ID. If not defined, current site.
|
||||||
|
* @return Promise resolved when done.
|
||||||
|
*/
|
||||||
|
protected downloadModuleWithMainFile(module: any, courseId: number, fixedUrl: string, files: any[], status: string,
|
||||||
|
component?: string, componentId?: string | number, siteId?: string): Promise<string> {
|
||||||
|
|
||||||
|
const isOnline = this.appProvider.isOnline();
|
||||||
|
const mainFile = files[0];
|
||||||
|
const fileUrl = this.fileHelper.getFileUrl(mainFile);
|
||||||
|
const timemodified = this.fileHelper.getFileTimemodified(mainFile);
|
||||||
|
|
||||||
if (!isOnline && status === CoreConstants.NOT_DOWNLOADED) {
|
if (!isOnline && status === CoreConstants.NOT_DOWNLOADED) {
|
||||||
// Not downloaded and we're offline, reject.
|
// Not downloaded and we're offline, reject.
|
||||||
return Promise.reject(this.translate.instant('core.networkerrormsg'));
|
return Promise.reject(this.translate.instant('core.networkerrormsg'));
|
||||||
|
@ -707,7 +743,7 @@ export class CoreCourseHelperProvider {
|
||||||
});
|
});
|
||||||
}, () => {
|
}, () => {
|
||||||
// Start the download if in wifi, but return the URL right away so the file is opened.
|
// Start the download if in wifi, but return the URL right away so the file is opened.
|
||||||
if (isWifi) {
|
if (this.appProvider.isWifi()) {
|
||||||
this.downloadModule(module, courseId, component, componentId, files, siteId);
|
this.downloadModule(module, courseId, component, componentId, files, siteId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -721,19 +757,6 @@ export class CoreCourseHelperProvider {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}).then((path) => {
|
|
||||||
result.path = path;
|
|
||||||
|
|
||||||
return result;
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
// We use the live URL.
|
|
||||||
result.path = fixedUrl;
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convenience function to download a module.
|
* Convenience function to download a module.
|
||||||
|
|
Loading…
Reference in New Issue