Return dimensions
This commit is contained in:
parent
b9f989986a
commit
a92e7d46fc
@ -86,17 +86,24 @@ public class NostrController : BaseDownloadController
|
|||||||
await _fileMetadata.Add(vf);
|
await _fileMetadata.Add(vf);
|
||||||
await _userUploads.AddFile(nostrUser.Id, vf.Id);
|
await _userUploads.AddFile(nostrUser.Id, vf.Id);
|
||||||
|
|
||||||
var ret = new Nip96UploadResult
|
List<List<string>> tags = new()
|
||||||
{
|
|
||||||
FileHeader = new()
|
|
||||||
{
|
|
||||||
Tags = new()
|
|
||||||
{
|
{
|
||||||
new() {"url", new Uri(_settings.SiteUrl, $"/nostr/{vf.OriginalDigest}{Path.GetExtension(vf.Name)}").ToString()},
|
new() {"url", new Uri(_settings.SiteUrl, $"/nostr/{vf.OriginalDigest}{Path.GetExtension(vf.Name)}").ToString()},
|
||||||
new() {"ox", vf.OriginalDigest ?? "", _settings.SiteUrl.ToString()},
|
new() {"ox", vf.OriginalDigest ?? "", _settings.SiteUrl.ToString()},
|
||||||
new() {"x", vf.Digest ?? ""},
|
new() {"x", vf.Digest ?? ""},
|
||||||
new() {"m", vf.MimeType}
|
new() {"m", vf.MimeType}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(vf.MediaDimensions))
|
||||||
|
{
|
||||||
|
tags.Add(new() {"dim", vf.MediaDimensions});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var ret = new Nip96UploadResult
|
||||||
|
{
|
||||||
|
FileHeader = new()
|
||||||
|
{
|
||||||
|
Tags = tags
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -359,7 +359,8 @@ public static class Extensions
|
|||||||
EditSecret = withEditSecret ? f.EditSecret : null,
|
EditSecret = withEditSecret ? f.EditSecret : null,
|
||||||
Storage = f.Storage,
|
Storage = f.Storage,
|
||||||
EncryptionParams = f.EncryptionParams,
|
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 Storage { get; init; } = "local-disk";
|
||||||
public string? EncryptionParams { get; init; }
|
public string? EncryptionParams { get; init; }
|
||||||
public string? MagnetLink { 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 probe = isImage ? await ImageFile.FromFileAsync(input) : default;
|
||||||
var ffmpeg = FFMpegArguments
|
var ffmpeg = FFMpegArguments
|
||||||
.FromFileInput(input)
|
.FromFileInput(input)
|
||||||
@ -73,7 +74,9 @@ public class CompressContent
|
|||||||
var result = await ffmpeg.ProcessAsynchronously();
|
var result = await ffmpeg.ProcessAsynchronously();
|
||||||
return new(result, output)
|
return new(result, output)
|
||||||
{
|
{
|
||||||
MimeType = outMime
|
MimeType = outMime,
|
||||||
|
Width = ffProbe?.PrimaryVideoStream?.Width,
|
||||||
|
Height = ffProbe?.PrimaryVideoStream?.Height,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -84,8 +87,24 @@ public class CompressContent
|
|||||||
return new(false, output);
|
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 record CompressResult(bool Success, string OutPath)
|
||||||
{
|
{
|
||||||
public string? MimeType { get; init; }
|
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,
|
Size = (ulong)fInfo.Length,
|
||||||
Digest = hash.ToHex(),
|
Digest = hash.ToHex(),
|
||||||
MimeType = res.MimeType ?? vf.MimeType,
|
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
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user