This commit is contained in:
2020-08-25 19:18:36 +00:00
parent cfbb70c284
commit 6c7faff512
4 changed files with 41 additions and 12 deletions

View File

@@ -243,7 +243,3 @@ DOCKER / LINUX CHEAT SHEET
<!-- <Target Name="CopyCustomContent" AfterTargets="AfterBuild">
<Copy SourceFiles=".\resource\ay-report.js;" DestinationFolder="$(OutDir)\resource\rpt" />
<!-- <Copy SourceFiles=".\resource\rpt\ay-report.js;.\resource\rpt\ay-hb.js;.\resource\rpt\ay-md.js" DestinationFolder="$(OutDir)\resource\rpt" /> -->
</Target> -->

View File

@@ -2,4 +2,13 @@ FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-alpine
WORKDIR /app
COPY ./files .
RUN apk add postgresql-client
RUN apk add --no-cache \
chromium \
nss \
freetype \
freetype-dev \
harfbuzz \
ca-certificates \
ttf-freefont
ENTRYPOINT ["dotnet", "AyaNova.dll"]

View File

@@ -44,15 +44,21 @@
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUi" Version="5.4.1" />
</ItemGroup>
<Target Name="CopyCustomContent" AfterTargets="AfterBuild">
<Copy SourceFiles=".\resource\de.json;.\resource\en.json;.\resource\es.json;.\resource\fr.json" DestinationFolder="$(OutDir)\resource" />
<!-- <Copy SourceFiles=".\resource\rpt\ay-report.js;.\resource\rpt\ay-hb.js;.\resource\rpt\ay-md.js" DestinationFolder="$(OutDir)\resource\rpt" /> -->
</Target>
<!-- <Target Name="CopyCustomContent" AfterTargets="AfterBuild">
<Copy SourceFiles=".\resource\de.json;.\resource\en.json;.\resource\es.json;.\resource\fr.json" DestinationFolder="$(OutDir)\resource" />
</Target> -->
<ItemGroup>
<Content Include=".\resource\rpt\*.*">
<ItemGroup>
<Content Include=".\resource\*.*">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<Content Include=".\resource\rpt\*.*">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>

View File

@@ -91,7 +91,7 @@ namespace AyaNova.Api.Controllers
if (!Directory.Exists(ReportJSFolderPath))
throw new System.Exception($"E1012: \"reportjs\" folder not found where expected: \"{ReportJSFolderPath}\", installation damaged?");
await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision);
//sample CSS
var reportCSS = @"
@@ -123,9 +123,26 @@ namespace AyaNova.Api.Controllers
var aylogo = $"{{small:'{API_URL}logo/small',medium:'{API_URL}logo/medium',large:'{API_URL}logo/large'}}";
var reportData = "{ person: { firstname: 'Tyler', lastname: 'Mott' },aylogo:[AYLOGO], mdtest:'| CODE | MEANING |\\n| ----- | ------------------------------ |\\n| E1000 | Could not connect to the database specified in the [connection string](ops-config-db.md). |\\n| E1050 | XXXXXXXX |\\n| E1012 | Missing resource folder. AyaNova was started from the wrong location or was not installed properly. |\\n' }";
reportData = reportData.Replace("[AYLOGO]", aylogo);
using (var browser = await Puppeteer.LaunchAsync(new LaunchOptions { Headless = true }))
log.LogInformation($"setting Chrome launchoptions for os:");
var lo = new LaunchOptions { Headless = true };
bool isWindows = System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows);
if (!isWindows)
{
log.LogInformation($"IS NOT WINDOWS: setting executable path for chrome");
lo.ExecutablePath = "/usr/bin/chromium-browser";
lo.Args = new string[] { "--no-sandbox" };
}
else
{
log.LogInformation($"IS WINDOWS: Calling browserFetcher download async now:");
await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision);
}
log.LogInformation($"Calling browser.launchAsync now:");
using (var browser = await Puppeteer.LaunchAsync(lo))
using (var page = await browser.NewPageAsync())
{
log.LogInformation($"In using for page ops adding scripts and report now:");
//Add handlebars JS for compiling and presenting
await page.AddScriptTagAsync(new AddTagOptions() { Path = Path.Combine(ReportJSFolderPath, "ay-hb.js") });
@@ -156,6 +173,7 @@ namespace AyaNova.Api.Controllers
//render to pdf and return
var pdfBuffer = await page.PdfDataAsync();
log.LogInformation($"returning results now:");
return new FileContentResult(pdfBuffer, "application/pdf");
}