feat: add E2EE DMs, group chats, local serversettings.json, and security/perf fixes
This commit is contained in:
parent
b60b5a0774
commit
3b52de20d1
33 changed files with 5107 additions and 366 deletions
|
|
@ -29,7 +29,30 @@ public class FileStorageService
|
|||
string originalFileName,
|
||||
string contentType,
|
||||
Stream stream,
|
||||
long length)
|
||||
long length,
|
||||
string uploaderRole = UserRoles.Member)
|
||||
{
|
||||
var (record, _) = await StoreFileWithMessageAsync(
|
||||
channelId,
|
||||
uploaderId,
|
||||
uploaderUsername,
|
||||
originalFileName,
|
||||
contentType,
|
||||
stream,
|
||||
length,
|
||||
uploaderRole);
|
||||
return record;
|
||||
}
|
||||
|
||||
public async Task<(FileRecord Record, ChatMessage Message)> StoreFileWithMessageAsync(
|
||||
string channelId,
|
||||
string uploaderId,
|
||||
string uploaderUsername,
|
||||
string originalFileName,
|
||||
string contentType,
|
||||
Stream stream,
|
||||
long length,
|
||||
string uploaderRole = UserRoles.Member)
|
||||
{
|
||||
long maxBytes = _options.MaxFileSizeMb * 1024 * 1024;
|
||||
if (length > maxBytes)
|
||||
|
|
@ -73,6 +96,7 @@ public class FileStorageService
|
|||
sha256Hex = Convert.ToHexString(sha256.Hash ?? Array.Empty<byte>());
|
||||
}
|
||||
|
||||
var now = DateTime.UtcNow;
|
||||
var record = new FileRecord
|
||||
{
|
||||
Id = fileId,
|
||||
|
|
@ -84,7 +108,7 @@ public class FileStorageService
|
|||
FileSizeBytes = writtenBytes,
|
||||
StoragePath = diskFilePath,
|
||||
Sha256Checksum = sha256Hex,
|
||||
CreatedAt = DateTime.UtcNow
|
||||
CreatedAt = now
|
||||
};
|
||||
|
||||
await _db.SaveFileRecordAsync(record);
|
||||
|
|
@ -95,15 +119,16 @@ public class FileStorageService
|
|||
ChannelId = channelId,
|
||||
SenderId = uploaderId,
|
||||
SenderUsername = uploaderUsername,
|
||||
SenderRole = string.IsNullOrWhiteSpace(uploaderRole) ? UserRoles.Member : uploaderRole,
|
||||
Content = $"Shared file: {safeName} ({FormatBytes(writtenBytes)})",
|
||||
CreatedAt = DateTime.UtcNow,
|
||||
CreatedAt = now,
|
||||
AttachmentId = record.Id,
|
||||
AttachmentName = safeName,
|
||||
AttachmentSizeBytes = writtenBytes
|
||||
};
|
||||
await _db.SaveMessageAsync(msg);
|
||||
|
||||
return record;
|
||||
return (record, msg);
|
||||
}
|
||||
|
||||
public async Task<FileRecord?> GetFileRecordAsync(string fileId)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue