Add binary media manifest metadata
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System.Text;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text.Json;
|
||||
using Jibo.Cloud.Application.Abstractions;
|
||||
using Jibo.Cloud.Domain.Models;
|
||||
@@ -343,10 +344,15 @@ public sealed class JiboCloudProtocolService(ICloudStateStore stateStore, IMedia
|
||||
var meta = ReadObject(body, "meta") ?? new Dictionary<string, object?>(StringComparer.OrdinalIgnoreCase);
|
||||
var contentType = ReadHeader(envelope, "Content-Type") ?? "application/octet-stream";
|
||||
meta["contentType"] = contentType;
|
||||
var bodyBytes = string.IsNullOrWhiteSpace(envelope.BodyText)
|
||||
? []
|
||||
: Encoding.UTF8.GetBytes(envelope.BodyText);
|
||||
meta["contentLength"] = bodyBytes.Length;
|
||||
meta["contentSha256"] = Convert.ToHexString(SHA256.HashData(bodyBytes)).ToLowerInvariant();
|
||||
if (!string.IsNullOrWhiteSpace(envelope.BodyText)) meta["bodyText"] = envelope.BodyText;
|
||||
|
||||
_mediaContentStore.StoreAsync(path, contentType,
|
||||
string.IsNullOrWhiteSpace(envelope.BodyText) ? [] : Encoding.UTF8.GetBytes(envelope.BodyText),
|
||||
bodyBytes,
|
||||
meta as IReadOnlyDictionary<string, object?>, CancellationToken.None).GetAwaiter().GetResult();
|
||||
|
||||
return ProtocolDispatchResult.Ok(
|
||||
@@ -743,4 +749,4 @@ public sealed class JiboCloudProtocolService(ICloudStateStore stateStore, IMedia
|
||||
return Task.FromResult<MediaContentSnapshot?>(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Text.Json;
|
||||
using System.Security.Cryptography;
|
||||
using Azure.Storage.Blobs;
|
||||
using Jibo.Cloud.Application.Abstractions;
|
||||
|
||||
@@ -31,11 +32,17 @@ internal sealed class AzureBlobMediaContentStore : IMediaContentStore
|
||||
var metaBlob = _containerClient.GetBlobClient($"{relative}.json");
|
||||
await _containerClient.CreateIfNotExistsAsync(cancellationToken: cancellationToken);
|
||||
await contentBlob.UploadAsync(new MemoryStream(content), true, cancellationToken);
|
||||
var manifestMeta = meta is null
|
||||
? new Dictionary<string, object?>(StringComparer.OrdinalIgnoreCase)
|
||||
: new Dictionary<string, object?>(meta, StringComparer.OrdinalIgnoreCase);
|
||||
manifestMeta["contentLength"] = content.Length;
|
||||
manifestMeta["contentSha256"] = Convert.ToHexString(SHA256.HashData(content)).ToLowerInvariant();
|
||||
manifestMeta["storedUtc"] = DateTimeOffset.UtcNow;
|
||||
var payload = JsonSerializer.Serialize(new
|
||||
{
|
||||
path,
|
||||
contentType,
|
||||
meta
|
||||
meta = manifestMeta
|
||||
}, JsonOptions);
|
||||
await metaBlob.UploadAsync(BinaryData.FromString(payload), true, cancellationToken);
|
||||
}
|
||||
@@ -77,4 +84,4 @@ internal sealed class AzureBlobMediaContentStore : IMediaContentStore
|
||||
Meta = meta as IReadOnlyDictionary<string, object?> ?? new Dictionary<string, object?>(meta)
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Text.Json;
|
||||
using System.Security.Cryptography;
|
||||
using Jibo.Cloud.Application.Abstractions;
|
||||
|
||||
namespace Jibo.Cloud.Infrastructure.Media;
|
||||
@@ -29,11 +30,17 @@ internal sealed class FileMediaContentStore : IMediaContentStore
|
||||
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(contentPath)!);
|
||||
await File.WriteAllBytesAsync(contentPath, content, cancellationToken);
|
||||
var manifestMeta = meta is null
|
||||
? new Dictionary<string, object?>(StringComparer.OrdinalIgnoreCase)
|
||||
: new Dictionary<string, object?>(meta, StringComparer.OrdinalIgnoreCase);
|
||||
manifestMeta["contentLength"] = content.Length;
|
||||
manifestMeta["contentSha256"] = Convert.ToHexString(SHA256.HashData(content)).ToLowerInvariant();
|
||||
manifestMeta["storedUtc"] = DateTimeOffset.UtcNow;
|
||||
var payload = new
|
||||
{
|
||||
path,
|
||||
contentType,
|
||||
meta
|
||||
meta = manifestMeta
|
||||
};
|
||||
await File.WriteAllTextAsync(metaPath, JsonSerializer.Serialize(payload, JsonOptions), cancellationToken);
|
||||
}
|
||||
@@ -79,4 +86,4 @@ internal sealed class FileMediaContentStore : IMediaContentStore
|
||||
Meta = meta as IReadOnlyDictionary<string, object?> ?? new Dictionary<string, object?>(meta)
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user