From e9e6a42e1b2a23731e0e46969effe2f22955c653 Mon Sep 17 00:00:00 2001 From: Oluwatobi Awe Date: Mon, 19 Aug 2024 00:52:10 +0100 Subject: [PATCH 1/3] archive replaced file --- LearningHub.Nhs.WebUI/Controllers/Api/ResourceController.cs | 5 +++-- LearningHub.Nhs.WebUI/Scripts/vuesrc/contribute/Content.vue | 5 +++-- LearningHub.Nhs.WebUI/Scripts/vuesrc/data/resource.ts | 4 ++-- WebAPI/LearningHub.Nhs.API/LearningHub.Nhs.Api.csproj.user | 2 +- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/LearningHub.Nhs.WebUI/Controllers/Api/ResourceController.cs b/LearningHub.Nhs.WebUI/Controllers/Api/ResourceController.cs index 0616474ff..e5e8ab35e 100644 --- a/LearningHub.Nhs.WebUI/Controllers/Api/ResourceController.cs +++ b/LearningHub.Nhs.WebUI/Controllers/Api/ResourceController.cs @@ -2,6 +2,7 @@ namespace LearningHub.Nhs.WebUI.Controllers.Api { using System; using System.Collections.Generic; + using System.Linq; using System.Threading.Tasks; using LearningHub.Nhs.Models.Enums; using LearningHub.Nhs.Models.Resource; @@ -565,9 +566,9 @@ public async Task DeleteResourceProviderAsync(int resourceVersionI /// A representing the asynchronous operation. [HttpPost] [Route("ArchiveResourceFile")] - public ActionResult ArchiveResourceFile(List filePaths) + public ActionResult ArchiveResourceFile(IEnumerable filePaths) { - _ = Task.Run(async () => { await this.fileService.PurgeResourceFile(null, filePaths); }); + _ = Task.Run(async () => { await this.fileService.PurgeResourceFile(null, filePaths.ToList()); }); return this.Ok(); } diff --git a/LearningHub.Nhs.WebUI/Scripts/vuesrc/contribute/Content.vue b/LearningHub.Nhs.WebUI/Scripts/vuesrc/contribute/Content.vue index 154d78e98..00d740bb2 100644 --- a/LearningHub.Nhs.WebUI/Scripts/vuesrc/contribute/Content.vue +++ b/LearningHub.Nhs.WebUI/Scripts/vuesrc/contribute/Content.vue @@ -822,7 +822,7 @@ this.fileUploadRef.value = null; (this.$refs.fileUploader as any).uploadResourceFile(this.file); }, - fileUploadComplete(uploadResult: FileUploadResult) { + async fileUploadComplete(uploadResult: FileUploadResult) { if (!uploadResult.invalid) { if (uploadResult.resourceType != ResourceType.SCORM) { this.$store.commit("setResourceType", uploadResult.resourceType); @@ -841,7 +841,7 @@ } if (this.filePathBeforeFileChange.length > 0) { - this.getResourceFilePath('completed'); + await this.getResourceFilePath('completed'); if (this.filePathBeforeFileChange.length > 0 && this.filePathAfterFileChange.length > 0) { let filePaths = this.filePathBeforeFileChange.filter(item => !this.filePathAfterFileChange.includes(item)); if (filePaths.length > 0) { @@ -1040,6 +1040,7 @@ await resourceData.getObsoleteResourceFile(resource.resourceVersionId).then(response => { if (fileChangeStatus == 'initialised') { this.filePathBeforeFileChange = response; + this.filePathAfterFileChange.length = 0; } else if (fileChangeStatus == 'completed') { this.filePathAfterFileChange = response; diff --git a/LearningHub.Nhs.WebUI/Scripts/vuesrc/data/resource.ts b/LearningHub.Nhs.WebUI/Scripts/vuesrc/data/resource.ts index 9127917d3..817ffcf2f 100644 --- a/LearningHub.Nhs.WebUI/Scripts/vuesrc/data/resource.ts +++ b/LearningHub.Nhs.WebUI/Scripts/vuesrc/data/resource.ts @@ -558,8 +558,8 @@ const getObsoleteResourceFile = async function (id: number): Promise { }; const archiveResourceFile = async function (filepaths: string[]): Promise { - const params = {filePaths:filepaths}; - return await AxiosWrapper.axios.post('/api/Resource/DuplicateBlocks', params).then(() => { + + return await AxiosWrapper.axios.post('/api/Resource/ArchiveResourceFile', filepaths).then(() => { return true }).catch(e => { console.log('archiveResourceFile:' + e); diff --git a/WebAPI/LearningHub.Nhs.API/LearningHub.Nhs.Api.csproj.user b/WebAPI/LearningHub.Nhs.API/LearningHub.Nhs.Api.csproj.user index 696cf1eb7..b4b25c980 100644 --- a/WebAPI/LearningHub.Nhs.API/LearningHub.Nhs.Api.csproj.user +++ b/WebAPI/LearningHub.Nhs.API/LearningHub.Nhs.Api.csproj.user @@ -4,7 +4,7 @@ ProjectDebugger - IIS Local + API IIS ProjectDebugger From 32046d21f3e3a6d944c6fb2f588872eba44ea10a Mon Sep 17 00:00:00 2001 From: Oluwatobi Awe Date: Thu, 22 Aug 2024 06:39:14 +0100 Subject: [PATCH 2/3] case publish error catch --- .../Controllers/Api/ContributeController.cs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs b/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs index 6bfbcca6c..572cd69c9 100644 --- a/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs +++ b/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs @@ -349,11 +349,18 @@ public async Task PublishResourceVersionAsync([FromBody] PublishVi { if (associatedResource.ResourceType != ResourceTypeEnum.Scorm && associatedResource.ResourceType != ResourceTypeEnum.Html) { + try + { var obsoleteFiles = await this.resourceService.GetObsoleteResourceFile(publishViewModel.ResourceVersionId); if (obsoleteFiles != null && obsoleteFiles.Any()) { - await this.fileService.PurgeResourceFile(null, obsoleteFiles); + _ = Task.Run(async () => { await this.fileService.PurgeResourceFile(null, obsoleteFiles); }); } + } + catch (Exception ex) + { + this.Logger.LogError($"File Archive Error: {ex.Message}", $"ResourceVersionId -{publishViewModel.ResourceVersionId}"); + } } } @@ -707,8 +714,8 @@ private async Task RemoveBlockCollectionFiles(int resourceVersionId, BlockCollec { foreach (var oldblock in existingImages) { - var entry = newBlocks.FirstOrDefault(x => x.BlockType == BlockType.Media && x.MediaBlock != null && x.MediaBlock.MediaType == MediaType.Image && x.MediaBlock.Image != null && (x.MediaBlock?.Image?.File?.FileId == oldblock.MediaBlock?.Image?.File?.FileId || x.MediaBlock?.Image?.File?.FilePath == oldblock.MediaBlock?.Image?.File?.FilePath)); - if (entry == null) + var entry = newBlocks.FirstOrDefault(x => x.BlockType == BlockType.Media && x.MediaBlock != null && x.MediaBlock.MediaType == MediaType.Image && x.MediaBlock.Image != null && (x.MediaBlock?.Image?.File?.FileId == oldblock.MediaBlock?.Image?.File?.FileId || x.MediaBlock?.Image?.File?.FilePath == oldblock.MediaBlock?.Image?.File?.FilePath)); + if (entry == null) { filePaths.Add(oldblock?.MediaBlock?.Image?.File?.FilePath); } @@ -790,8 +797,10 @@ private async Task RemoveBlockCollectionFiles(int resourceVersionId, BlockCollec _ = Task.Run(async () => { await this.fileService.PurgeResourceFile(null, deleteList); }); } } - catch + catch (Exception ex) { + var param = new object[] { resourceVersionId, existingResource, newResource }; + this.Logger.LogError($"BlockCollection Archive Error: {ex.Message}", param); } } From 18b9ef38d10f296120278fad124be0a271a278ef Mon Sep 17 00:00:00 2001 From: Oluwatobi Awe Date: Thu, 22 Aug 2024 06:47:43 +0100 Subject: [PATCH 3/3] . --- WebAPI/LearningHub.Nhs.API/LearningHub.Nhs.Api.csproj.user | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WebAPI/LearningHub.Nhs.API/LearningHub.Nhs.Api.csproj.user b/WebAPI/LearningHub.Nhs.API/LearningHub.Nhs.Api.csproj.user index b4b25c980..696cf1eb7 100644 --- a/WebAPI/LearningHub.Nhs.API/LearningHub.Nhs.Api.csproj.user +++ b/WebAPI/LearningHub.Nhs.API/LearningHub.Nhs.Api.csproj.user @@ -4,7 +4,7 @@ ProjectDebugger - API IIS + IIS Local ProjectDebugger