Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 5 additions & 4 deletions lib/uploader/uploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -474,10 +474,11 @@ export class Uploader {
// We can cast here as we handled system entries in the if above
const file = fileHandle as File

// If manually disabled or if the file is too small
// TODO: support chunk uploading in public pages
// @ts-expect-error TS2339 Object has no defined properties
const supportsPublicChunking = getCapabilities().dav?.public_shares_chunking ?? false
Comment thread
provokateurin marked this conversation as resolved.
const maxChunkSize = getMaxChunksSize('size' in file ? file.size : undefined)
const disabledChunkUpload = this._isPublic
// If manually disabled or if the file is too small
const disabledChunkUpload = !supportsPublicChunking
Comment thread
susnux marked this conversation as resolved.
Outdated
|| maxChunkSize === 0
|| ('size' in file && file.size < maxChunkSize)

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

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

// Generate chunks array
Expand Down
14 changes: 11 additions & 3 deletions lib/utils/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import type { AxiosProgressEvent, AxiosResponse, AxiosError } from 'axios'
import { generateRemoteUrl } from '@nextcloud/router'
import { generateRemoteUrl, getBaseUrl } from '@nextcloud/router'
import { getCurrentUser } from '@nextcloud/auth'
import axios from '@nextcloud/axios'
import axiosRetry, { exponentialDelay, isNetworkOrIdempotentRequestError } from 'axios-retry'
import { getSharingToken } from '@nextcloud/sharing/public'

import logger from './logger'

Expand Down Expand Up @@ -114,9 +115,16 @@ export const getChunk = function(file: File, start: number, length: number): Pro
* Create a temporary upload workspace to upload the chunks to
* @param destinationFile The file name after finishing the chunked upload
* @param retries number of retries
* @param isPublic whether this upload is in a public share or not
*/
export const initChunkWorkspace = async function(destinationFile: string | undefined = undefined, retries: number = 5): Promise<string> {
const chunksWorkspace = generateRemoteUrl(`dav/uploads/${getCurrentUser()?.uid}`)
export const initChunkWorkspace = async function(destinationFile: string | undefined = undefined, retries: number = 5, isPublic: boolean = false): Promise<string> {
let chunksWorkspace: string
if (isPublic) {
chunksWorkspace = `${getBaseUrl()}/public.php/dav/uploads/${getSharingToken()}`
} else {
chunksWorkspace = generateRemoteUrl(`dav/uploads/${getCurrentUser()?.uid}`)
}

const hash = [...Array(16)].map(() => Math.floor(Math.random() * 16).toString(16)).join('')
const tempWorkspace = `web-file-upload-${hash}`
const url = `${chunksWorkspace}/${tempWorkspace}`
Expand Down
Loading