33 lines
1020 B
C#
33 lines
1020 B
C#
using System.Globalization;
|
|
using Events.FilesAPI.Infrastructure.Files;
|
|
using Events.FilesAPI.Infrastructure.Options;
|
|
using Microsoft.Extensions.Options;
|
|
|
|
namespace Events.FilesAPI.Features.Certificates.Download;
|
|
|
|
public sealed class CertificateFileLocator(
|
|
IHostEnvironment hostEnvironment,
|
|
IOptions<GeneratedFilesOptions> generatedFilesOptions)
|
|
{
|
|
public GeneratedFileReference? TryGet(int eventId, int personId)
|
|
{
|
|
string rootPath = Path.IsPathRooted(generatedFilesOptions.Value.OutputPath)
|
|
? generatedFilesOptions.Value.OutputPath
|
|
: Path.GetFullPath(Path.Combine(hostEnvironment.ContentRootPath, generatedFilesOptions.Value.OutputPath));
|
|
|
|
string certificatePath = Path.Combine(
|
|
rootPath,
|
|
eventId.ToString(CultureInfo.InvariantCulture),
|
|
$"{eventId}-{personId}.pdf");
|
|
|
|
if (!File.Exists(certificatePath))
|
|
return null;
|
|
|
|
return new GeneratedFileReference
|
|
{
|
|
FileName = Path.GetFileName(certificatePath),
|
|
PhysicalPath = certificatePath
|
|
};
|
|
}
|
|
}
|