* Stores the compiled PDF as an execution file when execution context is * available, falling back to general storage otherwise.
( pdfBuffer: Buffer, body: LatexCompileBody, compiler: string, userId: string )
| 218 | * available, falling back to general storage otherwise. |
| 219 | */ |
| 220 | async function storeCompiledPdf( |
| 221 | pdfBuffer: Buffer, |
| 222 | body: LatexCompileBody, |
| 223 | compiler: string, |
| 224 | userId: string |
| 225 | ): Promise<StoredPdfResponse> { |
| 226 | const fileName = buildPdfFileName(body.fileName) |
| 227 | const executionContext = |
| 228 | body.workspaceId && body.workflowId && body.executionId |
| 229 | ? { |
| 230 | workspaceId: body.workspaceId, |
| 231 | workflowId: body.workflowId, |
| 232 | executionId: body.executionId, |
| 233 | } |
| 234 | : null |
| 235 | |
| 236 | if (executionContext) { |
| 237 | const { uploadExecutionFile } = await import('@/lib/uploads/contexts/execution') |
| 238 | const pdfFile = await uploadExecutionFile( |
| 239 | executionContext, |
| 240 | pdfBuffer, |
| 241 | fileName, |
| 242 | 'application/pdf', |
| 243 | userId |
| 244 | ) |
| 245 | |
| 246 | return { |
| 247 | pdfFile, |
| 248 | pdfUrl: pdfFile.url, |
| 249 | fileName, |
| 250 | contentType: 'application/pdf', |
| 251 | compiler, |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | const { StorageService } = await import('@/lib/uploads') |
| 256 | const fileInfo = await StorageService.uploadFile({ |
| 257 | file: pdfBuffer, |
| 258 | fileName, |
| 259 | contentType: 'application/pdf', |
| 260 | context: 'copilot', |
| 261 | }) |
| 262 | |
| 263 | return { |
| 264 | pdfUrl: `${getBaseUrl()}${fileInfo.path}`, |
| 265 | fileName, |
| 266 | contentType: 'application/pdf', |
| 267 | compiler, |
| 268 | } |
| 269 | } |
no test coverage detected