mirror of
https://github.com/langgenius/dify.git
synced 2026-02-12 04:01:29 -05:00
Introduce prepareSkillUploadFile utility that wraps markdown file content in a JSON payload format before uploading. This ensures consistent handling of skill files across file upload, folder upload, and drag-and-drop operations.
16 lines
513 B
TypeScript
16 lines
513 B
TypeScript
import { getFileExtension, isMarkdownFile } from './file-utils'
|
|
|
|
const buildSkillUploadPayload = (content: string) => {
|
|
return JSON.stringify({ content, metadata: {} })
|
|
}
|
|
|
|
export async function prepareSkillUploadFile(file: File): Promise<File> {
|
|
const extension = getFileExtension(file.name)
|
|
if (!isMarkdownFile(extension))
|
|
return file
|
|
|
|
const content = await file.text()
|
|
const payload = buildSkillUploadPayload(content)
|
|
return new File([payload], file.name, { type: file.type || 'text/plain' })
|
|
}
|