mirror of
https://github.com/langgenius/dify.git
synced 2026-01-08 07:14:14 +00:00
refactor: update file upload and download handling for pipeline format
This commit is contained in:
@@ -66,7 +66,7 @@ const DropDown = ({
|
|||||||
const a = document.createElement('a')
|
const a = document.createElement('a')
|
||||||
const file = new Blob([data], { type: 'application/yaml' })
|
const file = new Blob([data], { type: 'application/yaml' })
|
||||||
a.href = URL.createObjectURL(file)
|
a.href = URL.createObjectURL(file)
|
||||||
a.download = `${name}.yml`
|
a.download = `${name}.pipeline`
|
||||||
a.click()
|
a.click()
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
|
|||||||
@@ -17,12 +17,16 @@ export type Props = {
|
|||||||
file: File | undefined
|
file: File | undefined
|
||||||
updateFile: (file?: File) => void
|
updateFile: (file?: File) => void
|
||||||
className?: string
|
className?: string
|
||||||
|
accept?: string
|
||||||
|
displayName?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
const Uploader: FC<Props> = ({
|
const Uploader: FC<Props> = ({
|
||||||
file,
|
file,
|
||||||
updateFile,
|
updateFile,
|
||||||
className,
|
className,
|
||||||
|
accept = '.yaml,.yml',
|
||||||
|
displayName = 'YAML',
|
||||||
}) => {
|
}) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const { notify } = useContext(ToastContext)
|
const { notify } = useContext(ToastContext)
|
||||||
@@ -95,9 +99,9 @@ const Uploader: FC<Props> = ({
|
|||||||
<input
|
<input
|
||||||
ref={fileUploader}
|
ref={fileUploader}
|
||||||
style={{ display: 'none' }}
|
style={{ display: 'none' }}
|
||||||
type="file"
|
type='file'
|
||||||
id="fileUploader"
|
id='fileUploader'
|
||||||
accept='.yaml,.yml'
|
accept={accept}
|
||||||
onChange={fileChangeHandle}
|
onChange={fileChangeHandle}
|
||||||
/>
|
/>
|
||||||
<div ref={dropRef}>
|
<div ref={dropRef}>
|
||||||
@@ -116,12 +120,12 @@ const Uploader: FC<Props> = ({
|
|||||||
{file && (
|
{file && (
|
||||||
<div className={cn('group flex items-center rounded-lg border-[0.5px] border-components-panel-border bg-components-panel-on-panel-item-bg shadow-xs', ' hover:bg-components-panel-on-panel-item-bg-hover')}>
|
<div className={cn('group flex items-center rounded-lg border-[0.5px] border-components-panel-border bg-components-panel-on-panel-item-bg shadow-xs', ' hover:bg-components-panel-on-panel-item-bg-hover')}>
|
||||||
<div className='flex items-center justify-center p-3'>
|
<div className='flex items-center justify-center p-3'>
|
||||||
<YamlIcon className="h-6 w-6 shrink-0" />
|
<YamlIcon className='h-6 w-6 shrink-0' />
|
||||||
</div>
|
</div>
|
||||||
<div className='flex grow flex-col items-start gap-0.5 py-1 pr-2'>
|
<div className='flex grow flex-col items-start gap-0.5 py-1 pr-2'>
|
||||||
<span className='font-inter max-w-[calc(100%_-_30px)] overflow-hidden text-ellipsis whitespace-nowrap text-[12px] font-medium leading-4 text-text-secondary'>{file.name}</span>
|
<span className='font-inter max-w-[calc(100%_-_30px)] overflow-hidden text-ellipsis whitespace-nowrap text-[12px] font-medium leading-4 text-text-secondary'>{file.name}</span>
|
||||||
<div className='font-inter flex h-3 items-center gap-1 self-stretch text-[10px] font-medium uppercase leading-3 text-text-tertiary'>
|
<div className='font-inter flex h-3 items-center gap-1 self-stretch text-[10px] font-medium uppercase leading-3 text-text-tertiary'>
|
||||||
<span>YAML</span>
|
<span>{displayName}</span>
|
||||||
<span className='text-text-quaternary'>·</span>
|
<span className='text-text-quaternary'>·</span>
|
||||||
<span>{formatFileSize(file.size)}</span>
|
<span>{formatFileSize(file.size)}</span>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ const Uploader: FC<Props> = ({
|
|||||||
style={{ display: 'none' }}
|
style={{ display: 'none' }}
|
||||||
type='file'
|
type='file'
|
||||||
id='fileUploader'
|
id='fileUploader'
|
||||||
accept='.yaml,.yml'
|
accept='.pipeline'
|
||||||
onChange={fileChangeHandle}
|
onChange={fileChangeHandle}
|
||||||
/>
|
/>
|
||||||
<div ref={dropRef}>
|
<div ref={dropRef}>
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ const TemplateCard = ({
|
|||||||
const blob = new Blob([res.data], { type: 'application/yaml' })
|
const blob = new Blob([res.data], { type: 'application/yaml' })
|
||||||
downloadFile({
|
downloadFile({
|
||||||
data: blob,
|
data: blob,
|
||||||
fileName: `${pipeline.name}.yml`,
|
fileName: `${pipeline.name}.pipeline`,
|
||||||
})
|
})
|
||||||
Toast.notify({
|
Toast.notify({
|
||||||
type: 'success',
|
type: 'success',
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ const DatasetCard = ({
|
|||||||
const a = document.createElement('a')
|
const a = document.createElement('a')
|
||||||
const file = new Blob([data], { type: 'application/yaml' })
|
const file = new Blob([data], { type: 'application/yaml' })
|
||||||
a.href = URL.createObjectURL(file)
|
a.href = URL.createObjectURL(file)
|
||||||
a.download = `${name}.yml`
|
a.download = `${name}.pipeline`
|
||||||
a.click()
|
a.click()
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
|
|||||||
@@ -233,6 +233,8 @@ const UpdateDSLModal = ({
|
|||||||
file={currentFile}
|
file={currentFile}
|
||||||
updateFile={handleFile}
|
updateFile={handleFile}
|
||||||
className='!mt-0 w-full'
|
className='!mt-0 w-full'
|
||||||
|
accept='.pipeline'
|
||||||
|
displayName='PIPELINE'
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ export const useDSL = () => {
|
|||||||
const a = document.createElement('a')
|
const a = document.createElement('a')
|
||||||
const file = new Blob([data], { type: 'application/yaml' })
|
const file = new Blob([data], { type: 'application/yaml' })
|
||||||
a.href = URL.createObjectURL(file)
|
a.href = URL.createObjectURL(file)
|
||||||
a.download = `${knowledgeName}.yml`
|
a.download = `${knowledgeName}.pipeline`
|
||||||
a.click()
|
a.click()
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
|
|||||||
Reference in New Issue
Block a user