fix: 修复文档转换与预览链路中的图片、文件名和错误处理问题

This commit is contained in:
2026-04-24 10:40:29 +08:00
parent 37dd58eff0
commit e935afddfe
16 changed files with 451 additions and 69 deletions

View File

@@ -46,7 +46,8 @@ class ConvertDocumentToMarkdown implements ShouldQueue
$markdownPath = $conversionService->saveMarkdownToFile(
$this->document,
$result['markdown']
$result['markdown'],
$result['media_files'] ?? []
);
$conversionService->updateDocumentMarkdown($this->document, $markdownPath);
@@ -56,36 +57,46 @@ class ConvertDocumentToMarkdown implements ShouldQueue
'document_title' => $this->document->title,
'markdown_path' => $markdownPath,
]);
} catch (\Exception $e) {
} catch (\Throwable $e) {
$exception = $this->normalizeException($e);
Log::error('文档转换失败', [
'document_id' => $this->document->id,
'document_title' => $this->document->title,
'file_name' => $this->document->file_name,
'attempt' => $this->attempts(),
'error' => $e->getMessage(),
'error' => $exception->getMessage(),
]);
if ($this->attempts() >= $this->tries) {
$conversionService->handleConversionFailure($this->document, $e);
$conversionService->handleConversionFailure($this->document, $exception);
}
throw $e;
throw $exception;
}
}
public function failed(\Throwable $exception): void
{
$normalized = $this->normalizeException($exception);
Log::error('文档转换任务最终失败', [
'document_id' => $this->document->id,
'document_title' => $this->document->title,
'file_name' => $this->document->file_name,
'error' => $exception->getMessage(),
'error' => $normalized->getMessage(),
]);
$conversionService = app(DocumentConversionService::class);
$conversionService->handleConversionFailure(
$this->document,
$exception instanceof \Exception ? $exception : new \Exception($exception->getMessage())
);
$conversionService->handleConversionFailure($this->document, $normalized);
}
protected function normalizeException(\Throwable $throwable): \Exception
{
if ($throwable instanceof \Exception) {
return $throwable;
}
return new \RuntimeException($throwable->getMessage(), 0, $throwable);
}
}