Skip to content

Commit 4e07de9

Browse files
authored
Merge pull request #2004 from floccusaddon/feat/orion
fix(browser.permissions): Ignore permissions when using Orion
2 parents 1d353e3 + 55f7113 commit 4e07de9

File tree

7 files changed

+56
-23
lines changed

7 files changed

+56
-23
lines changed

src/lib/adapters/Git.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ export default class GitAdapter extends CachingAdapter {
8080
error = true
8181
console.warn(e)
8282
}
83-
if (!error && !hasPermissions) {
83+
const {isOrion} = await browser.storage.local.get({'isOrion': false})
84+
if (!error && !hasPermissions && !isOrion) {
8485
throw new MissingPermissionsError()
8586
}
8687
}

src/lib/adapters/GoogleDrive.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ export default class GoogleDriveAdapter extends CachingAdapter {
7171
if (platform === 'web') {
7272
const browser = (await import('../browser-api')).default
7373
const origins = ['https://oauth2.googleapis.com/', 'https://www.googleapis.com/']
74-
if (!(await browser.permissions.contains({ origins }))) {
74+
const {isOrion} = await browser.storage.local.get({'isOrion': false})
75+
if (!(await browser.permissions.contains({ origins })) && !isOrion) {
7576
throw new MissingPermissionsError()
7677
}
7778
}
@@ -208,7 +209,8 @@ export default class GoogleDriveAdapter extends CachingAdapter {
208209
error = true
209210
console.warn(e)
210211
}
211-
if (!error && !hasPermissions) {
212+
const {isOrion} = await browser.storage.local.get({'isOrion': false})
213+
if (!error && !hasPermissions && !isOrion) {
212214
throw new MissingPermissionsError()
213215
}
214216
}

src/lib/adapters/Karakeep.ts

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ import Logger from '../Logger'
66
import {
77
AuthenticationError,
88
CancelledSyncError,
9-
HttpError,
9+
HttpError, MissingPermissionsError,
1010
NetworkError,
1111
ParseResponseError,
1212
RedirectError,
13-
RequestTimeoutError,
13+
RequestTimeoutError
1414
} from '../../errors/Error'
1515
import { Capacitor, CapacitorHttp as Http } from '@capacitor/core'
1616

@@ -27,9 +27,7 @@ export interface KarakeepConfig {
2727

2828
const 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>> {

src/lib/adapters/Linkwarden.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { IResource } from '../interfaces/Resource'
55
import Logger from '../Logger'
66
import {
77
AuthenticationError,
8-
CancelledSyncError, HttpError,
8+
CancelledSyncError, HttpError, MissingPermissionsError,
99
NetworkError, ParseResponseError,
1010
RedirectError,
1111
RequestTimeoutError
@@ -87,9 +87,22 @@ export default class LinkwardenAdapter implements Adapter, IResource<typeof Item
8787
return Promise.resolve(undefined)
8888
}
8989

90-
onSyncStart(needLock?: boolean, forceLock?: boolean): Promise<void | boolean> {
90+
async onSyncStart(needLock?: boolean, forceLock?: boolean): Promise<void | boolean> {
9191
this.canceled = false
92-
return Promise.resolve(undefined)
92+
if (Capacitor.getPlatform() === 'web') {
93+
const browser = (await import('../browser-api')).default
94+
let hasPermissions, error = false
95+
try {
96+
hasPermissions = await browser.permissions.contains({ origins: [this.server.url + '/'] })
97+
} catch (e) {
98+
error = true
99+
console.warn(e)
100+
}
101+
const {isOrion} = await browser.storage.local.get({'isOrion': false})
102+
if (!error && !hasPermissions && !isOrion) {
103+
throw new MissingPermissionsError()
104+
}
105+
}
93106
}
94107

95108
async createBookmark(bookmark: Bookmark<typeof ItemLocation.SERVER>): Promise<string | number> {

src/lib/adapters/NextcloudBookmarks.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ export default class NextcloudBookmarksAdapter implements Adapter, BulkImportRes
142142
error = true
143143
console.warn(e)
144144
}
145-
if (!error && !hasPermissions) {
145+
const {isOrion} = await browser.storage.local.get({'isOrion': false})
146+
if (!error && !hasPermissions && !isOrion) {
146147
throw new MissingPermissionsError()
147148
}
148149
}

src/lib/adapters/WebDav.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,8 @@ export default class WebDavAdapter extends CachingAdapter {
297297
error = true
298298
console.warn(e)
299299
}
300-
if (!error && !hasPermissions) {
300+
const {isOrion} = await browser.storage.local.get({'isOrion': false})
301+
if (!error && !hasPermissions && !isOrion) {
301302
throw new MissingPermissionsError()
302303
}
303304
}

src/ui/App.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ export default {
144144
}
145145
},
146146
async created() {
147+
if (window.KAGI) {
148+
browser.storage.local.set({'isOrion': true})
149+
}
150+
147151
await Promise.all([
148152
this.$store.dispatch(actions.LOAD_LOCKED),
149153
this.$store.dispatch(actions.LOAD_ACCOUNTS)

0 commit comments

Comments
 (0)