mirror of
https://github.com/azaion/admin.git
synced 2026-06-21 19:41:10 +00:00
3a925b9b0f
- Deleted the `POST /resources/get/{dataFolder?}` and `GET /resources/get-installer` endpoints as part of the architectural shift towards simplified resource management.
- Removed associated methods and configurations, including `ResourcesService.GetEncryptedResource`, `ResourcesService.GetInstaller`, and related properties in `ResourcesConfig`.
- Cleaned up environment variables and configuration files to reflect the removal of installer-related settings.
- Eliminated the `GetResourceRequest` DTO and its validator, along with the `WrongResourceName` error code.
- Updated documentation to clarify the changes in resource handling and the retirement of per-user file encryption.
Co-authored-by: Cursor <cursoragent@cursor.com>
64 lines
2.4 KiB
C#
64 lines
2.4 KiB
C#
using Azaion.Common;
|
|
using Azaion.Common.Configs;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.Extensions.Logging;
|
|
using Microsoft.Extensions.Options;
|
|
|
|
namespace Azaion.Services;
|
|
|
|
public interface IResourcesService
|
|
{
|
|
Task SaveResource(string? dataFolder, IFormFile data, CancellationToken cancellationToken = default);
|
|
Task<IEnumerable<string>> ListResources(string? dataFolder, string? search, CancellationToken cancellationToken = default);
|
|
void ClearFolder(string? dataFolder);
|
|
}
|
|
|
|
public class ResourcesService(IOptions<ResourcesConfig> resourcesConfig, ILogger<ResourcesService> logger) : IResourcesService
|
|
{
|
|
private string GetResourceFolder(string? dataFolder)
|
|
{
|
|
return string.IsNullOrWhiteSpace(dataFolder)
|
|
? resourcesConfig.Value.ResourcesFolder
|
|
: Path.Combine(resourcesConfig.Value.ResourcesFolder, dataFolder);
|
|
}
|
|
|
|
public async Task SaveResource(string? dataFolder, IFormFile data, CancellationToken cancellationToken = default)
|
|
{
|
|
if (data == null)
|
|
throw new BusinessException(ExceptionEnum.NoFileProvided);
|
|
var resourceFolder = GetResourceFolder(dataFolder);
|
|
|
|
if (!Directory.Exists(resourceFolder))
|
|
Directory.CreateDirectory(resourceFolder);
|
|
|
|
var resourcePath = Path.Combine(resourceFolder, data.FileName);
|
|
File.Delete(resourcePath);
|
|
await using var fileStream = new FileStream(resourcePath, FileMode.OpenOrCreate, FileAccess.ReadWrite);
|
|
await data.CopyToAsync(fileStream, cancellationToken);
|
|
logger.LogInformation($"Resource {data.FileName} Saved Successfully");
|
|
}
|
|
|
|
public async Task<IEnumerable<string>> ListResources(string? dataFolder, string? search, CancellationToken cancellationToken = default)
|
|
{
|
|
var resourceFolder = GetResourceFolder(dataFolder);
|
|
return await Task.FromResult(
|
|
(string.IsNullOrWhiteSpace(search)
|
|
? new DirectoryInfo(resourceFolder).GetFiles()
|
|
: new DirectoryInfo(resourceFolder).GetFiles(search))
|
|
.Select(f => f.Name)
|
|
.ToList());
|
|
}
|
|
|
|
public void ClearFolder(string? dataFolder)
|
|
{
|
|
var di = new DirectoryInfo(GetResourceFolder(dataFolder));
|
|
if (!di.Exists)
|
|
return;
|
|
|
|
foreach (var file in di.GetFiles())
|
|
file.Delete();
|
|
|
|
foreach (var dir in di.GetDirectories())
|
|
dir.Delete(true);
|
|
}
|
|
} |