From 97c10b94c1bad0f356c34e6f6e922a1e10971669 Mon Sep 17 00:00:00 2001 From: Jannik Stehle Date: Mon, 12 Sep 2022 11:09:30 +0200 Subject: [PATCH 1/2] Include x-oc-mtime header in upload requests --- changelog/unreleased/bugfix-upload-modify-time | 6 ++++++ .../src/composables/upload/useUpload.ts | 15 +++++++++++++-- packages/web-runtime/src/services/uppyService.ts | 13 +++++++++---- 3 files changed, 28 insertions(+), 6 deletions(-) create mode 100644 changelog/unreleased/bugfix-upload-modify-time diff --git a/changelog/unreleased/bugfix-upload-modify-time b/changelog/unreleased/bugfix-upload-modify-time new file mode 100644 index 00000000000..8646e3ae243 --- /dev/null +++ b/changelog/unreleased/bugfix-upload-modify-time @@ -0,0 +1,6 @@ +Bugfix: Upload modify time + +We've included the `x-oc-mtime` header in upload requests to tell the backend the proper modify date of uploaded resources. + +https://github.com/owncloud/web/pull/7630 +https://github.com/owncloud/web/issues/7628 diff --git a/packages/web-runtime/src/composables/upload/useUpload.ts b/packages/web-runtime/src/composables/upload/useUpload.ts index 3805dc1273e..c42876acf6e 100644 --- a/packages/web-runtime/src/composables/upload/useUpload.ts +++ b/packages/web-runtime/src/composables/upload/useUpload.ts @@ -10,7 +10,7 @@ import { useStore } from 'web-pkg/src/composables' import { computed, Ref, unref, watch } from '@vue/composition-api' -import { UppyService } from '../../services/uppyService' +import { UppyService, uppyHeaders } from '../../services/uppyService' import * as uuid from 'uuid' export interface UppyResource { @@ -79,7 +79,18 @@ export function useUpload(options: UploadOptions): UploadResult { onBeforeRequest: (req) => { req.setHeader('Authorization', unref(headers).Authorization) }, - headers: () => unref(headers), + headers: (file) => { + const reqHeaders = { + 'x-oc-mtime': file.data.lastModified / 1000, + ...unref(headers) + } as uppyHeaders + + if (unref(isTusSupported)) { + // Tus includes auth headers before each request + delete reqHeaders.Authorization + } + return reqHeaders + }, ...(isTusSupported && { tusMaxChunkSize: unref(tusMaxChunkSize), tusHttpMethodOverride: unref(tusHttpMethodOverride), diff --git a/packages/web-runtime/src/services/uppyService.ts b/packages/web-runtime/src/services/uppyService.ts index f132f61eeb0..be433376dba 100644 --- a/packages/web-runtime/src/services/uppyService.ts +++ b/packages/web-runtime/src/services/uppyService.ts @@ -21,6 +21,10 @@ type UppyServiceTopics = | 'drag-out' | 'drop' +export type uppyHeaders = { + [name: string]: string | number +} + export class UppyService { uppy: Uppy uploadInputs: HTMLInputElement[] = [] @@ -36,17 +40,20 @@ export class UppyService { tusMaxChunkSize, tusHttpMethodOverride, tusExtension, - onBeforeRequest + onBeforeRequest, + headers }: { tusMaxChunkSize: number tusHttpMethodOverride: boolean tusExtension: string onBeforeRequest: () => void + headers: () => uppyHeaders }) { const chunkSize = tusMaxChunkSize || Infinity const uploadDataDuringCreation = tusExtension.includes('creation-with-upload') const tusPluginOptions = { + headers, chunkSize: chunkSize, removeFingerprintOnSuccess: true, overridePatchMethod: !!tusHttpMethodOverride, @@ -72,9 +79,7 @@ export class UppyService { useXhr({ headers }: { - headers: () => { - [name: string]: string | number - } + headers: () => uppyHeaders }) { const xhrPluginOptions: XHRUploadOptions = { endpoint: '', From a09aaa64b4c1369e109c95724f5c2407a5e16287 Mon Sep 17 00:00:00 2001 From: Jannik Stehle Date: Mon, 12 Sep 2022 11:21:30 +0200 Subject: [PATCH 2/2] Run linter --- packages/web-runtime/src/services/uppyService.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/web-runtime/src/services/uppyService.ts b/packages/web-runtime/src/services/uppyService.ts index be433376dba..72087ba70b5 100644 --- a/packages/web-runtime/src/services/uppyService.ts +++ b/packages/web-runtime/src/services/uppyService.ts @@ -76,11 +76,7 @@ export class UppyService { this.uppy.use(CustomTus, tusPluginOptions as unknown as TusOptions) } - useXhr({ - headers - }: { - headers: () => uppyHeaders - }) { + useXhr({ headers }: { headers: () => uppyHeaders }) { const xhrPluginOptions: XHRUploadOptions = { endpoint: '', method: 'put',