implement RestoreThenUpload for charadata

This commit is contained in:
Stanley Dimant
2025-02-08 00:14:16 +01:00
parent 5e4451fc9e
commit 1d9bb90976
3 changed files with 46 additions and 3 deletions

View File

@@ -621,8 +621,29 @@ public sealed partial class CharaDataManager : DisposableMediatorSubscriberBase
var hasDto = _ownCharaData.TryGetValue(id, out var dto);
if (!hasDto || dto == null) return;
var missingFileList = dto.MissingFiles.ToList();
UiBlockingComputation = UploadTask = UploadFiles(missingFileList, async () =>
UiBlockingComputation = UploadTask = RestoreThenUpload(dto);
}
private async Task<(string Output, bool Success)> RestoreThenUpload(CharaDataFullExtendedDto dto)
{
var newDto = await _apiController.CharaDataAttemptRestore(dto.Id).ConfigureAwait(false);
if (newDto == null)
{
_ownCharaData.Remove(dto.Id);
_metaInfoCache.Remove(dto.FullId, out _);
return ("No such DTO found", false);
}
await AddOrUpdateDto(newDto).ConfigureAwait(false);
_ = _ownCharaData.TryGetValue(dto.Id, out var extendedDto);
if (!extendedDto!.HasMissingFiles)
{
return ("Restored successfully", true);
}
var missingFileList = extendedDto!.MissingFiles.ToList();
return await UploadFiles(missingFileList, async () =>
{
var newFilePaths = dto.FileGamePaths;
foreach (var missing in missingFileList)
@@ -635,7 +656,7 @@ public sealed partial class CharaDataManager : DisposableMediatorSubscriberBase
};
var res = await _apiController.CharaDataUpdate(updateDto).ConfigureAwait(false);
await AddOrUpdateDto(res).ConfigureAwait(false);
});
}).ConfigureAwait(false);
}
internal void ApplyDataToSelf(CharaDataFullExtendedDto dataDto)

View File

@@ -84,6 +84,11 @@ internal sealed partial class CharaDataHubUi
}
});
}
else if (_charaDataManager.UploadTask?.IsCompleted ?? false)
{
var color = UiSharedService.GetBoolColor(_charaDataManager.UploadTask.Result.Success);
UiSharedService.ColorTextWrapped(_charaDataManager.UploadTask.Result.Output, color);
}
});
}
indent.Dispose();

View File

@@ -1,5 +1,6 @@
using MareSynchronos.API.Data;
using MareSynchronos.API.Dto.CharaData;
using MareSynchronos.Services.CharaData.Models;
using Microsoft.AspNetCore.SignalR.Client;
using Microsoft.Extensions.Logging;
@@ -70,6 +71,22 @@ public partial class ApiController
}
}
public async Task<CharaDataFullDto?> CharaDataAttemptRestore(string id)
{
if (!IsConnected) return null;
try
{
Logger.LogDebug("Attempting to restore chara data {id}", id);
return await _mareHub!.InvokeAsync<CharaDataFullDto?>(nameof(CharaDataAttemptRestore), id).ConfigureAwait(false);
}
catch (Exception ex)
{
Logger.LogWarning(ex, "Failed to restore chara data for {id}", id);
return null;
}
}
public async Task<List<CharaDataFullDto>> CharaDataGetOwn()
{
if (!IsConnected) return [];