mirror of
https://github.com/langgenius/dify.git
synced 2026-07-21 02:28:30 +08:00
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Yansong Zhang <916125788@qq.com>
41 lines
1.2 KiB
TypeScript
41 lines
1.2 KiB
TypeScript
import { Buffer } from 'node:buffer'
|
|
import { mkdir, writeFile } from 'node:fs/promises'
|
|
import path from 'node:path'
|
|
import { fileURLToPath } from 'node:url'
|
|
|
|
export const testMaterialsDir = fileURLToPath(
|
|
new URL('../fixtures/test-materials', import.meta.url),
|
|
)
|
|
export const generatedTestMaterialsDir = fileURLToPath(
|
|
new URL('../.generated-test-materials', import.meta.url),
|
|
)
|
|
|
|
export const voiceInputTestMaterial = {
|
|
fileName: 'voice-input.wav',
|
|
recordingDuration: '00:07',
|
|
} as const
|
|
|
|
export const getTestMaterialPath = (fileName: string) => path.join(testMaterialsDir, fileName)
|
|
export const getVoiceInputTestMaterialPath = () =>
|
|
getTestMaterialPath(voiceInputTestMaterial.fileName)
|
|
|
|
export async function getGeneratedTextMaterialPath({
|
|
fileName,
|
|
sizeBytes,
|
|
seedText,
|
|
}: {
|
|
fileName: string
|
|
sizeBytes: number
|
|
seedText: string
|
|
}) {
|
|
await mkdir(generatedTestMaterialsDir, { recursive: true })
|
|
|
|
const targetPath = path.join(generatedTestMaterialsDir, fileName)
|
|
const chunk = `${seedText}\n`
|
|
const repeatCount = Math.ceil(sizeBytes / Buffer.byteLength(chunk))
|
|
const contents = chunk.repeat(repeatCount).slice(0, sizeBytes)
|
|
await writeFile(targetPath, contents)
|
|
|
|
return targetPath
|
|
}
|