first commit
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
using Fragalytics.Web;
|
||||
using Fragalytics.Web.Models;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace Fragalytics.RenderWorker.Services;
|
||||
|
||||
public sealed class SampleCopyRenderBackend : IClipRenderBackend
|
||||
{
|
||||
private readonly FragalyticsOptions _options;
|
||||
|
||||
public SampleCopyRenderBackend(IOptions<FragalyticsOptions> options)
|
||||
{
|
||||
_options = options.Value;
|
||||
}
|
||||
|
||||
public string Name => "sample-copy";
|
||||
|
||||
public async Task<RenderedClipResult> RenderAsync(ClipJobRecord clipJob, CancellationToken cancellationToken)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(_options.RenderWorker.SampleClipPath))
|
||||
{
|
||||
throw new InvalidOperationException("Fragalytics:RenderWorker:SampleClipPath is not configured.");
|
||||
}
|
||||
|
||||
var sampleClipPath = Path.GetFullPath(_options.RenderWorker.SampleClipPath);
|
||||
if (!File.Exists(sampleClipPath))
|
||||
{
|
||||
throw new FileNotFoundException("Configured sample clip was not found.", sampleClipPath);
|
||||
}
|
||||
|
||||
var tempDirectory = Path.GetFullPath(_options.RenderWorker.TempDirectory);
|
||||
Directory.CreateDirectory(tempDirectory);
|
||||
|
||||
var extension = Path.GetExtension(sampleClipPath);
|
||||
var outputPath = Path.Combine(tempDirectory, $"clipjob_{clipJob.Id}_{DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()}{extension}");
|
||||
|
||||
await using var input = File.OpenRead(sampleClipPath);
|
||||
await using var output = File.Create(outputPath);
|
||||
await input.CopyToAsync(output, cancellationToken);
|
||||
|
||||
return new RenderedClipResult
|
||||
{
|
||||
FilePath = outputPath,
|
||||
FileName = Path.GetFileName(sampleClipPath),
|
||||
ContentType = extension.Equals(".webm", StringComparison.OrdinalIgnoreCase) ? "video/webm" : "video/mp4"
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user