@@ -19,15 +19,20 @@ public class MediaLibraryManager : IAsyncBackgroundService
1919 NotificationService NotificationService ;
2020 DialogService DialogService ;
2121 public List < MediaLibraryItem > MediaItems { get ; private set ; } = new List < MediaLibraryItem > ( ) ;
22- public MediaLibraryManager ( BlazorJSRuntime js , NotificationService notificationService , DialogService dialogService )
22+ HttpClient HttpClient ;
23+ AssetManifestService AssetManifestService ;
24+ public MediaLibraryManager ( BlazorJSRuntime js , HttpClient httpClient , NotificationService notificationService , DialogService dialogService , AssetManifestService assetManifestService )
2325 {
2426 JS = js ;
27+ HttpClient = httpClient ;
2528 NotificationService = notificationService ;
2629 DialogService = dialogService ;
30+ AssetManifestService = assetManifestService ;
2731 window = JS . Get < Window > ( "window" ) ;
2832 }
2933 async Task InitAsync ( )
3034 {
35+ await AssetManifestService . Ready ;
3136 window . AddEventListener ( "dragover" , Callback . Create < DragEvent > ( Window_OnDragOver , callbackGroup ) ) ;
3237 window . AddEventListener ( "drop" , Callback . Create < DragEvent > ( Window_OnDrop , callbackGroup ) ) ;
3338 LibraryCache = await Cache . OpenCache ( "MediaLibrary" ) ;
@@ -79,12 +84,21 @@ public async Task<bool> Remove(string fileName)
7984 }
8085 async Task UpdateMediaItems ( )
8186 {
82- var files = await LibraryCache . GetAllFiles ( ) ;
8387 var newList = new List < MediaLibraryItem > ( ) ;
88+ var included = await GetIncludedPixelArt ( ) ;
89+ foreach ( var file in included )
90+ {
91+ using var resp = await JS . Fetch ( file ) ;
92+ var fileBlob = await resp . Blob ( ) ;
93+ var mediaItem = new MediaLibraryItem ( file , fileBlob , true ) ;
94+ newList . Add ( mediaItem ) ;
95+ }
96+ var files = await LibraryCache . GetAllFiles ( ) ;
8497 foreach ( var file in files )
8598 {
8699 var fileBlob = await LibraryCache . ReadBlob ( file ) ;
87- var mediaItem = new MediaLibraryItem ( file , fileBlob ) ;
100+ if ( fileBlob == null ) continue ;
101+ var mediaItem = new MediaLibraryItem ( file , fileBlob , false ) ;
88102 newList . Add ( mediaItem ) ;
89103 }
90104 var previous = MediaItems . ToList ( ) ;
@@ -132,5 +146,21 @@ void StateHasChanged()
132146 {
133147 OnStateChanged ? . Invoke ( ) ;
134148 }
149+ async Task < List < string > > GetIncludedPixelArt ( )
150+ {
151+ var ret = new List < string > ( ) ;
152+ var assetManifest = AssetManifestService . AssetManifest ;
153+ if ( assetManifest != null )
154+ {
155+ foreach ( var asset in assetManifest . Assets )
156+ {
157+ if ( asset . Url . StartsWith ( "pixelart/" ) )
158+ {
159+ ret . Add ( asset . Url ) ;
160+ }
161+ }
162+ }
163+ return ret ;
164+ }
135165 }
136166}
0 commit comments