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

Include x-oc-mtime header in upload requests #7630

Merged
merged 2 commits into from
Sep 12, 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-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
kulmann marked this conversation as resolved.
Show resolved Hide resolved
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