LANCommander/LANCommander.Server/Controllers/UploadController.cs
Pat Hartl add770b227 Refactor Settings
Settings for the server are now combined with the settings from the SDK. This introduces a large breaking change and a migration should be created. This refactor utilizes .NET Configuration and the Options pattern. This will allow for the overriding of any setting using envionment variables. It also means that Settings.yml can be used to override any .NET configuration. A SettingsProvider implementation was created, and any updating of settings was changed from SettingsService.SaveSettings() to SettingsProvider.Update(s => { ... })
2025-11-16 12:31:25 -06:00

52 lines
1.7 KiB
C#

using LANCommander.Server.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using ZiggyCreatures.Caching.Fusion;
namespace LANCommander.Server.Controllers
{
[Authorize(Roles = RoleService.AdministratorRoleName)]
public class UploadController : BaseController
{
private readonly StorageLocationService StorageLocationService;
private readonly ArchiveClient _archiveClient;
private readonly IFusionCache Cache;
public UploadController(
ILogger<UploadController> logger,
SettingsProvider<Settings.Settings> settingsProvider,
StorageLocationService storageLocationService,
ArchiveClient archiveClient,
IFusionCache cache) : base(logger, settingsProvider)
{
StorageLocationService = storageLocationService;
_archiveClient = archiveClient;
Cache = cache;
}
[HttpPost]
public async Task<IActionResult> FileAsync(IFormFile file, string path)
{
try
{
if (!Directory.Exists(path))
return BadRequest("Destination path does not exist.");
path = Path.Combine(path, file.FileName);
using (var fileStream = System.IO.File.OpenWrite(path))
{
await file.CopyToAsync(fileStream);
}
return Ok();
}
catch (Exception ex)
{
Logger?.LogError(ex, "An error occurred while uploading the file");
return BadRequest("An error occurred while uploading the file.");
}
}
}
}