@@ -6,11 +6,11 @@ import Logger from '../Logger'
66import {
77 AuthenticationError ,
88 CancelledSyncError ,
9- HttpError ,
9+ HttpError , MissingPermissionsError ,
1010 NetworkError ,
1111 ParseResponseError ,
1212 RedirectError ,
13- RequestTimeoutError ,
13+ RequestTimeoutError
1414} from '../../errors/Error'
1515import { Capacitor , CapacitorHttp as Http } from '@capacitor/core'
1616
@@ -27,9 +27,7 @@ export interface KarakeepConfig {
2727
2828const TIMEOUT = 300000
2929
30- export default class KarakeepAdapter
31- implements Adapter , IResource < typeof ItemLocation . SERVER >
32- {
30+ export default class KarakeepAdapter implements Adapter , IResource < typeof ItemLocation . SERVER > {
3331 private server : KarakeepConfig
3432 private fetchQueue : PQueue
3533 private abortController : AbortController
@@ -97,12 +95,25 @@ export default class KarakeepAdapter
9795 return Promise . resolve ( undefined )
9896 }
9997
100- onSyncStart (
98+ async onSyncStart (
10199 needLock ?: boolean ,
102100 forceLock ?: boolean
103101 ) : Promise < void | boolean > {
104102 this . canceled = false
105- return Promise . resolve ( undefined )
103+ if ( Capacitor . getPlatform ( ) === 'web' ) {
104+ const browser = ( await import ( '../browser-api' ) ) . default
105+ let hasPermissions , error = false
106+ try {
107+ hasPermissions = await browser . permissions . contains ( { origins : [ this . server . url + '/' ] } )
108+ } catch ( e ) {
109+ error = true
110+ console . warn ( e )
111+ }
112+ const { isOrion} = await browser . storage . local . get ( { 'isOrion' : false } )
113+ if ( ! error && ! hasPermissions && ! isOrion ) {
114+ throw new MissingPermissionsError ( )
115+ }
116+ }
106117 }
107118
108119 async createBookmark ( bookmark : {
@@ -254,12 +265,12 @@ export default class KarakeepAdapter
254265 async removeFolder ( folder : { id : string | number } ) : Promise < void > {
255266 Logger . log ( '(karakeep)DELETEFOLDER' , { folder } )
256267
257- const deleteListContent = async ( ) => {
268+ const deleteListContent = async ( ) => {
258269 // Get the list of bookmarks in the list
259270 const bookmarkIds = [ ]
260271 let nextCursor = null
261272 do {
262- let response = await this . sendRequest (
273+ const response = await this . sendRequest (
263274 'GET' ,
264275 `/api/v1/lists/${ folder . id } /bookmarks?includeContent=false&${
265276 nextCursor ? 'cursor=' + nextCursor : ''
@@ -278,10 +289,10 @@ export default class KarakeepAdapter
278289 )
279290 }
280291
281- const deleteListFolders = async ( ) => {
292+ const deleteListFolders = async ( ) => {
282293 // Get the list of lists in the list
283294 const { lists } = await this . sendRequest ( 'GET' , `/api/v1/lists` )
284- let childrenListIds = lists
295+ const childrenListIds = lists
285296 . filter ( ( list ) => list . parentId === folder . id )
286297 . map ( ( l ) => l . id )
287298
@@ -309,11 +320,11 @@ export default class KarakeepAdapter
309320 async getBookmarksTree (
310321 loadAll ?: boolean
311322 ) : Promise < Folder < typeof ItemLocation . SERVER > > {
312- const fetchBookmarks = async ( listId : string ) => {
323+ const fetchBookmarks = async ( listId : string ) => {
313324 const links = [ ]
314325 let nextCursor = null
315326 do {
316- let response = await this . sendRequest (
327+ const response = await this . sendRequest (
317328 'GET' ,
318329 `/api/v1/lists/${ listId } /bookmarks?includeContent=false&${
319330 nextCursor ? 'cursor=' + nextCursor : ''
@@ -365,7 +376,7 @@ export default class KarakeepAdapter
365376 listTree [ list . parentId ] . push ( list . id )
366377 } )
367378
368- const buildTree = async ( listId , isRoot = false ) => {
379+ const buildTree = async ( listId , isRoot = false ) => {
369380 const list = listIdtoList [ listId ]
370381
371382 const childrenBookmarks = ( await fetchBookmarks ( listId ) )
@@ -394,7 +405,7 @@ export default class KarakeepAdapter
394405 } )
395406 }
396407
397- return await buildTree ( rootId , true )
408+ return buildTree ( rootId , true )
398409 }
399410
400411 async getListsOfBookmark ( bookmarkId : string | number ) : Promise < Set < string > > {
0 commit comments