* 将请求 body 写入临时文件,返回文件路径和解析后的 content type 信息
( request: FastifyRequest, isJson: boolean )
| 133 | * 将请求 body 写入临时文件,返回文件路径和解析后的 content type 信息 |
| 134 | */ |
| 135 | async function writeTempFile( |
| 136 | request: FastifyRequest, |
| 137 | isJson: boolean |
| 138 | ): Promise<{ tempFile: string; error?: never } | { tempFile?: never; error: string }> { |
| 139 | if (isJson) { |
| 140 | const body = request.body |
| 141 | if (!body || typeof body !== 'object') { |
| 142 | return { error: 'Request body is not valid JSON' } |
| 143 | } |
| 144 | const tempFile = getTempFilePath('.json') |
| 145 | fs.writeFileSync(tempFile, JSON.stringify(body), 'utf-8') |
| 146 | return { tempFile } |
| 147 | } else { |
| 148 | const tempFile = getTempFilePath('.jsonl') |
| 149 | const writeStream = fs.createWriteStream(tempFile) |
| 150 | await pipeline(request.raw, writeStream) |
| 151 | return { tempFile } |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | /** |
| 156 | * v3 统一导入处理:自动判断新建或增量 |
no test coverage detected