update server to api 11
This commit is contained in:
2
MareAPI
2
MareAPI
Submodule MareAPI updated: 21fe024dfb...374cc31bab
@@ -54,41 +54,47 @@ namespace MareSynchronosServer.Hubs
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Authorize(AuthenticationSchemes = SecretKeyAuthenticationHandler.AuthScheme)]
|
[Authorize(AuthenticationSchemes = SecretKeyAuthenticationHandler.AuthScheme)]
|
||||||
[HubMethodName(Api.InvokeFileGetFileSize)]
|
[HubMethodName(Api.InvokeGetFilesSizes)]
|
||||||
public async Task<DownloadFileDto> GetFileSize(string hash)
|
public async Task<List<DownloadFileDto>> GetFilesSizes(List<string> hashes)
|
||||||
{
|
{
|
||||||
var file = await _dbContext.Files.AsNoTracking().SingleOrDefaultAsync(f => f.Hash == hash);
|
var allFiles = await _dbContext.Files.Where(f => hashes.Contains(f.Hash)).ToListAsync();
|
||||||
var forbidden = _dbContext.ForbiddenUploadEntries.AsNoTracking().
|
var forbiddenFiles = await _dbContext.ForbiddenUploadEntries.
|
||||||
SingleOrDefault(f => f.Hash == hash);
|
Where(f => hashes.Contains(f.Hash)).ToListAsync();
|
||||||
var fileInfo = new FileInfo(Path.Combine(BasePath, hash));
|
List<DownloadFileDto> response = new();
|
||||||
long fileSize = 0;
|
foreach (var hash in hashes)
|
||||||
try
|
|
||||||
{
|
{
|
||||||
fileSize = fileInfo.Length;
|
var fileInfo = new FileInfo(Path.Combine(BasePath, hash));
|
||||||
}
|
long fileSize = 0;
|
||||||
catch
|
try
|
||||||
{
|
{
|
||||||
// file doesn't exist anymore
|
fileSize = fileInfo.Length;
|
||||||
}
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// file doesn't exist anymore
|
||||||
|
}
|
||||||
|
|
||||||
var response = new DownloadFileDto
|
var forbiddenFile = forbiddenFiles.SingleOrDefault(f => f.Hash == hash);
|
||||||
{
|
var downloadFile = allFiles.SingleOrDefault(f => f.Hash == hash);
|
||||||
FileExists = fileInfo.Exists,
|
|
||||||
ForbiddenBy = forbidden?.ForbiddenBy ?? string.Empty,
|
|
||||||
IsForbidden = forbidden != null,
|
|
||||||
Hash = hash,
|
|
||||||
Size = fileSize,
|
|
||||||
Url = _configuration["CdnFullUrl"] + hash.ToUpperInvariant()
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!fileInfo.Exists && file != null)
|
response.Add(new DownloadFileDto
|
||||||
{
|
{
|
||||||
_dbContext.Files.Remove(file);
|
FileExists = fileInfo.Exists,
|
||||||
await _dbContext.SaveChangesAsync();
|
ForbiddenBy = forbiddenFile?.ForbiddenBy ?? string.Empty,
|
||||||
|
IsForbidden = forbiddenFile != null,
|
||||||
|
Hash = hash,
|
||||||
|
Size = fileSize,
|
||||||
|
Url = _configuration["CdnFullUrl"] + hash.ToUpperInvariant()
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!fileInfo.Exists && downloadFile != null)
|
||||||
|
{
|
||||||
|
_dbContext.Files.Remove(downloadFile);
|
||||||
|
await _dbContext.SaveChangesAsync();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Authorize(AuthenticationSchemes = SecretKeyAuthenticationHandler.AuthScheme)]
|
[Authorize(AuthenticationSchemes = SecretKeyAuthenticationHandler.AuthScheme)]
|
||||||
|
|||||||
@@ -205,39 +205,37 @@ namespace MareSynchronosServer.Hubs
|
|||||||
|
|
||||||
[Authorize(AuthenticationSchemes = SecretKeyAuthenticationHandler.AuthScheme)]
|
[Authorize(AuthenticationSchemes = SecretKeyAuthenticationHandler.AuthScheme)]
|
||||||
[HubMethodName(Api.SendUserPairedClientPauseChange)]
|
[HubMethodName(Api.SendUserPairedClientPauseChange)]
|
||||||
public async Task SendPairedClientPauseChange(string uid, bool isPaused)
|
public async Task SendPairedClientPauseChange(string otherUserUid, bool isPaused)
|
||||||
{
|
{
|
||||||
if (uid == AuthenticatedUserId) return;
|
if (otherUserUid == AuthenticatedUserId) return;
|
||||||
var user = await _dbContext.Users.AsNoTracking()
|
ClientPair pair = await _dbContext.ClientPairs.SingleOrDefaultAsync(w => w.UserUID == AuthenticatedUserId && w.OtherUserUID == otherUserUid);
|
||||||
.SingleAsync(u => u.UID == AuthenticatedUserId);
|
if (pair == null) return;
|
||||||
var otherUser = await _dbContext.Users.AsNoTracking()
|
|
||||||
.SingleOrDefaultAsync(u => u.UID == uid);
|
|
||||||
if (otherUser == null) return;
|
|
||||||
_logger.LogInformation("User " + AuthenticatedUserId + " changed pause status with " + uid + " to " + isPaused);
|
|
||||||
ClientPair wl =
|
|
||||||
await _dbContext.ClientPairs.SingleOrDefaultAsync(w => w.User == user && w.OtherUser == otherUser);
|
|
||||||
wl.IsPaused = isPaused;
|
|
||||||
_dbContext.Update(wl);
|
|
||||||
await _dbContext.SaveChangesAsync();
|
|
||||||
var otherEntry = OppositeEntry(uid);
|
|
||||||
|
|
||||||
await Clients.User(user.UID)
|
_logger.LogInformation("User " + AuthenticatedUserId + " changed pause status with " + otherUserUid + " to " + isPaused);
|
||||||
|
pair.IsPaused = isPaused;
|
||||||
|
_dbContext.Update(pair);
|
||||||
|
await _dbContext.SaveChangesAsync();
|
||||||
|
var selfCharaIdent = (await _dbContext.Users.SingleAsync(u => u.UID == AuthenticatedUserId)).CharacterIdentification;
|
||||||
|
var otherCharaIdent = (await _dbContext.Users.SingleAsync(u => u.UID == otherUserUid)).CharacterIdentification;
|
||||||
|
var otherEntry = OppositeEntry(otherUserUid);
|
||||||
|
|
||||||
|
await Clients.User(AuthenticatedUserId)
|
||||||
.SendAsync(Api.OnUserUpdateClientPairs, new ClientPairDto()
|
.SendAsync(Api.OnUserUpdateClientPairs, new ClientPairDto()
|
||||||
{
|
{
|
||||||
OtherUID = otherUser.UID,
|
OtherUID = otherUserUid,
|
||||||
IsPaused = isPaused,
|
IsPaused = isPaused,
|
||||||
IsPausedFromOthers = otherEntry?.IsPaused ?? false,
|
IsPausedFromOthers = otherEntry?.IsPaused ?? false,
|
||||||
IsSynced = otherEntry != null
|
IsSynced = otherEntry != null
|
||||||
}, otherUser.CharacterIdentification);
|
}, otherCharaIdent);
|
||||||
if (otherEntry != null)
|
if (otherEntry != null)
|
||||||
{
|
{
|
||||||
await Clients.User(uid).SendAsync(Api.OnUserUpdateClientPairs, new ClientPairDto()
|
await Clients.User(otherUserUid).SendAsync(Api.OnUserUpdateClientPairs, new ClientPairDto()
|
||||||
{
|
{
|
||||||
OtherUID = user.UID,
|
OtherUID = AuthenticatedUserId,
|
||||||
IsPaused = otherEntry.IsPaused,
|
IsPaused = otherEntry.IsPaused,
|
||||||
IsPausedFromOthers = isPaused,
|
IsPausedFromOthers = isPaused,
|
||||||
IsSynced = true
|
IsSynced = true
|
||||||
}, user.CharacterIdentification);
|
}, selfCharaIdent);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isPaused)
|
if (isPaused)
|
||||||
|
|||||||
Reference in New Issue
Block a user