Return dimensions

This commit is contained in:
Kieran 2023-12-26 18:20:15 +00:00
parent b9f989986a
commit a92e7d46fc
Signed by: Kieran
GPG Key ID: DE71CEB3925BE941
5 changed files with 39 additions and 10 deletions

View File

@ -86,17 +86,24 @@ public class NostrController : BaseDownloadController
await _fileMetadata.Add(vf);
await _userUploads.AddFile(nostrUser.Id, vf.Id);
List<List<string>> tags = new()
{
new() {"url", new Uri(_settings.SiteUrl, $"/nostr/{vf.OriginalDigest}{Path.GetExtension(vf.Name)}").ToString()},
new() {"ox", vf.OriginalDigest ?? "", _settings.SiteUrl.ToString()},
new() {"x", vf.Digest ?? ""},
new() {"m", vf.MimeType}
};
if (!string.IsNullOrEmpty(vf.MediaDimensions))
{
tags.Add(new() {"dim", vf.MediaDimensions});
}
var ret = new Nip96UploadResult
{
FileHeader = new()
{
Tags = new()
{
new() {"url", new Uri(_settings.SiteUrl, $"/nostr/{vf.OriginalDigest}{Path.GetExtension(vf.Name)}").ToString()},
new() {"ox", vf.OriginalDigest ?? "", _settings.SiteUrl.ToString()},
new() {"x", vf.Digest ?? ""},
new() {"m", vf.MimeType}
}
Tags = tags
}
};

View File

@ -359,7 +359,8 @@ public static class Extensions
EditSecret = withEditSecret ? f.EditSecret : null,
Storage = f.Storage,
EncryptionParams = f.EncryptionParams,
MagnetLink = f.MagnetLink
MagnetLink = f.MagnetLink,
MediaDimensions = f.MediaDimensions
};
}

View File

@ -32,4 +32,5 @@ public class VoidFileMeta
public string Storage { get; init; } = "local-disk";
public string? EncryptionParams { get; init; }
public string? MagnetLink { get; init; }
public string? MediaDimensions { get; init; }
}

View File

@ -40,6 +40,7 @@ public class CompressContent
}
}
var ffProbe = await TryProbe(input, cts);
var probe = isImage ? await ImageFile.FromFileAsync(input) : default;
var ffmpeg = FFMpegArguments
.FromFileInput(input)
@ -73,7 +74,9 @@ public class CompressContent
var result = await ffmpeg.ProcessAsynchronously();
return new(result, output)
{
MimeType = outMime
MimeType = outMime,
Width = ffProbe?.PrimaryVideoStream?.Width,
Height = ffProbe?.PrimaryVideoStream?.Height,
};
}
catch (Exception ex)
@ -84,8 +87,24 @@ public class CompressContent
return new(false, output);
}
private async Task<IMediaAnalysis?> TryProbe(string path, CancellationToken cts)
{
try
{
return await FFProbe.AnalyseAsync(path, cancellationToken: cts);
}
catch
{
// ignored
}
return default;
}
public record CompressResult(bool Success, string OutPath)
{
public string? MimeType { get; init; }
public int? Width { get; init; }
public int? Height { get; init; }
}
}

View File

@ -73,7 +73,8 @@ public class LocalDiskFileStore : StreamFileStore, IFileStore
Size = (ulong)fInfo.Length,
Digest = hash.ToHex(),
MimeType = res.MimeType ?? vf.MimeType,
OriginalDigest = originalHash.ToHex()
OriginalDigest = originalHash.ToHex(),
MediaDimensions = res is {Width: not null, Height: not null} ? $"{res.Width.Value}x{res.Height.Value}" : null
};
}
else