Skip to content

Commit 1d433db

Browse files
authored
Merge pull request #540 from TechnologyEnhancedLearning/Develop/Fixes/TD-4226
TD-4226 AMS storage additional bugs
2 parents c3fcb9d + 18b9ef3 commit 1d433db

File tree

4 files changed

+21
-10
lines changed

4 files changed

+21
-10
lines changed

LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -349,11 +349,18 @@ public async Task<ActionResult> PublishResourceVersionAsync([FromBody] PublishVi
349349
{
350350
if (associatedResource.ResourceType != ResourceTypeEnum.Scorm && associatedResource.ResourceType != ResourceTypeEnum.Html)
351351
{
352+
try
353+
{
352354
var obsoleteFiles = await this.resourceService.GetObsoleteResourceFile(publishViewModel.ResourceVersionId);
353355
if (obsoleteFiles != null && obsoleteFiles.Any())
354356
{
355-
await this.fileService.PurgeResourceFile(null, obsoleteFiles);
357+
_ = Task.Run(async () => { await this.fileService.PurgeResourceFile(null, obsoleteFiles); });
356358
}
359+
}
360+
catch (Exception ex)
361+
{
362+
this.Logger.LogError($"File Archive Error: {ex.Message}", $"ResourceVersionId -{publishViewModel.ResourceVersionId}");
363+
}
357364
}
358365
}
359366

@@ -707,8 +714,8 @@ private async Task RemoveBlockCollectionFiles(int resourceVersionId, BlockCollec
707714
{
708715
foreach (var oldblock in existingImages)
709716
{
710-
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));
711-
if (entry == null)
717+
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));
718+
if (entry == null)
712719
{
713720
filePaths.Add(oldblock?.MediaBlock?.Image?.File?.FilePath);
714721
}
@@ -790,8 +797,10 @@ private async Task RemoveBlockCollectionFiles(int resourceVersionId, BlockCollec
790797
_ = Task.Run(async () => { await this.fileService.PurgeResourceFile(null, deleteList); });
791798
}
792799
}
793-
catch
800+
catch (Exception ex)
794801
{
802+
var param = new object[] { resourceVersionId, existingResource, newResource };
803+
this.Logger.LogError($"BlockCollection Archive Error: {ex.Message}", param);
795804
}
796805
}
797806

LearningHub.Nhs.WebUI/Controllers/Api/ResourceController.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ namespace LearningHub.Nhs.WebUI.Controllers.Api
22
{
33
using System;
44
using System.Collections.Generic;
5+
using System.Linq;
56
using System.Threading.Tasks;
67
using LearningHub.Nhs.Models.Enums;
78
using LearningHub.Nhs.Models.Resource;
@@ -565,9 +566,9 @@ public async Task<ActionResult> DeleteResourceProviderAsync(int resourceVersionI
565566
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
566567
[HttpPost]
567568
[Route("ArchiveResourceFile")]
568-
public ActionResult ArchiveResourceFile(List<string> filePaths)
569+
public ActionResult ArchiveResourceFile(IEnumerable<string> filePaths)
569570
{
570-
_ = Task.Run(async () => { await this.fileService.PurgeResourceFile(null, filePaths); });
571+
_ = Task.Run(async () => { await this.fileService.PurgeResourceFile(null, filePaths.ToList()); });
571572
return this.Ok();
572573
}
573574

LearningHub.Nhs.WebUI/Scripts/vuesrc/contribute/Content.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,7 @@
822822
this.fileUploadRef.value = null;
823823
(this.$refs.fileUploader as any).uploadResourceFile(this.file);
824824
},
825-
fileUploadComplete(uploadResult: FileUploadResult) {
825+
async fileUploadComplete(uploadResult: FileUploadResult) {
826826
if (!uploadResult.invalid) {
827827
if (uploadResult.resourceType != ResourceType.SCORM) {
828828
this.$store.commit("setResourceType", uploadResult.resourceType);
@@ -841,7 +841,7 @@
841841
}
842842
843843
if (this.filePathBeforeFileChange.length > 0) {
844-
this.getResourceFilePath('completed');
844+
await this.getResourceFilePath('completed');
845845
if (this.filePathBeforeFileChange.length > 0 && this.filePathAfterFileChange.length > 0) {
846846
let filePaths = this.filePathBeforeFileChange.filter(item => !this.filePathAfterFileChange.includes(item));
847847
if (filePaths.length > 0) {
@@ -1040,6 +1040,7 @@
10401040
await resourceData.getObsoleteResourceFile(resource.resourceVersionId).then(response => {
10411041
if (fileChangeStatus == 'initialised') {
10421042
this.filePathBeforeFileChange = response;
1043+
this.filePathAfterFileChange.length = 0;
10431044
}
10441045
else if (fileChangeStatus == 'completed') {
10451046
this.filePathAfterFileChange = response;

LearningHub.Nhs.WebUI/Scripts/vuesrc/data/resource.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -558,8 +558,8 @@ const getObsoleteResourceFile = async function (id: number): Promise<string[]> {
558558
};
559559

560560
const archiveResourceFile = async function (filepaths: string[]): Promise<boolean> {
561-
const params = {filePaths:filepaths};
562-
return await AxiosWrapper.axios.post('/api/Resource/DuplicateBlocks', params).then(() => {
561+
562+
return await AxiosWrapper.axios.post('/api/Resource/ArchiveResourceFile', filepaths).then(() => {
563563
return true
564564
}).catch(e => {
565565
console.log('archiveResourceFile:' + e);

0 commit comments

Comments
 (0)