Files
admin/_docs/02_document/modules/services_resources_service.md
2026-04-16 06:25:36 +03:00

2.5 KiB

Module: Azaion.Services.ResourcesService

Purpose

File-based resource management: upload, list, download (encrypted), clear, and installer retrieval from the server's filesystem.

Public Interface

IResourcesService

Method Signature Description
GetInstaller (string?, Stream?) GetInstaller(bool isStage) Returns the latest installer file (prod or stage)
GetEncryptedResource Task<Stream> GetEncryptedResource(string? dataFolder, string fileName, string key, CancellationToken ct) Reads a file and returns it AES-encrypted
SaveResource Task SaveResource(string? dataFolder, IFormFile data, CancellationToken ct) Saves an uploaded file to the resource folder
ListResources Task<IEnumerable<string>> ListResources(string? dataFolder, string? search, CancellationToken ct) Lists file names in a resource folder, optionally filtered
ClearFolder void ClearFolder(string? dataFolder) Deletes all files and subdirectories in the specified folder

Internal Logic

  • GetResourceFolder: resolves the target directory. If dataFolder is null/empty, uses ResourcesConfig.ResourcesFolder directly; otherwise, appends it as a subdirectory.
  • GetInstaller: scans the installer folder for files matching "AzaionSuite.Iterative*", returns the first match as a FileStream.
  • GetEncryptedResource: opens the file, encrypts via Security.EncryptTo extension into a MemoryStream, returns the encrypted stream.
  • SaveResource: creates the folder if needed, deletes any existing file with the same name, then copies the uploaded file.
  • ListResources: uses DirectoryInfo.GetFiles with optional search pattern.
  • ClearFolder: iterates and deletes all files and subdirectories.

Dependencies

  • IOptions<ResourcesConfig> — folder paths
  • ILogger<ResourcesService> — logs successful saves
  • BusinessException — thrown for null file uploads
  • Security.EncryptTo — stream encryption extension

Consumers

  • Program.cs — all /resources/* endpoints

Data Models

None.

Configuration

Uses ResourcesConfig (ResourcesFolder, SuiteInstallerFolder, SuiteStageInstallerFolder).

External Integrations

Local filesystem for resource storage.

Security

  • Resources are encrypted per-user using a key derived from email + password + hardware hash
  • File deletion overwrites existing files before writing new ones
  • No path traversal protection on dataFolder parameter

Tests

None.