Skip to content

Commit

Permalink
@uppy/url: migrate to TS
Browse files Browse the repository at this point in the history
  • Loading branch information
Murderlon authored and aduh95 committed Mar 10, 2024
1 parent c352d27 commit 102d8f8
Show file tree
Hide file tree
Showing 13 changed files with 382 additions and 251 deletions.
37 changes: 5 additions & 32 deletions packages/@uppy/provider-views/src/View.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,12 @@ import type {
UnknownProviderPlugin,
UnknownSearchProviderPlugin,
} from '@uppy/core/lib/Uppy'
import type { Body, Meta } from '@uppy/utils/lib/UppyFile'
import type { Body, Meta, TagFile } from '@uppy/utils/lib/UppyFile'
import type { CompanionFile } from '@uppy/utils/lib/CompanionFile'
import getFileType from '@uppy/utils/lib/getFileType'
import isPreviewSupported from '@uppy/utils/lib/isPreviewSupported'
import remoteFileObjToLocal from '@uppy/utils/lib/remoteFileObjToLocal'

type TagFile<M extends Meta> = {
id: string
source: string
data: Blob
name: string
type: string
isRemote: boolean
preview?: string
meta: {
authorName?: string
authorUrl?: string
relativePath?: string | null
absolutePath?: string
} & M
remote: {
companionUrl: string
url: string
body: {
fileId: string
}
providerName: string
provider: string
requestClientId: string
}
}

type PluginType = 'Provider' | 'SearchProvider'

// Conditional type for selecting the plugin
Expand Down Expand Up @@ -155,7 +129,6 @@ export default class View<
name: file.name || file.id,
type: file.mimeType,
isRemote: true,
// @ts-expect-error meta is filled conditionally below
data: file,
// @ts-expect-error meta is filled conditionally below
meta: {},
Expand Down Expand Up @@ -184,17 +157,17 @@ export default class View<

if (file.author) {
if (file.author.name != null)
tagFile.meta.authorName = String(file.author.name)
if (file.author.url) tagFile.meta.authorUrl = file.author.url
tagFile.meta!.authorName = String(file.author.name)
if (file.author.url) tagFile.meta!.authorUrl = file.author.url
}

// add relativePath similar to non-remote files: https://github.com/transloadit/uppy/pull/4486#issuecomment-1579203717
if (file.relDirPath != null)
tagFile.meta.relativePath =
tagFile.meta!.relativePath =
file.relDirPath ? `${file.relDirPath}/${tagFile.name}` : null
// and absolutePath (with leading slash) https://github.com/transloadit/uppy/pull/4537#issuecomment-1614236655
if (file.absDirPath != null)
tagFile.meta.absolutePath =
tagFile.meta!.absolutePath =
file.absDirPath ?
`/${file.absDirPath}/${tagFile.name}`
: `/${tagFile.name}`
Expand Down
1 change: 1 addition & 0 deletions packages/@uppy/provider-views/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ export {
default as ProviderViews,
defaultPickerIcon,
} from './ProviderView/index.ts'

export { default as SearchProviderViews } from './SearchProviderView/index.ts'
1 change: 1 addition & 0 deletions packages/@uppy/url/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tsconfig.*
195 changes: 0 additions & 195 deletions packages/@uppy/url/src/Url.jsx

This file was deleted.

Loading

0 comments on commit 102d8f8

Please sign in to comment.