@@ -248,8 +248,55 @@ export default class KarakeepAdapter
248248 )
249249 }
250250
251+ /**
252+ * Removes the list from karakeep, but also all its content recursively
253+ */
251254 async removeFolder ( folder : { id : string | number } ) : Promise < void > {
252255 Logger . log ( '(karakeep)DELETEFOLDER' , { folder } )
256+
257+ const deleteListContent = async ( ) => {
258+ // Get the list of bookmarks in the list
259+ const bookmarkIds = [ ]
260+ let nextCursor = null
261+ do {
262+ let response = await this . sendRequest (
263+ 'GET' ,
264+ `/api/v1/lists/${ folder . id } /bookmarks?includeContent=false&${
265+ nextCursor ? 'cursor=' + nextCursor : ''
266+ } `
267+ )
268+ nextCursor = response . nextCursor
269+ bookmarkIds . push ( ...response . bookmarks . map ( ( b ) => b . id ) )
270+ } while ( nextCursor !== null )
271+ await Promise . all (
272+ bookmarkIds . map ( ( id ) =>
273+ this . removeBookmark ( {
274+ id : `${ id } ;${ folder . id } ` ,
275+ parentId : folder . id ,
276+ } )
277+ )
278+ )
279+ }
280+
281+ const deleteListFolders = async ( ) => {
282+ // Get the list of lists in the list
283+ const { lists } = await this . sendRequest ( 'GET' , `/api/v1/lists` )
284+ let childrenListIds = lists
285+ . filter ( ( list ) => list . parentId === folder . id )
286+ . map ( ( l ) => l . id )
287+
288+ await Promise . all (
289+ childrenListIds . map ( ( listId ) =>
290+ this . removeFolder ( {
291+ id : listId ,
292+ } )
293+ )
294+ )
295+ }
296+
297+ await Promise . all ( [ deleteListContent ( ) , deleteListFolders ( ) ] )
298+
299+ // Delete the list itself "after" deleting all its content in case any failure occurs in the previous steps
253300 await this . sendRequest (
254301 'DELETE' ,
255302 `/api/v1/lists/${ folder . id } ` ,
0 commit comments