mirror of
https://github.com/transloadit/uppy.git
synced 2026-07-17 16:50:22 +00:00
allow getSafeFileId to accept UppyFile
fixes #6033 also convert InternalMetadata to interface (interface is preferred when possible)
This commit is contained in:
parent
b1e33bcef7
commit
251103a2a3
2 changed files with 14 additions and 7 deletions
|
|
@ -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