Skip to content

Commit

Permalink
chore: only request oneshot token when required (#905)
Browse files Browse the repository at this point in the history
Signed-off-by: Pedro Lamas <pedrolamas@gmail.com>
  • Loading branch information
pedrolamas committed Oct 11, 2022
1 parent d6886fd commit e5d177c
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/mixins/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ export default class FilesMixin extends Vue {
return this.$store.state.config.apiUrl
}

get isTrustedUser () {
const forceLogins = this.$store.getters['server/getConfig'].authorization.force_logins

return !forceLogins || this.$store.getters['auth/getCurrentUser']?.username === '_TRUSTED_USER_'
}

getThumbUrl (thumbnails: Thumbnail[], path: string, large: boolean, cachebust?: number) {
if (thumbnails.length) {
if (!cachebust) cachebust = new Date().getTime()
Expand Down Expand Up @@ -114,7 +120,7 @@ export default class FilesMixin extends Vue {
}
}

return await httpClient.get(encodeURI(this.apiUrl + '/server/files/' + filepath + '?date=' + new Date().getTime()), o)
return await httpClient.get(encodeURI(`${this.apiUrl}/server/files/${filepath}?date=${Date.now()}`), o)
}

/**
Expand Down Expand Up @@ -148,11 +154,13 @@ export default class FilesMixin extends Vue {
* @returns The url for the requested file
*/
async createFileUrl (filename: string, path: string) {
const token = (await authApi.getOneShot()).data.result

const filepath = (path) ? `${path}/${filename}` : `${filename}`

return `${this.apiUrl}/server/files/${filepath}?token=${token}&date=${Date.now()}`
const url = `${this.apiUrl}/server/files/${filepath}?date=${Date.now()}`

return this.isTrustedUser
? url
: `${url}&token=${(await authApi.getOneShot()).data.result}`
}

/**
Expand Down

0 comments on commit e5d177c

Please sign in to comment.