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 <opensource@fthiessen.de>
  • Loading branch information
susnux committed Jan 25, 2024
1 parent b42908b commit 84e9d9a
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 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,26 +163,23 @@ 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 += '/'
link += '/index.php'
}
if (app !== '') {
app += '/'
link += app
if (app) {
link += `/${app}`
}
if (type) {
link += type + '/'
link += `/${type}`
}
link += file
link += `/${file}`
}
return link
}
Expand Down

0 comments on commit 84e9d9a

Please sign in to comment.