MCPcopy Create free account
hub / github.com/ChatLab/ChatLab / writeTempFile

Function writeTempFile

apps/desktop/main/api/routes/import.ts:135–153  ·  view source on GitHub ↗

* 将请求 body 写入临时文件,返回文件路径和解析后的 content type 信息

(
  request: FastifyRequest,
  isJson: boolean
)

Source from the content-addressed store, hash-verified

133 * 将请求 body 写入临时文件,返回文件路径和解析后的 content type 信息
134 */
135async 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 统一导入处理:自动判断新建或增量

Callers 2

handleUnifiedImportFunction · 0.85
handleLegacyImportFunction · 0.85

Calls 1

getTempFilePathFunction · 0.70

Tested by

no test coverage detected