implement RestoreThenUpload for charadata
This commit is contained in:
@@ -621,8 +621,29 @@ public sealed partial class CharaDataManager : DisposableMediatorSubscriberBase
|
|||||||
var hasDto = _ownCharaData.TryGetValue(id, out var dto);
|
var hasDto = _ownCharaData.TryGetValue(id, out var dto);
|
||||||
if (!hasDto || dto == null) return;
|
if (!hasDto || dto == null) return;
|
||||||
|
|
||||||
var missingFileList = dto.MissingFiles.ToList();
|
UiBlockingComputation = UploadTask = RestoreThenUpload(dto);
|
||||||
UiBlockingComputation = UploadTask = UploadFiles(missingFileList, async () =>
|
}
|
||||||
|
|
||||||
|
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;
|
var newFilePaths = dto.FileGamePaths;
|
||||||
foreach (var missing in missingFileList)
|
foreach (var missing in missingFileList)
|
||||||
@@ -635,7 +656,7 @@ public sealed partial class CharaDataManager : DisposableMediatorSubscriberBase
|
|||||||
};
|
};
|
||||||
var res = await _apiController.CharaDataUpdate(updateDto).ConfigureAwait(false);
|
var res = await _apiController.CharaDataUpdate(updateDto).ConfigureAwait(false);
|
||||||
await AddOrUpdateDto(res).ConfigureAwait(false);
|
await AddOrUpdateDto(res).ConfigureAwait(false);
|
||||||
});
|
}).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void ApplyDataToSelf(CharaDataFullExtendedDto dataDto)
|
internal void ApplyDataToSelf(CharaDataFullExtendedDto dataDto)
|
||||||
|
|||||||
@@ -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();
|
indent.Dispose();
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using MareSynchronos.API.Data;
|
using MareSynchronos.API.Data;
|
||||||
using MareSynchronos.API.Dto.CharaData;
|
using MareSynchronos.API.Dto.CharaData;
|
||||||
|
using MareSynchronos.Services.CharaData.Models;
|
||||||
using Microsoft.AspNetCore.SignalR.Client;
|
using Microsoft.AspNetCore.SignalR.Client;
|
||||||
using Microsoft.Extensions.Logging;
|
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()
|
public async Task<List<CharaDataFullDto>> CharaDataGetOwn()
|
||||||
{
|
{
|
||||||
if (!IsConnected) return [];
|
if (!IsConnected) return [];
|
||||||
|
|||||||
Reference in New Issue
Block a user