1- using System . Collections . Generic ;
1+ using System . Collections . Generic ;
22using System . Linq ;
33using CommunityToolkit . Diagnostics ;
44using Ipfs ;
@@ -50,9 +50,23 @@ public async Task AddImageAsync(IFile imageFile, CancellationToken cancellationT
5050 }
5151
5252 /// <inheritdoc />
53- public Task RemoveImageAsync ( IFile imageFile , CancellationToken cancellationToken )
53+ public async Task RemoveImageAsync ( IFile imageFile , CancellationToken cancellationToken )
5454 {
55- throw new NotImplementedException ( ) ;
55+ var image = Inner . Inner . Images . FirstOrDefault ( img => img . Id == imageFile . Id ) ;
56+ if ( image == null )
57+ {
58+ throw new ArgumentException ( "Image not found in the collection." , nameof ( imageFile ) ) ;
59+ }
60+
61+ var keyCid = await Client . Dag . PutAsync ( image . Id , pin : KuboOptions . ShouldPin , cancel : cancellationToken ) ;
62+ var valueCid = await Client . Dag . PutAsync ( image , pin : KuboOptions . ShouldPin , cancel : cancellationToken ) ;
63+
64+ var updateEvent = new ValueUpdateEvent ( Id , nameof ( RemoveImageAsync ) , ( DagCid ) keyCid , ( DagCid ) valueCid , true ) ;
65+
66+ await ApplyEntryUpdateAsync ( updateEvent , image , cancellationToken ) ;
67+ var appendedEntry = await AppendNewEntryAsync ( updateEvent , cancellationToken ) ;
68+
69+ EventStreamPosition = appendedEntry ;
5670 }
5771
5872 /// <inheritdoc />
@@ -134,4 +148,4 @@ public override Task ResetEventStreamPositionAsync(CancellationToken cancellatio
134148
135149 return Task . CompletedTask ;
136150 }
137- }
151+ }
0 commit comments