Current libraries: the database, media, sanitizer, mail and sign-in libraries are on their latest versions
Build / Build (push) Successful in 35s
Build / Build (push) Successful in 35s
- MongoDB.Entities 26, FFMpegCore 6, HtmlSanitizer 11, Serilog's MongoDB sink 8, OpenIddict 7.8, MailKit 4.18.2, Markdig 1.6, Swashbuckle 10.3, QRCoder 1.8.1 and the .NET 10.0.14 sign-in library; the build uses SDK 10.0.403. The two packages with known vulnerabilities in the old set are gone. - Stored records are read and written exactly as before: ids keep their form, personas and groups still get ids that carry their published day, and an older version can still read what this one writes. - Videos are probed, transcoded and given a poster frame as before. - Federated posts are cleaned exactly as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01W4YtEJrgxG12Pc39Fai8Bd
This commit is contained in:
1 parent
739a1603ca
commit
8a1e4e419b
9 files changed
+88
-26
No files matched your search
@@ -0,0 +1,49 @@
|
||||
using MongoDB.Bson;
|
||||
using MongoDB.Bson.Serialization;
|
||||
using MongoDB.Entities;
|
||||
|
||||
namespace PrivaPub.Infrastructure.Data
|
||||
{
|
||||
public interface IOwnId
|
||||
{
|
||||
string NewId();
|
||||
}
|
||||
|
||||
public static class EntityIds
|
||||
{
|
||||
static readonly Lock Gate = new();
|
||||
|
||||
public static void Register()
|
||||
{
|
||||
lock (Gate)
|
||||
{
|
||||
if (BsonClassMap.IsClassMapRegistered(typeof(Entity)))
|
||||
{
|
||||
if (BsonClassMap.LookupClassMap(typeof(Entity)).IdMemberMap?.IdGenerator is Generator)
|
||||
return;
|
||||
|
||||
throw new InvalidOperationException(
|
||||
"The BSON map of Entity was built before EntityIds.Register(), so IDs would not be stored as they always were. Register them before anything touches a stored record.");
|
||||
}
|
||||
|
||||
BsonClassMap.RegisterClassMap<Entity>(map =>
|
||||
{
|
||||
map.AutoMap();
|
||||
map.SetIgnoreExtraElements(true);
|
||||
var id = map.MapIdProperty(entity => entity.ID);
|
||||
((IBsonMemberMapAttribute)new AsObjectIdAttribute()).Apply(id);
|
||||
id.SetIdGenerator(new Generator());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
sealed class Generator : IIdGenerator
|
||||
{
|
||||
public object GenerateId(object container, object document)
|
||||
=> document is IOwnId own ? own.NewId() : ObjectId.GenerateNewId().ToString();
|
||||
|
||||
public bool IsEmpty(object id)
|
||||
=> string.IsNullOrEmpty(id as string);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user