-
Notifications
You must be signed in to change notification settings - Fork 12
feat(upload): merge upload related API from @nextcloud/upload
#1509
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
204201a
feat(upload): merge upload classes from `@nextcloud/upload`
susnux 28aaa7f
refactor(upload): resolve linter issues (`npm run lint:fix`)
susnux 22f3b17
refactor(upload): drop duplicated logger
susnux 7b65ce5
refactor(upload): merge window declarations
susnux ce3f236
refactor(upload): use consistent case for filenames
susnux 9f007e5
fix(upload): use scoped globals for the files uploader
susnux fb33863
fix(upload): use proper local imports for files API
susnux a809431
refactor(upload): adjust code for Typescript erasable syntax
susnux e740dce
refactor(upload): migrate from `p-cancelable` to native AbortController
susnux e43053b
refactor(upload): remove localization - this is pure API
susnux 2c4eb92
test: add unit tests for uploader
susnux File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| /*! | ||
| * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| import { expect, test } from 'vitest' | ||
| import { UploadCancelledError } from './UploadCancelledError.ts' | ||
|
|
||
| test('UploadCancelledError', () => { | ||
| const cause = new Error('Network error') | ||
| const error = new UploadCancelledError(cause) | ||
| expect(error).toBeInstanceOf(Error) | ||
| expect(error).toBeInstanceOf(UploadCancelledError) | ||
| expect(error.message).toBe('Upload has been cancelled') | ||
| expect(error.cause).toBe(cause) | ||
| expect(error).toHaveProperty('__UPLOAD_CANCELLED__') | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| /*! | ||
| * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| export class UploadCancelledError extends Error { | ||
| __UPLOAD_CANCELLED__ = true | ||
|
|
||
| public constructor(cause?: unknown) { | ||
| super('Upload has been cancelled', { cause }) | ||
| } | ||
|
|
||
| public static isCancelledError(error: unknown): error is UploadCancelledError { | ||
| return typeof error === 'object' && error !== null && (error as UploadCancelledError).__UPLOAD_CANCELLED__ === true | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| /*! | ||
| * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| import { join } from '@nextcloud/paths' | ||
| import { expect, test } from 'vitest' | ||
| import { defaultRemoteURL, defaultRootPath } from '../dav/dav.ts' | ||
| import { scopedGlobals } from '../globalScope.ts' | ||
| import { Folder } from '../node/folder.ts' | ||
| import { getUploader } from './getUploader.ts' | ||
| import { Uploader } from './uploader/Uploader.ts' | ||
|
|
||
| test('getUploader - should return the uploader instance from the global scope', async () => { | ||
| const uploader = new Uploader(false, new Folder({ owner: 'test', root: defaultRootPath, source: join(defaultRemoteURL, defaultRootPath) })) | ||
| scopedGlobals.uploader = uploader | ||
| const returnedUploader = getUploader() | ||
| expect(returnedUploader).toBe(uploader) | ||
| }) | ||
|
|
||
| test('getUploader - should return the same instance on multiple calls', async () => { | ||
| const uploader1 = getUploader() | ||
| const uploader2 = getUploader() | ||
| expect(uploader1).toBe(uploader2) | ||
| }) | ||
|
|
||
| test('getUploader - should not return the same instance on multiple calls with forceRecreate', async () => { | ||
| const uploader1 = getUploader(true) | ||
| const uploader2 = getUploader(true, true) | ||
| expect(uploader1).not.toBe(uploader2) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| /*! | ||
| * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| import { isPublicShare } from '@nextcloud/sharing/public' | ||
| import { scopedGlobals } from '../globalScope.ts' | ||
| import { Uploader } from './uploader/Uploader.ts' | ||
|
|
||
| /** | ||
| * Get the global Uploader instance. | ||
| * | ||
| * Note: If you need a local uploader you can just create a new instance, | ||
| * this global instance will be shared with other apps and is mostly useful | ||
| * for the Files app web UI to keep track of all uploads and their progress. | ||
| * | ||
| * @param isPublic Set to true to use public upload endpoint (by default it is auto detected) | ||
| * @param forceRecreate Force a new uploader instance - main purpose is for testing | ||
| */ | ||
| export function getUploader(isPublic: boolean = isPublicShare(), forceRecreate = false): Uploader { | ||
| if (forceRecreate || scopedGlobals.uploader === undefined) { | ||
| scopedGlobals.uploader = new Uploader(isPublic) | ||
| } | ||
|
|
||
| return scopedGlobals.uploader | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| /*! | ||
| * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| export type { Eta, EtaEventsMap } from './uploader/index.ts' | ||
| export type { Directory, IDirectory } from './utils/fileTree.ts' | ||
|
|
||
| export { getUploader } from './getUploader.ts' | ||
| export { Upload, UploadStatus } from './uploader/Upload.ts' | ||
| export { EtaStatus, Uploader, UploaderStatus } from './uploader/index.ts' | ||
| export { getConflicts, hasConflict } from './utils/conflicts.ts' |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I always wonder if we should not auto detect the public boolean. What if an app creates a normal instance and the other a public without forceCreate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes we should!
but lets do changes in separate PRs this PR is mainly for copy it over and adjust code to work in this repo