mirror of
https://github.com/Caraxi/mare.server.git
synced 2025-12-13 15:24:14 +01:00
update server to api 11
This commit is contained in:
parent
c21e2f740c
commit
7abe4f9f2e
3 changed files with 53 additions and 49 deletions
2
MareAPI
2
MareAPI
|
|
@ -1 +1 @@
|
|||
Subproject commit 21fe024dfb8cecad466dfc8ceef15040300ad342
|
||||
Subproject commit 374cc31babec9ac37aa21104d7fc02e41cd0d38e
|
||||
|
|
@ -54,41 +54,47 @@ namespace MareSynchronosServer.Hubs
|
|||
}
|
||||
|
||||
[Authorize(AuthenticationSchemes = SecretKeyAuthenticationHandler.AuthScheme)]
|
||||
[HubMethodName(Api.InvokeFileGetFileSize)]
|
||||
public async Task<DownloadFileDto> GetFileSize(string hash)
|
||||
[HubMethodName(Api.InvokeGetFilesSizes)]
|
||||
public async Task<List<DownloadFileDto>> GetFilesSizes(List<string> hashes)
|
||||
{
|
||||
var file = await _dbContext.Files.AsNoTracking().SingleOrDefaultAsync(f => f.Hash == hash);
|
||||
var forbidden = _dbContext.ForbiddenUploadEntries.AsNoTracking().
|
||||
SingleOrDefault(f => f.Hash == hash);
|
||||
var fileInfo = new FileInfo(Path.Combine(BasePath, hash));
|
||||
long fileSize = 0;
|
||||
try
|
||||
var allFiles = await _dbContext.Files.Where(f => hashes.Contains(f.Hash)).ToListAsync();
|
||||
var forbiddenFiles = await _dbContext.ForbiddenUploadEntries.
|
||||
Where(f => hashes.Contains(f.Hash)).ToListAsync();
|
||||
List<DownloadFileDto> response = new();
|
||||
foreach (var hash in hashes)
|
||||
{
|
||||
fileSize = fileInfo.Length;
|
||||
}
|
||||
catch
|
||||
{
|
||||
// file doesn't exist anymore
|
||||
}
|
||||
var fileInfo = new FileInfo(Path.Combine(BasePath, hash));
|
||||
long fileSize = 0;
|
||||
try
|
||||
{
|
||||
fileSize = fileInfo.Length;
|
||||
}
|
||||
catch
|
||||
{
|
||||
// file doesn't exist anymore
|
||||
}
|
||||
|
||||
var response = new DownloadFileDto
|
||||
{
|
||||
FileExists = fileInfo.Exists,
|
||||
ForbiddenBy = forbidden?.ForbiddenBy ?? string.Empty,
|
||||
IsForbidden = forbidden != null,
|
||||
Hash = hash,
|
||||
Size = fileSize,
|
||||
Url = _configuration["CdnFullUrl"] + hash.ToUpperInvariant()
|
||||
};
|
||||
var forbiddenFile = forbiddenFiles.SingleOrDefault(f => f.Hash == hash);
|
||||
var downloadFile = allFiles.SingleOrDefault(f => f.Hash == hash);
|
||||
|
||||
if (!fileInfo.Exists && file != null)
|
||||
{
|
||||
_dbContext.Files.Remove(file);
|
||||
await _dbContext.SaveChangesAsync();
|
||||
response.Add(new DownloadFileDto
|
||||
{
|
||||
FileExists = fileInfo.Exists,
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
[Authorize(AuthenticationSchemes = SecretKeyAuthenticationHandler.AuthScheme)]
|
||||
|
|
|
|||
|
|
@ -205,39 +205,37 @@ namespace MareSynchronosServer.Hubs
|
|||
|
||||
[Authorize(AuthenticationSchemes = SecretKeyAuthenticationHandler.AuthScheme)]
|
||||
[HubMethodName(Api.SendUserPairedClientPauseChange)]
|
||||
public async Task SendPairedClientPauseChange(string uid, bool isPaused)
|
||||
public async Task SendPairedClientPauseChange(string otherUserUid, bool isPaused)
|
||||
{
|
||||
if (uid == AuthenticatedUserId) return;
|
||||
var user = await _dbContext.Users.AsNoTracking()
|
||||
.SingleAsync(u => u.UID == AuthenticatedUserId);
|
||||
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);
|
||||
if (otherUserUid == AuthenticatedUserId) return;
|
||||
ClientPair pair = await _dbContext.ClientPairs.SingleOrDefaultAsync(w => w.UserUID == AuthenticatedUserId && w.OtherUserUID == otherUserUid);
|
||||
if (pair == null) return;
|
||||
|
||||
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()
|
||||
{
|
||||
OtherUID = otherUser.UID,
|
||||
OtherUID = otherUserUid,
|
||||
IsPaused = isPaused,
|
||||
IsPausedFromOthers = otherEntry?.IsPaused ?? false,
|
||||
IsSynced = otherEntry != null
|
||||
}, otherUser.CharacterIdentification);
|
||||
}, otherCharaIdent);
|
||||
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,
|
||||
IsPausedFromOthers = isPaused,
|
||||
IsSynced = true
|
||||
}, user.CharacterIdentification);
|
||||
}, selfCharaIdent);
|
||||
}
|
||||
|
||||
if (isPaused)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue