Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -349,11 +349,18 @@ public async Task<ActionResult> 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}");
}
}
}

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
}

Expand Down
5 changes: 3 additions & 2 deletions LearningHub.Nhs.WebUI/Controllers/Api/ResourceController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -565,9 +566,9 @@ public async Task<ActionResult> DeleteResourceProviderAsync(int resourceVersionI
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
[HttpPost]
[Route("ArchiveResourceFile")]
public ActionResult ArchiveResourceFile(List<string> filePaths)
public ActionResult ArchiveResourceFile(IEnumerable<string> filePaths)
{
_ = Task.Run(async () => { await this.fileService.PurgeResourceFile(null, filePaths); });
_ = Task.Run(async () => { await this.fileService.PurgeResourceFile(null, filePaths.ToList()); });
return this.Ok();
}

Expand Down
5 changes: 3 additions & 2 deletions LearningHub.Nhs.WebUI/Scripts/vuesrc/contribute/Content.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions LearningHub.Nhs.WebUI/Scripts/vuesrc/data/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -558,8 +558,8 @@ const getObsoleteResourceFile = async function (id: number): Promise<string[]> {
};

const archiveResourceFile = async function (filepaths: string[]): Promise<boolean> {
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);
Expand Down