11/// <reference types="@nextcloud/typings" />
22
3- declare var OC : Nextcloud . v16 . OC | Nextcloud . v17 . OC | Nextcloud . v18 . OC | Nextcloud . v19 . OC | Nextcloud . v20 . OC ;
3+ declare global {
4+ interface Window {
5+ OC : Nextcloud . v16 . OC | Nextcloud . v17 . OC | Nextcloud . v18 . OC | Nextcloud . v19 . OC | Nextcloud . v20 . OC ;
6+ }
7+ }
48
59/**
610 * Get an url with webroot to a file in an app
@@ -105,7 +109,7 @@ export const generateUrl = (url: string, params?: object, options?: UrlOptions)
105109 noRewrite : false
106110 } , options || { } )
107111
108- if ( OC . config . modRewriteWorking === true && ! allOptions . noRewrite ) {
112+ if ( window ?. OC ? .config ? .modRewriteWorking === true && ! allOptions . noRewrite ) {
109113 return getRootUrl ( ) + _generateUrlPath ( url , params , options ) ;
110114 }
111115
@@ -139,7 +143,7 @@ export const imagePath = (app: string, file: string) => {
139143 * @return {string } URL with webroot for a file in an app
140144 */
141145export const generateFilePath = ( app : string , type : string , file : string ) => {
142- const isCore = OC . coreApps . indexOf ( app ) !== - 1
146+ const isCore = window ?. OC ? .coreApps ? .indexOf ( app ) !== - 1
143147 let link = getRootUrl ( )
144148 if ( file . substring ( file . length - 3 ) === 'php' && ! isCore ) {
145149 link += '/index.php/apps/' + app ;
@@ -151,7 +155,7 @@ export const generateFilePath = (app: string, type: string, file: string) => {
151155 link += file
152156 }
153157 } else if ( file . substring ( file . length - 3 ) !== 'php' && ! isCore ) {
154- link = OC . appswebroots [ app ] ;
158+ link = window ?. OC ? .appswebroots ?. [ app ] ;
155159 if ( type ) {
156160 link += '/' + type + '/'
157161 }
@@ -187,4 +191,4 @@ export const generateFilePath = (app: string, type: string, file: string) => {
187191 *
188192 * @return {string } web root path
189193 */
190- export const getRootUrl = ( ) => OC . webroot
194+ export const getRootUrl = ( ) => window ?. OC ? .webroot || ''
0 commit comments