This commit is contained in:
@@ -36,6 +36,7 @@
|
||||
<PackageReference Include="NLog" Version="4.7.2" />
|
||||
<PackageReference Include="NLog.Web.AspNetCore" Version="4.9.2" />
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="3.1.4" />
|
||||
<PackageReference Include="PuppeteerSharp" Version="2.0.4" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.4.1" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="5.4.1" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="5.4.1" />
|
||||
|
||||
@@ -7,7 +7,7 @@ using Microsoft.Extensions.Logging;
|
||||
using AyaNova.Models;
|
||||
using AyaNova.Api.ControllerHelpers;
|
||||
using AyaNova.Biz;
|
||||
|
||||
using PuppeteerSharp;
|
||||
|
||||
namespace AyaNova.Api.Controllers
|
||||
{
|
||||
@@ -44,11 +44,24 @@ namespace AyaNova.Api.Controllers
|
||||
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
||||
|
||||
|
||||
switch(test){
|
||||
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);
|
||||
break;
|
||||
//first test, just render a web page to pdf and return it
|
||||
//return PhysicalFile(filePath, mimetype, dbObject.DisplayFileName);
|
||||
|
||||
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.PdfAsync(outputFile);
|
||||
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -56,11 +69,17 @@ namespace AyaNova.Api.Controllers
|
||||
|
||||
//return PhysicalFile(filePath, mimetype, dbObject.DisplayFileName);
|
||||
}
|
||||
|
||||
//https://github.com/hardkoded/puppeteer-sharp
|
||||
//http://www.puppeteersharp.com/api/index.html
|
||||
//https://github.com/hardkoded/puppeteer-sharp
|
||||
|
||||
//------------
|
||||
/*
|
||||
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
|
||||
|
||||
|
||||
*/
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
@@ -154,6 +154,7 @@ namespace AyaNova.Api.Controllers
|
||||
AYANOVA_DB_CONNECTION = ServerBootConfig.AYANOVA_DB_CONNECTION,
|
||||
AYANOVA_FOLDER_USER_FILES = ServerBootConfig.AYANOVA_FOLDER_USER_FILES,
|
||||
AYANOVA_FOLDER_BACKUP_FILES = ServerBootConfig.AYANOVA_FOLDER_BACKUP_FILES,
|
||||
AYANOVA_FOLDER_TEMPORARY_SERVER_FILES = ServerBootConfig.AYANOVA_FOLDER_TEMPORARY_SERVER_FILES,
|
||||
AYANOVA_BACKUP_PG_DUMP_PATH = ServerBootConfig.AYANOVA_BACKUP_PG_DUMP_PATH,
|
||||
AYANOVA_LOG_PATH = ServerBootConfig.AYANOVA_LOG_PATH,
|
||||
AYANOVA_LOG_LEVEL = ServerBootConfig.AYANOVA_LOG_LEVEL,
|
||||
|
||||
@@ -33,24 +33,33 @@ namespace AyaNova.Util
|
||||
|
||||
//UserFiles
|
||||
if (string.IsNullOrWhiteSpace(ServerBootConfig.AYANOVA_FOLDER_USER_FILES))
|
||||
{
|
||||
ServerBootConfig.AYANOVA_FOLDER_USER_FILES = Path.Combine(contentRootPath, "userfiles");
|
||||
}
|
||||
|
||||
|
||||
//BackupFiles
|
||||
if (ServerBootConfig.AYANOVA_FOLDER_BACKUP_FILES == null)
|
||||
{
|
||||
ServerBootConfig.AYANOVA_FOLDER_BACKUP_FILES = Path.Combine(contentRootPath, "backupfiles");
|
||||
}
|
||||
|
||||
|
||||
//Temporary system files (reports etc)
|
||||
if (ServerBootConfig.AYANOVA_FOLDER_TEMPORARY_SERVER_FILES == null)
|
||||
ServerBootConfig.AYANOVA_FOLDER_TEMPORARY_SERVER_FILES = Path.Combine(contentRootPath, "tempfiles");
|
||||
|
||||
|
||||
|
||||
//Prevent using the same folder for both
|
||||
if (string.Equals(Path.GetFullPath(ServerBootConfig.AYANOVA_FOLDER_USER_FILES), Path.GetFullPath(ServerBootConfig.AYANOVA_FOLDER_BACKUP_FILES), StringComparison.OrdinalIgnoreCase))
|
||||
if (
|
||||
string.Equals(Path.GetFullPath(ServerBootConfig.AYANOVA_FOLDER_USER_FILES), Path.GetFullPath(ServerBootConfig.AYANOVA_FOLDER_BACKUP_FILES), StringComparison.OrdinalIgnoreCase) ||
|
||||
string.Equals(Path.GetFullPath(ServerBootConfig.AYANOVA_FOLDER_USER_FILES), Path.GetFullPath(ServerBootConfig.AYANOVA_FOLDER_TEMPORARY_SERVER_FILES), StringComparison.OrdinalIgnoreCase) ||
|
||||
string.Equals(Path.GetFullPath(ServerBootConfig.AYANOVA_FOLDER_BACKUP_FILES), Path.GetFullPath(ServerBootConfig.AYANOVA_FOLDER_TEMPORARY_SERVER_FILES), StringComparison.OrdinalIgnoreCase)
|
||||
)
|
||||
{
|
||||
throw new System.NotSupportedException("E1040: The configuration settings AYANOVA_FOLDER_USER_FILES and the AYANOVA_FOLDER_BACKUP_FILES must not point to the exact same location");
|
||||
throw new System.NotSupportedException("E1040: The configuration settings AYANOVA_FOLDER_USER_FILES, AYANOVA_FOLDER_BACKUP_FILES and AYANOVA_FOLDER_TEMPORARY_SYSTEM_FILES must all be different locations");
|
||||
}
|
||||
|
||||
EnsurePath(ServerBootConfig.AYANOVA_FOLDER_USER_FILES);
|
||||
EnsurePath(ServerBootConfig.AYANOVA_FOLDER_BACKUP_FILES);
|
||||
EnsurePath(ServerBootConfig.AYANOVA_FOLDER_TEMPORARY_SERVER_FILES);
|
||||
}
|
||||
|
||||
//create path if doesn't exist already
|
||||
@@ -61,6 +70,35 @@ namespace AyaNova.Util
|
||||
}
|
||||
#endregion folder ensurance
|
||||
|
||||
#region Temporary files handling
|
||||
/// <summary>
|
||||
/// Get backup file folder
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
internal static string TemporaryFilesFolder
|
||||
{
|
||||
get
|
||||
{
|
||||
return ServerBootConfig.AYANOVA_FOLDER_TEMPORARY_SERVER_FILES;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Get a random file name with path to temporary files folder
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
internal static string NewRandomTempFilesFolderFileName
|
||||
{
|
||||
get
|
||||
{
|
||||
return Path.Combine(TemporaryFilesFolder, NewRandomFileName);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Utility (BACKUP) file handling
|
||||
|
||||
|
||||
@@ -315,17 +353,7 @@ namespace AyaNova.Util
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Get a random file name
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
internal static string NewRandomFileName
|
||||
{
|
||||
get
|
||||
{
|
||||
return Path.GetRandomFileName();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Get a random file name with path to attachments folder
|
||||
@@ -569,6 +597,18 @@ namespace AyaNova.Util
|
||||
|
||||
#region General utilities
|
||||
|
||||
/// <summary>
|
||||
/// Get a random file name
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
internal static string NewRandomFileName
|
||||
{
|
||||
get
|
||||
{
|
||||
return Path.GetRandomFileName();
|
||||
}
|
||||
}
|
||||
|
||||
//https://stackoverflow.com/a/11124118/8939
|
||||
// Returns the human-readable file size for an arbitrary, 64-bit file size
|
||||
// The default format is "0.### XB", e.g. "4.2 KB" or "1.434 GB"
|
||||
|
||||
@@ -46,6 +46,7 @@ namespace AyaNova.Util
|
||||
//FILE FOLDERS
|
||||
internal static string AYANOVA_FOLDER_USER_FILES { get; set; }
|
||||
internal static string AYANOVA_FOLDER_BACKUP_FILES { get; set; }
|
||||
internal static string AYANOVA_FOLDER_TEMPORARY_SERVER_FILES { get; set; }
|
||||
|
||||
//BACKUP PG_DUMP PATH (IF NOT IN PATH ALREADY)
|
||||
internal static string AYANOVA_BACKUP_PG_DUMP_PATH { get; set; }
|
||||
@@ -159,6 +160,9 @@ namespace AyaNova.Util
|
||||
//BackupFiles
|
||||
AYANOVA_FOLDER_BACKUP_FILES = config.GetValue<string>("AYANOVA_FOLDER_BACKUP_FILES");
|
||||
|
||||
//TemporaryFiles
|
||||
AYANOVA_FOLDER_TEMPORARY_SERVER_FILES = config.GetValue<string>("AYANOVA_FOLDER_TEMPORARY_SERVER_FILES");
|
||||
|
||||
//pgdump backup utility path
|
||||
AYANOVA_BACKUP_PG_DUMP_PATH = config.GetValue<string>("AYANOVA_BACKUP_PG_DUMP_PATH");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user