update blabla

This commit is contained in:
Stanley Dimant
2022-07-31 17:32:15 +02:00
parent 641ad52313
commit 8939585c3c
7 changed files with 80 additions and 35 deletions

View File

@@ -53,32 +53,6 @@ namespace MareSynchronosServer.Hubs
await _dbContext.SaveChangesAsync();
}
[Authorize(AuthenticationSchemes = SecretKeyAuthenticationHandler.AuthScheme)]
[HubMethodName(Api.StreamFileDownloadFileAsync)]
public async IAsyncEnumerable<byte[]> DownloadFileAsync(string hash, [EnumeratorCancellation] CancellationToken ct)
{
_logger.LogInformation("User " + AuthenticatedUserId + " downloading file: " + hash);
var file = _dbContext.Files.AsNoTracking()
.SingleOrDefault(f => f.Hash == hash);
if (file == null) yield break;
var chunkSize = 1024 * 512; // 512kb
int readByteCount;
var buffer = new byte[chunkSize];
var path = Path.Combine(BasePath, hash);
await using var fs = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read);
while ((readByteCount = fs.Read(buffer, 0, chunkSize)) > 0)
{
yield return readByteCount == chunkSize ? buffer.ToArray() : buffer.Take(readByteCount).ToArray();
}
_logger.LogInformation("User " + AuthenticatedUserId + " finished downloading file: " + hash);
MareMetrics.UserDownloadedFiles.Inc();
MareMetrics.UserDownloadedFilesSize.Inc(new FileInfo(path).Length);
}
[Authorize(AuthenticationSchemes = SecretKeyAuthenticationHandler.AuthScheme)]
[HubMethodName(Api.InvokeFileGetFileSize)]
public async Task<DownloadFileDto> GetFileSize(string hash)

View File

@@ -26,6 +26,7 @@ namespace MareSynchronosServer.Hubs
string userid = AuthenticatedUserId;
var userEntry = await _dbContext.Users.SingleAsync(u => u.UID == userid);
var ownPairData = await _dbContext.ClientPairs.Where(u => u.User.UID == userid).ToListAsync();
var auth = await _dbContext.Auth.SingleAsync(u => u.UserUID == userid);
MareMetrics.Pairs.Dec(ownPairData.Count);
MareMetrics.PairsPaused.Dec(ownPairData.Count(c => c.IsPaused));
@@ -50,6 +51,7 @@ namespace MareSynchronosServer.Hubs
_dbContext.RemoveRange(otherPairData);
_dbContext.Remove(userEntry);
_dbContext.Remove(auth);
await _dbContext.SaveChangesAsync();
}

View File

@@ -41,7 +41,7 @@ namespace MareSynchronosServer.Hubs
var isBanned = await _dbContext.BannedUsers.AsNoTracking().AnyAsync(u => u.CharacterIdentification == characterIdentification);
if (userId != null && !isBanned && !string.IsNullOrEmpty(characterIdentification))
if (!string.IsNullOrEmpty(userId) && !isBanned && !string.IsNullOrEmpty(characterIdentification))
{
_logger.LogInformation("Connection from " + userId);
var user = (await _dbContext.Users.SingleAsync(u => u.UID == userId));
@@ -52,8 +52,11 @@ namespace MareSynchronosServer.Hubs
ServerVersion = Api.Version
};
}
else if (string.IsNullOrEmpty(user.CharacterIdentification))
{
MareMetrics.AuthorizedConnections.Inc();
}
MareMetrics.AuthorizedConnections.Inc();
user.LastLoggedIn = DateTime.UtcNow;
user.CharacterIdentification = characterIdentification;
await _dbContext.SaveChangesAsync();
@@ -109,9 +112,6 @@ namespace MareSynchronosServer.Hubs
(await _dbContext.Users.SingleAsync(u => u.UID == AuthenticatedUserId)).CharacterIdentification = null;
await _dbContext.SaveChangesAsync();
await Clients.All.SendAsync("UsersOnline",
await _dbContext.Users.CountAsync(u => !string.IsNullOrEmpty(u.CharacterIdentification)));
}
await base.OnDisconnectedAsync(exception);