mirror of
https://github.com/transloadit/uppy.git
synced 2026-01-23 02:25:07 +00:00
allow getSafeFileId to accept UppyFile (#6048)
fixes #6033
also convert InternalMetadata to interface (interface is preferred when
possible)
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> Broaden `getSafeFileId` to accept `UppyFile` and extend types by
converting `InternalMetadata` to an interface with optional
`relativePath`.
>
> - **utils**:
> - **`getSafeFileId`**: Broadens parameter via new `SafeFileIdBasis` so
it can accept `UppyFile`; call site logic unchanged.
> - **Types**: Convert `InternalMetadata` to an interface and add
optional `relativePath`; propagate through `UppyFile`/`generateFileID`
typings.
> - **Changeset**: Adds patch entry for `@uppy/utils`.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
133240fc0f. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
---------
Co-authored-by: Merlijn Vos <merlijn@soverin.net>
This commit is contained in:
parent
2e14f15e11
commit
ad50314c50
3 changed files with 19 additions and 7 deletions
5
.changeset/tender-yaks-shave.md
Normal file
5
.changeset/tender-yaks-shave.md
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
"@uppy/utils": patch
|
||||
---
|
||||
|
||||
Allow `getSafeFileId` to accept `UppyFile`
|
||||
|
|
@ -4,7 +4,11 @@ export type Meta = Record<string, unknown>
|
|||
|
||||
export type Body = Record<string, unknown>
|
||||
|
||||
export type InternalMetadata = { name: string; type?: string }
|
||||
export interface InternalMetadata {
|
||||
name: string
|
||||
type?: string
|
||||
relativePath?: string
|
||||
}
|
||||
|
||||
// for better readability instead of using Record<string, something>
|
||||
export type UppyFileId = string
|
||||
|
|
|
|||
|
|
@ -77,13 +77,16 @@ function hasFileStableId<M extends Meta, B extends Body>(
|
|||
return stableIdProviders.has(file.remote.provider!)
|
||||
}
|
||||
|
||||
export type SafeFileIdBasis<M extends Meta, B extends Body> = Partial<
|
||||
Pick<UppyFile<M, B>, 'id' | 'type'>
|
||||
> &
|
||||
(
|
||||
| Pick<RemoteUppyFile<M, B>, 'isRemote' | 'remote' | 'data'>
|
||||
| Pick<LocalUppyFile<M, B>, 'isRemote' | 'data'>
|
||||
) & { meta?: { relativePath?: unknown } | undefined }
|
||||
|
||||
export function getSafeFileId<M extends Meta, B extends Body>(
|
||||
file: Partial<Pick<UppyFile<M, B>, 'id' | 'type'>> &
|
||||
Pick<UppyFile<M, B>, 'data'> &
|
||||
(
|
||||
| Pick<RemoteUppyFile<M, B>, 'isRemote' | 'remote'>
|
||||
| Pick<LocalUppyFile<M, B>, 'isRemote'>
|
||||
) & { meta?: { relativePath?: unknown } | undefined },
|
||||
file: SafeFileIdBasis<M, B>,
|
||||
instanceId: string,
|
||||
): string {
|
||||
if (hasFileStableId(file)) return file.id!
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue