allow getSafeFileId to accept UppyFile

fixes #6033
also convert InternalMetadata to interface (interface is preferred when possible)
This commit is contained in:
Mikael Finstad 2025-11-03 17:34:08 +08:00
parent b1e33bcef7
commit 251103a2a3
No known key found for this signature in database
GPG key ID: 25AB36E3E81CBC26
2 changed files with 14 additions and 7 deletions

View file

@ -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

View file

@ -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!