diff --git a/packages/@uppy/core/src/Uppy.js b/packages/@uppy/core/src/Uppy.js index 522ca0f419..ce45394923 100644 --- a/packages/@uppy/core/src/Uppy.js +++ b/packages/@uppy/core/src/Uppy.js @@ -8,7 +8,7 @@ import throttle from 'lodash.throttle' import DefaultStore from '@uppy/store-default' import getFileType from '@uppy/utils/lib/getFileType' import getFileNameAndExtension from '@uppy/utils/lib/getFileNameAndExtension' -import generateFileID from '@uppy/utils/lib/generateFileID' +import { getSafeFileId } from '@uppy/utils/lib/generateFileID' import supportsUploadProgress from './supportsUploadProgress.js' import getFileName from './getFileName.js' import { justErrorsLogger, debugLogger } from './loggers.js' @@ -1570,24 +1570,4 @@ class Uppy { } } -// If the provider has a stable, unique ID, then we can use that to identify the file. -// Then we don't have to generate our own ID, and we can add the same file many times if needed (different path) -function hasFileStableId (file) { - if (!file.isRemote || !file.remote) return false - // These are the providers that it seems like have stable IDs for their files. The other's I haven't checked yet. - const stableIdProviders = new Set(['box', 'dropbox', 'drive', 'facebook', 'unsplash']) - return stableIdProviders.has(file.remote.provider) -} - -export function getSafeFileId (file) { - if (hasFileStableId(file)) return file.id - - const fileType = getFileType(file) - - return generateFileID({ - ...file, - type: fileType, - }) -} - export default Uppy diff --git a/packages/@uppy/provider-views/src/ProviderView/ProviderView.jsx b/packages/@uppy/provider-views/src/ProviderView/ProviderView.jsx index a0008a6d7a..3690cf6348 100644 --- a/packages/@uppy/provider-views/src/ProviderView/ProviderView.jsx +++ b/packages/@uppy/provider-views/src/ProviderView/ProviderView.jsx @@ -1,6 +1,6 @@ import { h } from 'preact' -import { getSafeFileId } from '@uppy/core/lib/Uppy.js' +import { getSafeFileId } from '@uppy/utils/lib/generateFileID' import AuthView from './AuthView.jsx' import Header from './Header.jsx' diff --git a/packages/@uppy/utils/src/generateFileID.js b/packages/@uppy/utils/src/generateFileID.js index 73a88fc4e9..bdb6367658 100644 --- a/packages/@uppy/utils/src/generateFileID.js +++ b/packages/@uppy/utils/src/generateFileID.js @@ -1,3 +1,5 @@ +import getFileType from './getFileType.js' + function encodeCharacter (character) { return character.charCodeAt(0).toString(32) } @@ -43,3 +45,23 @@ export default function generateFileID (file) { return id } + +// If the provider has a stable, unique ID, then we can use that to identify the file. +// Then we don't have to generate our own ID, and we can add the same file many times if needed (different path) +function hasFileStableId (file) { + if (!file.isRemote || !file.remote) return false + // These are the providers that it seems like have stable IDs for their files. The other's I haven't checked yet. + const stableIdProviders = new Set(['box', 'dropbox', 'drive', 'facebook', 'unsplash']) + return stableIdProviders.has(file.remote.provider) +} + +export function getSafeFileId (file) { + if (hasFileStableId(file)) return file.id + + const fileType = getFileType(file) + + return generateFileID({ + ...file, + type: fileType, + }) +}