From 33a2557c23e5085245c5561e950366fcee0c74f0 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Mon, 13 Jul 2020 16:24:58 +0200 Subject: [PATCH] MOBILE-3453 h5p: Don't unpack more than one H5P at the same time --- src/core/h5p/classes/helper.ts | 23 ++++++++++++++++++++--- src/core/h5p/providers/h5p.ts | 3 +++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/core/h5p/classes/helper.ts b/src/core/h5p/classes/helper.ts index 8d42f04c2..905ed8c08 100644 --- a/src/core/h5p/classes/helper.ts +++ b/src/core/h5p/classes/helper.ts @@ -146,12 +146,29 @@ export class CoreH5PHelper { static async saveH5P(fileUrl: string, file: FileEntry, siteId?: string, onProgress?: (event: any) => any): Promise { siteId = siteId || CoreSites.instance.getCurrentSiteId(); - const folderName = CoreMimetypeUtils.instance.removeExtension(file.name); - const destFolder = CoreTextUtils.instance.concatenatePaths(CoreFileProvider.TMPFOLDER, 'h5p/' + folderName); - // Notify that the unzip is starting. onProgress && onProgress({message: 'core.unzipping'}); + const queueId = siteId + ':saveH5P:' + fileUrl; + + await CoreH5P.instance.queueRunner.run(queueId, () => CoreH5PHelper.performSave(fileUrl, file, siteId, onProgress)); + } + + /** + * Extract and store an H5P file. + * + * @param fileUrl The file URL used to download the file. + * @param file The file entry of the downloaded file. + * @param siteId Site ID. If not defined, current site. + * @param onProgress Function to call on progress. + * @return Promise resolved when done. + */ + protected static async performSave(fileUrl: string, file: FileEntry, siteId?: string, onProgress?: (event: any) => any) + : Promise { + + const folderName = CoreMimetypeUtils.instance.removeExtension(file.name); + const destFolder = CoreTextUtils.instance.concatenatePaths(CoreFileProvider.TMPFOLDER, 'h5p/' + folderName); + // Unzip the file. await CoreFile.instance.unzipFile(file.toURL(), destFolder, onProgress); diff --git a/src/core/h5p/providers/h5p.ts b/src/core/h5p/providers/h5p.ts index cdccc72be..c0a83dff0 100644 --- a/src/core/h5p/providers/h5p.ts +++ b/src/core/h5p/providers/h5p.ts @@ -19,6 +19,7 @@ import { CoreSite, CoreSiteWSPreSets } from '@classes/site'; import { CoreWSExternalWarning, CoreWSExternalFile } from '@providers/ws'; import { CoreTextUtils } from '@providers/utils/text'; import { CoreUrlUtils } from '@providers/utils/url'; +import { CoreQueueRunner } from '@classes/queue-runner'; import { CoreH5PCore } from '../classes/core'; import { CoreH5PFramework } from '../classes/framework'; @@ -46,6 +47,7 @@ export class CoreH5PProvider { h5pPlayer: CoreH5PPlayer; h5pStorage: CoreH5PStorage; h5pValidator: CoreH5PValidator; + queueRunner: CoreQueueRunner; protected siteSchema: CoreSiteSchema = { name: 'CoreH5PProvider', @@ -271,6 +273,7 @@ export class CoreH5PProvider { constructor() { this.logger = CoreLogger.instance.getInstance('CoreH5PProvider'); + this.queueRunner = new CoreQueueRunner(1); CoreSites.instance.registerSiteSchema(this.siteSchema);