mirror of
https://git.v0l.io/Kieran/void.cat.git
synced 2025-03-17 21:12:22 +01:00
Return dimensions
This commit is contained in:
parent
b9f989986a
commit
a92e7d46fc
@ -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
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -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
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -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; }
|
||||
}
|
@ -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; }
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user