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: unique request ids for upload- and worker-requests #11929

Merged
merged 1 commit into from
Nov 19, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions changelog/unreleased/bugfix-unique-request-ids
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Bugfix: Unique request ids

We've fixed an issue where the request ids for upload- and worker-requests were not unique.

https://github.com/owncloud/web/pull/11929
https://github.com/owncloud/web/issues/11925
40 changes: 31 additions & 9 deletions packages/web-pkg/src/composables/upload/useUpload.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,51 @@
import { computed, unref, watch } from 'vue'
import { v4 as uuidV4 } from 'uuid'
import { UppyService } from '../../services/uppy/uppyService'
import { useCapabilityStore } from '../piniaStores'
import { useAuthStore, useCapabilityStore } from '../piniaStores'
import { TusOptions } from '@uppy/tus'
import { XHRUploadOptions } from '@uppy/xhr-upload'
import { UppyFile } from '@uppy/core'
import { useRequestHeaders } from '../requestHeaders'
import { useClientService } from '../clientService'
import { useGettext } from 'vue3-gettext'

interface UploadOptions {
uppyService: UppyService
}

export function useUpload(options: UploadOptions) {
const capabilityStore = useCapabilityStore()
const { headers } = useRequestHeaders()
const authStore = useAuthStore()
const clientService = useClientService()
const language = useGettext()

const isTusSupported = computed(() => capabilityStore.tusMaxChunkSize > 0)

const getHeaders = () => {
const headers: Record<string, string> = {}

if (authStore.publicLinkPassword) {
headers['Authorization'] =
'Basic ' +
Buffer.from(['public', authStore.publicLinkPassword].join(':')).toString('base64')
} else if (authStore.accessToken && !authStore.publicLinkPassword) {
headers['Authorization'] = 'Bearer ' + authStore.accessToken
}

headers['X-Request-ID'] = uuidV4()
headers['Accept-Language'] = language.current
headers['Initiator-ID'] = clientService.initiatorId
return headers
}

const tusOptions = computed<TusOptions>(() => {
const options: TusOptions = {
onBeforeRequest: (req, file) =>
new Promise((resolve) => {
req.setHeader('Authorization', unref(headers).Authorization)
req.setHeader('X-Request-ID', unref(headers)['X-Request-ID'])
req.setHeader('Accept-Language', unref(headers)['Accept-Language'])
req.setHeader('Initiator-ID', unref(headers)['Initiator-ID'])
const headers = getHeaders()
req.setHeader('Authorization', headers.Authorization)
req.setHeader('X-Request-ID', headers['X-Request-ID'])
req.setHeader('Accept-Language', headers['Accept-Language'])
req.setHeader('Initiator-ID', headers['Initiator-ID'])
if (file?.isRemote) {
req.setHeader('x-oc-mtime', (file?.data?.lastModified / 1000).toString())
}
Expand All @@ -37,7 +59,7 @@ export function useUpload(options: UploadOptions) {
// FIXME: remove if cloud upload still works without this
;(options as any)['headers'] = (file: UppyFile) => {
if (!!file.xhrUpload || file?.isRemote) {
return { 'x-oc-mtime': file?.data?.lastModified / 1000, ...unref(headers) }
return { 'x-oc-mtime': file?.data?.lastModified / 1000, ...getHeaders() }
}
}

Expand All @@ -50,7 +72,7 @@ export function useUpload(options: UploadOptions) {
endpoint: '',
headers: (file) => ({
'x-oc-mtime': file?.data?.lastModified / 1000,
...unref(headers)
...getHeaders()
})
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ export const useDeleteWorker = ({
resources,
concurrentRequests,
baseUrl: configStore.serverUrl,
headers: unref(headers)
headers: {
...unref(headers),
'X-Request-ID': undefined // is being generated by the dav client in the worker
}
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ export const usePasteWorker = () => {
data: {
transferData,
baseUrl: configStore.serverUrl,
headers: unref(headers)
headers: {
...unref(headers),
'X-Request-ID': undefined // is being generated by the dav client in the worker
}
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ export const useRestoreWorker = () => {
resources,
missingFolderPaths,
baseUrl: configStore.serverUrl,
headers: unref(headers)
headers: {
...unref(headers),
'X-Request-ID': undefined // is being generated by the dav client in the worker
}
}
})
}
Expand Down