This commit is contained in:
@@ -7,6 +7,7 @@ using Microsoft.Extensions.Logging;
|
||||
using AyaNova.Models;
|
||||
using AyaNova.Api.ControllerHelpers;
|
||||
using AyaNova.Biz;
|
||||
using AyaNova.Util;
|
||||
using PuppeteerSharp;
|
||||
|
||||
namespace AyaNova.Api.Controllers
|
||||
@@ -38,48 +39,67 @@ namespace AyaNova.Api.Controllers
|
||||
|
||||
|
||||
[HttpGet("render/{test}")]
|
||||
[AllowAnonymous]
|
||||
public async Task<IActionResult> GetTestReport([FromRoute] string test)
|
||||
{
|
||||
if (!serverState.IsOpen)
|
||||
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
||||
|
||||
string outputFile = FileUtil.NewRandomTempFilesFolderFileName;
|
||||
|
||||
switch (test)
|
||||
{
|
||||
case "chrome-reddit-to-pdf":
|
||||
//first test, just render a web page to pdf and return it
|
||||
//return PhysicalFile(filePath, mimetype, dbObject.DisplayFileName);
|
||||
|
||||
outputFile += ".pdf";
|
||||
//http://www.puppeteersharp.com/api/index.html
|
||||
//https://github.com/hardkoded/puppeteer-sharp
|
||||
await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision);
|
||||
var browser = await Puppeteer.LaunchAsync(new LaunchOptions
|
||||
{
|
||||
Headless = true
|
||||
});
|
||||
var page = await browser.NewPageAsync();
|
||||
await page.GoToAsync("http://www.reddit.com");
|
||||
await page.GoToAsync("https://github.com/hardkoded/puppeteer-sharp");
|
||||
|
||||
await page.PdfAsync(outputFile);
|
||||
|
||||
|
||||
break;
|
||||
return PhysicalFile(outputFile, "application/pdf");
|
||||
}
|
||||
|
||||
|
||||
return NotFound(test);
|
||||
|
||||
//return PhysicalFile(filePath, mimetype, dbObject.DisplayFileName);
|
||||
}
|
||||
//http://www.puppeteersharp.com/api/index.html
|
||||
//https://github.com/hardkoded/puppeteer-sharp
|
||||
|
||||
|
||||
[HttpGet("render/pdf/{url}")]
|
||||
[AllowAnonymous]
|
||||
public async Task<IActionResult> GetUrlPdfReport([FromRoute] string url)
|
||||
{
|
||||
if (!serverState.IsOpen)
|
||||
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
||||
string outputFile = FileUtil.NewRandomTempFilesFolderFileName;
|
||||
//first test, just render a web page to pdf and return it
|
||||
//return PhysicalFile(filePath, mimetype, dbObject.DisplayFileName);
|
||||
outputFile += ".pdf";
|
||||
//http://www.puppeteersharp.com/api/index.html
|
||||
//https://github.com/hardkoded/puppeteer-sharp
|
||||
await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision);
|
||||
var browser = await Puppeteer.LaunchAsync(new LaunchOptions
|
||||
{
|
||||
Headless = true
|
||||
});
|
||||
var page = await browser.NewPageAsync();
|
||||
await page.GoToAsync(url);
|
||||
await page.PdfAsync(outputFile);
|
||||
return PhysicalFile(outputFile, "application/pdf");
|
||||
}
|
||||
|
||||
//------------
|
||||
/*
|
||||
NOTES/TODO during testing
|
||||
/*
|
||||
NOTES/TODO during testing
|
||||
|
||||
Need a temporary folder path dedicated to generating pdf's etc, a utility path just for that purpose, perhaps in a dedicated folder in the utility / backup region
|
||||
Need job to automatically erase any temp files older than 5 minutes (or whatever)
|
||||
|
||||
|
||||
*/
|
||||
*/
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
Reference in New Issue
Block a user