Skip to content

Commit

Permalink
fix: fix window variable definition
Browse files Browse the repository at this point in the history
Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
  • Loading branch information
skjnldsv committed Dec 28, 2022
1 parent 5488f49 commit fe54fd8
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
/// <reference types="@nextcloud/typings" />

declare var OC: Nextcloud.v16.OC | Nextcloud.v17.OC | Nextcloud.v18.OC | Nextcloud.v19.OC | Nextcloud.v20.OC;
declare global {
interface Window {
OC: Nextcloud.v16.OC | Nextcloud.v17.OC | Nextcloud.v18.OC | Nextcloud.v19.OC | Nextcloud.v20.OC;
}
}

/**
* Get an url with webroot to a file in an app
Expand Down Expand Up @@ -105,7 +109,7 @@ export const generateUrl = (url: string, params?: object, options?: UrlOptions)
noRewrite: false
}, options || {})

if (OC.config.modRewriteWorking === true && !allOptions.noRewrite) {
if (window?.OC?.config?.modRewriteWorking === true && !allOptions.noRewrite) {
return getRootUrl() + _generateUrlPath(url, params, options);
}

Expand Down Expand Up @@ -187,4 +191,4 @@ export const generateFilePath = (app: string, type: string, file: string) => {
*
* @return {string} web root path
*/
export const getRootUrl = () => OC.webroot
export const getRootUrl = () => window?.OC?.webroot || ''

0 comments on commit fe54fd8

Please sign in to comment.