|
3 | 3 | * SPDX-License-Identifier: AGPL-3.0-or-later |
4 | 4 | */ |
5 | 5 | import type { AxiosProgressEvent, AxiosResponse, AxiosError } from 'axios' |
6 | | -import { generateRemoteUrl } from '@nextcloud/router' |
| 6 | +import { generateRemoteUrl, getBaseUrl } from '@nextcloud/router' |
7 | 7 | import { getCurrentUser } from '@nextcloud/auth' |
8 | 8 | import axios from '@nextcloud/axios' |
9 | 9 | import axiosRetry, { exponentialDelay, isNetworkOrIdempotentRequestError } from 'axios-retry' |
| 10 | +import { getSharingToken } from '@nextcloud/sharing/public' |
10 | 11 |
|
11 | 12 | import logger from './logger' |
12 | 13 |
|
@@ -114,9 +115,16 @@ export const getChunk = function(file: File, start: number, length: number): Pro |
114 | 115 | * Create a temporary upload workspace to upload the chunks to |
115 | 116 | * @param destinationFile The file name after finishing the chunked upload |
116 | 117 | * @param retries number of retries |
| 118 | + * @param isPublic whether this upload is in a public share or not |
117 | 119 | */ |
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 | + |
120 | 128 | const hash = [...Array(16)].map(() => Math.floor(Math.random() * 16).toString(16)).join('') |
121 | 129 | const tempWorkspace = `web-file-upload-${hash}` |
122 | 130 | const url = `${chunksWorkspace}/${tempWorkspace}` |
|
0 commit comments