Skip to content

Commit 21a15b5

Browse files
committed
feat(Uploader): Enable chunked upload for public shares if supported
Signed-off-by: provokateurin <kate@provokateurin.de>
1 parent fcddd81 commit 21a15b5

2 files changed

Lines changed: 14 additions & 6 deletions

File tree

lib/uploader/uploader.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -475,9 +475,9 @@ export class Uploader {
475475
const file = fileHandle as File
476476

477477
// If manually disabled or if the file is too small
478-
// TODO: support chunk uploading in public pages
478+
const { public_shares_chunking: supportsPublicChunking } = getCapabilities().dav
479479
const maxChunkSize = getMaxChunksSize('size' in file ? file.size : undefined)
480-
const disabledChunkUpload = this._isPublic
480+
const disabledChunkUpload = !(supportsPublicChunking ?? false)
481481
|| maxChunkSize === 0
482482
|| ('size' in file && file.size < maxChunkSize)
483483

@@ -492,7 +492,7 @@ export class Uploader {
492492
logger.debug('Initializing chunked upload', { file, upload })
493493

494494
// Let's initialize a chunk upload
495-
const tempUrl = await initChunkWorkspace(encodedDestinationFile, retries)
495+
const tempUrl = await initChunkWorkspace(encodedDestinationFile, retries, this._isPublic)
496496
const chunksQueue: Array<Promise<void>> = []
497497

498498
// Generate chunks array

lib/utils/upload.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
55
import type { AxiosProgressEvent, AxiosResponse, AxiosError } from 'axios'
6-
import { generateRemoteUrl } from '@nextcloud/router'
6+
import { generateRemoteUrl, getBaseUrl } from '@nextcloud/router'
77
import { getCurrentUser } from '@nextcloud/auth'
88
import axios from '@nextcloud/axios'
99
import axiosRetry, { exponentialDelay, isNetworkOrIdempotentRequestError } from 'axios-retry'
10+
import { getSharingToken } from '@nextcloud/sharing/public'
1011

1112
import logger from './logger'
1213

@@ -114,9 +115,16 @@ export const getChunk = function(file: File, start: number, length: number): Pro
114115
* Create a temporary upload workspace to upload the chunks to
115116
* @param destinationFile The file name after finishing the chunked upload
116117
* @param retries number of retries
118+
* @param isPublic whether this upload is in a public share or not
117119
*/
118-
export const initChunkWorkspace = async function(destinationFile: string | undefined = undefined, retries: number = 5): Promise<string> {
119-
const chunksWorkspace = generateRemoteUrl(`dav/uploads/${getCurrentUser()?.uid}`)
120+
export const initChunkWorkspace = async function(destinationFile: string | undefined = undefined, retries: number = 5, isPublic: boolean = false): Promise<string> {
121+
let chunksWorkspace: string
122+
if (isPublic) {
123+
chunksWorkspace = `${getBaseUrl()}/public.php/dav/uploads/${getSharingToken()}`
124+
} else {
125+
chunksWorkspace = generateRemoteUrl(`dav/uploads/${getCurrentUser()?.uid}`)
126+
}
127+
120128
const hash = [...Array(16)].map(() => Math.floor(Math.random() * 16).toString(16)).join('')
121129
const tempWorkspace = `web-file-upload-${hash}`
122130
const url = `${chunksWorkspace}/${tempWorkspace}`

0 commit comments

Comments
 (0)