@@ -216,7 +216,7 @@ class ClientSideStorage implements commonStorage.Storage {
216216 return this . renameFile ( oldPath , newPath ) ;
217217 }
218218
219- async renameDirectory ( oldPath : string , newPath : string ) : Promise < void > {
219+ private async renameDirectory ( oldPath : string , newPath : string ) : Promise < void > {
220220 return new Promise ( ( resolve , reject ) => {
221221 const transaction = this . db . transaction ( [ FILES_STORE_NAME ] , 'readwrite' ) ;
222222 transaction . oncomplete = ( ) => {
@@ -265,7 +265,7 @@ class ClientSideStorage implements commonStorage.Storage {
265265 } ) ;
266266 }
267267
268- async renameFile ( oldPath : string , newPath : string ) : Promise < void > {
268+ private async renameFile ( oldPath : string , newPath : string ) : Promise < void > {
269269 return new Promise ( ( resolve , reject ) => {
270270 const transaction = this . db . transaction ( [ FILES_STORE_NAME ] , 'readwrite' ) ;
271271 transaction . oncomplete = ( ) => {
@@ -366,7 +366,52 @@ class ClientSideStorage implements commonStorage.Storage {
366366 } ) ;
367367 }
368368
369- async deleteFile ( filePath : string ) : Promise < void > {
369+ async delete ( path : string ) : Promise < void > {
370+ if ( path . endsWith ( '/' ) ) {
371+ return this . deleteDirectory ( path ) ;
372+ }
373+ return this . deleteFile ( path ) ;
374+ }
375+
376+ private async deleteDirectory ( path : string ) : Promise < void > {
377+ return new Promise ( ( resolve , reject ) => {
378+ const transaction = this . db . transaction ( [ FILES_STORE_NAME ] , 'readwrite' ) ;
379+ transaction . oncomplete = ( ) => {
380+ resolve ( ) ;
381+ } ;
382+ transaction . onabort = ( ) => {
383+ console . log ( 'IndexedDB transaction aborted.' ) ;
384+ reject ( new Error ( 'IndexedDB transaction aborted.' ) ) ;
385+ } ;
386+ const filesObjectStore = transaction . objectStore ( FILES_STORE_NAME ) ;
387+ const openKeyCursorRequest = filesObjectStore . openKeyCursor ( ) ;
388+ openKeyCursorRequest . onerror = ( ) => {
389+ console . log ( 'IndexedDB openKeyCursor request failed. openKeyCursorRequest.error is...' ) ;
390+ console . log ( openKeyCursorRequest . error ) ;
391+ throw new Error ( 'IndexedDB openKeyCursor request failed.' ) ;
392+ } ;
393+ openKeyCursorRequest . onsuccess = ( ) => {
394+ const cursor = openKeyCursorRequest . result ;
395+ if ( cursor && cursor . key ) {
396+ const filePath : string = cursor . key as string ;
397+ if ( filePath . startsWith ( path ) ) {
398+ const deleteRequest = filesObjectStore . delete ( filePath ) ;
399+ deleteRequest . onerror = ( ) => {
400+ console . log ( 'IndexedDB delete request failed. deleteRequest.error is...' ) ;
401+ console . log ( deleteRequest . error ) ;
402+ throw new Error ( 'IndexedDB delete request failed.' ) ;
403+ } ;
404+ }
405+ cursor . continue ( ) ;
406+ } else {
407+ // The cursor is done. We have finished reading all the files.
408+ resolve ( ) ;
409+ }
410+ } ;
411+ } ) ;
412+ }
413+
414+ private async deleteFile ( filePath : string ) : Promise < void > {
370415 return new Promise ( ( resolve , reject ) => {
371416 const transaction = this . db . transaction ( [ FILES_STORE_NAME ] , 'readwrite' ) ;
372417 transaction . oncomplete = ( ) => {
0 commit comments