Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Do not rely on OC.webroots or OC.appwebroots but use own logic #560

Merged
merged 1 commit into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 24 additions & 2 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export const generateFilePath = (app: string, type: string, file: string) => {
link += file
}
} else if (file.substring(file.length - 3) !== 'php' && !isCore) {
link = window?.OC?.appswebroots?.[app];
link = getAppRootUrl(app)
if (type) {
link += '/' + type + '/'
}
Expand Down Expand Up @@ -183,4 +183,26 @@ export const generateFilePath = (app: string, type: string, file: string) => {
*
* @return {string} web root path
*/
export const getRootUrl = () => window?.OC?.webroot || ''
export function getRootUrl(): string {
let webroot = window._oc_webroot

if (typeof webroot === 'undefined') {
webroot = location.pathname
const pos = webroot.indexOf('/index.php/')
if (pos !== -1) {
webroot = webroot.substr(0, pos)
} else {
webroot = webroot.substr(0, webroot.lastIndexOf('/'))
}
}
return webroot
}

/**
* Return the web root path for a given app
* @param {string} app The ID of the app
*/
export function getAppRootUrl(app: string): string {
const webroots = window._oc_appswebroots ?? {}
return webroots[app] ?? ''
}
6 changes: 5 additions & 1 deletion lib/oc.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
/// <reference types="@nextcloud/typings" />

declare interface Window {
OC: Nextcloud.v25.OC | Nextcloud.v26.OC | Nextcloud.v27.OC;
OC: Nextcloud.v26.OC | Nextcloud.v27.OC;

// Private state directly from server
_oc_webroot?: string
_oc_appswebroots?: Record<string, string|undefined>
}