From 2c7693c4e34a0b57b52aec682fd1a54cc0bb4e50 Mon Sep 17 00:00:00 2001 From: zpc Date: Wed, 18 Mar 2026 00:56:17 +0800 Subject: [PATCH] 21 --- server/MiAssessment/src/MiAssessment.Api/Dockerfile | 7 +++++++ .../src/MiAssessment.Core/Services/PdfGenerationService.cs | 4 +++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/server/MiAssessment/src/MiAssessment.Api/Dockerfile b/server/MiAssessment/src/MiAssessment.Api/Dockerfile index 5afb52a..a8edcf7 100644 --- a/server/MiAssessment/src/MiAssessment.Api/Dockerfile +++ b/server/MiAssessment/src/MiAssessment.Api/Dockerfile @@ -39,4 +39,11 @@ RUN dotnet publish MiAssessment.Api.csproj -c $BUILD_CONFIGURATION -o /app/publi FROM base AS final WORKDIR /app COPY --from=publish /app/publish . + +# 创建 PDF 输出目录和静态图片目录,并赋予写入权限 +USER root +RUN mkdir -p /app/wwwroot/reports /app/wwwroot/images/report \ + && chown -R $APP_UID:$APP_UID /app/wwwroot/reports /app/wwwroot/images/report +USER $APP_UID + ENTRYPOINT ["dotnet", "MiAssessment.Api.dll"] diff --git a/server/MiAssessment/src/MiAssessment.Core/Services/PdfGenerationService.cs b/server/MiAssessment/src/MiAssessment.Core/Services/PdfGenerationService.cs index 60c1875..995d822 100644 --- a/server/MiAssessment/src/MiAssessment.Core/Services/PdfGenerationService.cs +++ b/server/MiAssessment/src/MiAssessment.Core/Services/PdfGenerationService.cs @@ -205,7 +205,9 @@ public class PdfGenerationService : IPdfGenerationService return null; } - var imagePath = Path.Combine("wwwroot", "images", "static-pages", config.ImageUrl); + // 去掉前导斜杠,避免 Path.Combine 在 Linux 上将其视为绝对路径 + var relativePath = config.ImageUrl.TrimStart('/'); + var imagePath = Path.Combine("wwwroot", relativePath); if (!File.Exists(imagePath)) { _logger.LogWarning("静态图片文件不存在,跳过页面: {PageName},路径: {ImagePath}",