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 9af617a commit 9cc38cd
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/index.ts
@@ -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 @@ -139,7 +143,7 @@ export const imagePath = (app: string, file: string) => {
* @return {string} URL with webroot for a file in an app
*/
export const generateFilePath = (app: string, type: string, file: string) => {
const isCore = OC.coreApps.indexOf(app) !== -1
const isCore = window?.OC?.coreApps?.indexOf(app) !== -1
let link = getRootUrl()
if (file.substring(file.length - 3) === 'php' && !isCore) {
link += '/index.php/apps/' + app;
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 9cc38cd

Please sign in to comment.