 14575a4a6b
			
		
	
	14575a4a6b
	
	
	
		
			
			* add jwt expiry * start of 0.9 api impl * some stuff idk * some more impl * some cleanup * remove grouppair, add configuration, rework some pair drawing stuff * do some stuff * rework some ui * I don't even know anymore * add cancellationtoken * token bla * ui fixes etc * probably individual adding/removing now working fully as expected * add working report popup * I guess it's more syncshell shit or so * popup shit idk * work out most of the syncshell bullshit I guess * delete some old crap * are we actually getting closer to the end * update pair info stuff * more fixes/adjustments, idk * refactor some things * some rework * some more cleanup * cleanup * make menu buttons w i d e * better icon text buttons * add all syncshell folder and ordering fixes --------- Co-authored-by: rootdarkarchon <root.darkarchon@outlook.com>
		
			
				
	
	
		
			117 lines
		
	
	
		
			4.1 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			117 lines
		
	
	
		
			4.1 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| using MareSynchronos.API.Data;
 | |
| using MareSynchronos.API.Dto;
 | |
| using MareSynchronos.API.Dto.User;
 | |
| using Microsoft.AspNetCore.SignalR.Client;
 | |
| using Microsoft.Extensions.Logging;
 | |
| using System.Text;
 | |
| 
 | |
| namespace MareSynchronos.WebAPI;
 | |
| 
 | |
| #pragma warning disable MA0040
 | |
| public partial class ApiController
 | |
| {
 | |
|     public async Task PushCharacterData(CharacterData data, List<UserData> visibleCharacters)
 | |
|     {
 | |
|         if (!IsConnected) return;
 | |
| 
 | |
|         try
 | |
|         {
 | |
|             await PushCharacterDataInternal(data, [.. visibleCharacters]).ConfigureAwait(false);
 | |
|         }
 | |
|         catch (OperationCanceledException)
 | |
|         {
 | |
|             Logger.LogDebug("Upload operation was cancelled");
 | |
|         }
 | |
|         catch (Exception ex)
 | |
|         {
 | |
|             Logger.LogWarning(ex, "Error during upload of files");
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     public async Task UserAddPair(UserDto user)
 | |
|     {
 | |
|         if (!IsConnected) return;
 | |
|         await _mareHub!.SendAsync(nameof(UserAddPair), user).ConfigureAwait(false);
 | |
|     }
 | |
| 
 | |
|     public async Task UserDelete()
 | |
|     {
 | |
|         CheckConnection();
 | |
|         await _mareHub!.SendAsync(nameof(UserDelete)).ConfigureAwait(false);
 | |
|         await CreateConnections().ConfigureAwait(false);
 | |
|     }
 | |
| 
 | |
|     public async Task<List<OnlineUserIdentDto>> UserGetOnlinePairs()
 | |
|     {
 | |
|         return await _mareHub!.InvokeAsync<List<OnlineUserIdentDto>>(nameof(UserGetOnlinePairs)).ConfigureAwait(false);
 | |
|     }
 | |
| 
 | |
|     public async Task<List<UserFullPairDto>> UserGetPairedClients()
 | |
|     {
 | |
|         return await _mareHub!.InvokeAsync<List<UserFullPairDto>>(nameof(UserGetPairedClients)).ConfigureAwait(false);
 | |
|     }
 | |
| 
 | |
|     public async Task<UserProfileDto> UserGetProfile(UserDto dto)
 | |
|     {
 | |
|         if (!IsConnected) return new UserProfileDto(dto.User, Disabled: false, IsNSFW: null, ProfilePictureBase64: null, Description: null);
 | |
|         return await _mareHub!.InvokeAsync<UserProfileDto>(nameof(UserGetProfile), dto).ConfigureAwait(false);
 | |
|     }
 | |
| 
 | |
|     public async Task UserPushData(UserCharaDataMessageDto dto)
 | |
|     {
 | |
|         try
 | |
|         {
 | |
|             await _mareHub!.InvokeAsync(nameof(UserPushData), dto).ConfigureAwait(false);
 | |
|         }
 | |
|         catch (Exception ex)
 | |
|         {
 | |
|             Logger.LogWarning(ex, "Failed to Push character data");
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     public async Task UserRemovePair(UserDto userDto)
 | |
|     {
 | |
|         if (!IsConnected) return;
 | |
|         await _mareHub!.SendAsync(nameof(UserRemovePair), userDto).ConfigureAwait(false);
 | |
|     }
 | |
| 
 | |
|     public async Task UserReportProfile(UserProfileReportDto userDto)
 | |
|     {
 | |
|         if (!IsConnected) return;
 | |
|         await _mareHub!.SendAsync(nameof(UserReportProfile), userDto).ConfigureAwait(false);
 | |
|     }
 | |
| 
 | |
|     public async Task UserSetPairPermissions(UserPermissionsDto userPermissions)
 | |
|     {
 | |
|         await _mareHub!.SendAsync(nameof(UserSetPairPermissions), userPermissions).ConfigureAwait(false);
 | |
|     }
 | |
| 
 | |
|     public async Task UserSetProfile(UserProfileDto userDescription)
 | |
|     {
 | |
|         if (!IsConnected) return;
 | |
|         await _mareHub!.InvokeAsync(nameof(UserSetProfile), userDescription).ConfigureAwait(false);
 | |
|     }
 | |
| 
 | |
|     public async Task UserUpdateDefaultPermissions(DefaultPermissionsDto defaultPermissionsDto)
 | |
|     {
 | |
|         CheckConnection();
 | |
|         await _mareHub!.InvokeAsync(nameof(UserUpdateDefaultPermissions), defaultPermissionsDto).ConfigureAwait(false);
 | |
|     }
 | |
| 
 | |
|     private async Task PushCharacterDataInternal(CharacterData character, List<UserData> visibleCharacters)
 | |
|     {
 | |
|         Logger.LogInformation("Pushing character data for {hash} to {charas}", character.DataHash.Value, string.Join(", ", visibleCharacters.Select(c => c.AliasOrUID)));
 | |
|         StringBuilder sb = new();
 | |
|         foreach (var kvp in character.FileReplacements.ToList())
 | |
|         {
 | |
|             sb.AppendLine($"FileReplacements for {kvp.Key}: {kvp.Value.Count}");
 | |
|         }
 | |
|         foreach (var item in character.GlamourerData)
 | |
|         {
 | |
|             sb.AppendLine($"GlamourerData for {item.Key}: {!string.IsNullOrEmpty(item.Value)}");
 | |
|         }
 | |
|         Logger.LogDebug("Chara data contained: {nl} {data}", Environment.NewLine, sb.ToString());
 | |
|         await UserPushData(new(visibleCharacters, character)).ConfigureAwait(false);
 | |
|     }
 | |
| }
 | |
| #pragma warning restore MA0040 |