using System.Security.Cryptography; namespace RunnersMeet.Server.Persistence; public class FileName { public string Hash { get; } public string DisplayName { get; } private FileName(string hash, string displayName) { Hash = hash; DisplayName = displayName; } public string GetPath() { return Path.Combine(Hash.Substring(0, 2), Hash.Substring(2, 2), Hash); } public static async Task FromFormUploadAsync(IFormFile file, string? displayName, CancellationToken cancellationToken = default) { var sha1 = SHA1.Create(); var hash = Convert.ToHexString(await sha1.ComputeHashAsync(file.OpenReadStream(), cancellationToken)); return new FileName(hash, displayName ?? file.FileName); } }