Skip to content

Commit

Permalink
fix: Optimize and modernize code
Browse files Browse the repository at this point in the history
Signed-off-by: Ferdinand Thiessen <[email protected]>
  • Loading branch information
susnux committed Jan 25, 2024
1 parent 3264a4e commit 1aa9822
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,11 @@ 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 = window?.OC?.coreApps?.indexOf(app) !== -1
const isCore = window?.OC?.coreApps?.includes(app)
const isPHP = file.slice(-3) === 'php'
let link = getRootUrl()
if (isPHP && !isCore) {
link += '/index.php/apps/' + app
link += `/index.php/apps/${app}`
if (file !== 'index.php') {
link += '/'
if (type) {
Expand All @@ -163,22 +163,17 @@ export const generateFilePath = (app: string, type: string, file: string) => {
} else if (!isPHP && !isCore) {
link = getAppRootUrl(app)
if (type) {
link += '/' + type + '/'
link += `/${type}/`
}
if (link.substring(link.length - 1) !== '/') {
if (link.at(-1) !== '/') {
link += '/'
}
link += file
} else {
if ((app === 'settings' || app === 'core' || app === 'search') && type === 'ajax') {
link += '/index.php/'
} else {
link += '/'
}
if (app !== '') {
app += '/'
link += app
link += '/index.php'
}
link += `/${app}`
if (type) {
link += type + '/'
}
Expand All @@ -201,9 +196,9 @@ export function getRootUrl(): string {
webroot = location.pathname
const pos = webroot.indexOf('/index.php/')
if (pos !== -1) {
webroot = webroot.substr(0, pos)
webroot = webroot.slice(0, pos)
} else {
webroot = webroot.substr(0, webroot.lastIndexOf('/'))
webroot = webroot.slice(0, webroot.lastIndexOf('/'))
}
}
return webroot
Expand Down

0 comments on commit 1aa9822

Please sign in to comment.