mirror of
https://github.com/Stone-Red-Code/EchoHub.git
synced 2026-09-04 09:06:07 +02:00
- Created User, Channel, Message, and ServerInfo models with necessary properties. - Added DTOs for user profiles, server information, and message handling. - Implemented JWT authentication service for user login and token generation. - Developed Entity Framework Core DbContext for database interactions. - Introduced SignalR ChatHub for real-time messaging and presence tracking. - Implemented file storage and image to ASCII conversion services. - Set up CORS and middleware for API endpoints. - Created launch settings and development configuration for server and web projects.
47 lines
1.2 KiB
C#
47 lines
1.2 KiB
C#
namespace EchoHub.Server.Services;
|
|
|
|
public class FileStorageService
|
|
{
|
|
private readonly string _storagePath;
|
|
|
|
public FileStorageService(IConfiguration configuration)
|
|
{
|
|
_storagePath = configuration["Storage:Path"] ?? "./uploads";
|
|
|
|
if (!Directory.Exists(_storagePath))
|
|
{
|
|
Directory.CreateDirectory(_storagePath);
|
|
}
|
|
}
|
|
|
|
public async Task<(string fileId, string filePath)> SaveFileAsync(Stream stream, string fileName)
|
|
{
|
|
var fileId = Guid.NewGuid().ToString();
|
|
var extension = Path.GetExtension(fileName);
|
|
var storedFileName = $"{fileId}{extension}";
|
|
var filePath = Path.Combine(_storagePath, storedFileName);
|
|
|
|
using var fileStream = File.Create(filePath);
|
|
await stream.CopyToAsync(fileStream);
|
|
|
|
return (fileId, filePath);
|
|
}
|
|
|
|
public string? GetFilePath(string fileId)
|
|
{
|
|
var files = Directory.GetFiles(_storagePath, $"{fileId}.*");
|
|
|
|
return files.Length > 0 ? files[0] : null;
|
|
}
|
|
|
|
public void DeleteFile(string fileId)
|
|
{
|
|
var filePath = GetFilePath(fileId);
|
|
|
|
if (filePath is not null && File.Exists(filePath))
|
|
{
|
|
File.Delete(filePath);
|
|
}
|
|
}
|
|
}
|