Skip to content

Commit

Permalink
mov eto utils
Browse files Browse the repository at this point in the history
  • Loading branch information
mifi committed Apr 1, 2023
1 parent 8f5c32d commit 46368c8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 22 deletions.
22 changes: 1 addition & 21 deletions packages/@uppy/core/src/Uppy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
22 changes: 22 additions & 0 deletions packages/@uppy/utils/src/generateFileID.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import getFileType from './getFileType.js'

function encodeCharacter (character) {
return character.charCodeAt(0).toString(32)
}
Expand Down Expand Up @@ -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,
})
}

0 comments on commit 46368c8

Please sign in to comment.