Skip to content

Commit

Permalink
Include x-oc-mtime header in upload requests (#7630)
Browse files Browse the repository at this point in the history
  • Loading branch information
JammingBen authored Sep 12, 2022
1 parent 0fed385 commit ed8b1ba
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
6 changes: 6 additions & 0 deletions changelog/unreleased/bugfix-upload-modify-time
Original file line number Diff line number Diff line change
@@ -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
15 changes: 13 additions & 2 deletions packages/web-runtime/src/composables/upload/useUpload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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),
Expand Down
17 changes: 9 additions & 8 deletions packages/web-runtime/src/services/uppyService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ type UppyServiceTopics =
| 'drag-out'
| 'drop'

export type uppyHeaders = {
[name: string]: string | number
}

export class UppyService {
uppy: Uppy
uploadInputs: HTMLInputElement[] = []
Expand All @@ -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,
Expand All @@ -69,13 +76,7 @@ export class UppyService {
this.uppy.use(CustomTus, tusPluginOptions as unknown as TusOptions)
}

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

0 comments on commit ed8b1ba

Please sign in to comment.