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 access token renewal during upload #7296

Merged
merged 1 commit into from
Jul 19, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions changelog/unreleased/bugfix-token-renewal-during-upload
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Bugfix: Access token renewal during upload

We've fixed the access token renewal during ongoing uploads.

https://github.com/owncloud/web/issues/7240
https://github.com/owncloud/web/pull/7296
5 changes: 4 additions & 1 deletion packages/web-runtime/src/composables/upload/useUpload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ export function useUpload(options: UploadOptions): UploadResult {

return {
isTusSupported,
headers: unref(headers),
onBeforeRequest: (req) => {
req.setHeader('Authorization', unref(headers).Authorization)
},
headers: () => unref(headers),
...(isTusSupported && {
tusMaxChunkSize: unref(tusMaxChunkSize),
tusHttpMethodOverride: unref(tusHttpMethodOverride),
Expand Down
18 changes: 12 additions & 6 deletions packages/web-runtime/src/services/uppyService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,24 @@ export class UppyService {
tusMaxChunkSize,
tusHttpMethodOverride,
tusExtension,
headers
onBeforeRequest
}: {
tusMaxChunkSize: number
tusHttpMethodOverride: boolean
tusExtension: string
headers: { [key: string]: string }
onBeforeRequest: () => void
}) {
const chunkSize = tusMaxChunkSize || Infinity
const uploadDataDuringCreation = tusExtension.includes('creation-with-upload')

const tusPluginOptions = {
headers: headers,
chunkSize: chunkSize,
removeFingerprintOnSuccess: true,
overridePatchMethod: !!tusHttpMethodOverride,
retryDelays: [0, 500, 1000],
// @TODO Use uploadDataDuringCreation once https://github.com/tus/tus-js-client/issues/397 is solved
uploadDataDuringCreation: false
uploadDataDuringCreation: false,
onBeforeRequest
}

const xhrPlugin = this.uppy.getPlugin('XHRUpload')
Expand All @@ -64,10 +64,16 @@ export class UppyService {
return
}

this.uppy.use(CustomTus, tusPluginOptions as TusOptions)
this.uppy.use(CustomTus, tusPluginOptions as unknown as TusOptions)
}

useXhr({ headers }: { headers: { [key: string]: string } }) {
useXhr({
headers
}: {
headers: () => {
[name: string]: string | number
}
}) {
const xhrPluginOptions: XHRUploadOptions = {
endpoint: '',
method: 'put',
Expand Down