diff --git a/.vscode/launch.json b/.vscode/launch.json index 7b0440e3..4044e905 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -51,6 +51,7 @@ "AYANOVA_USE_URLS": "http://*:7575;", "AYANOVA_FOLDER_USER_FILES": "c:\\temp\\RavenTestData\\userfiles", "AYANOVA_FOLDER_BACKUP_FILES": "c:\\temp\\RavenTestData\\backupfiles", + "AYANOVA_FOLDER_TEMPORARY_SERVER_FILES": "c:\\temp\\RavenTestData\\tempfiles", "AYANOVA_SERVER_TEST_MODE": "false", "AYANOVA_SERVER_TEST_MODE_SEEDLEVEL": "small", "AYANOVA_SERVER_TEST_MODE_TZ_OFFSET": "-7", diff --git a/docs/8.0/ayanova/docs/ops-config-environment-variables.md b/docs/8.0/ayanova/docs/ops-config-environment-variables.md index bc4f36a9..0c521bb9 100644 --- a/docs/8.0/ayanova/docs/ops-config-environment-variables.md +++ b/docs/8.0/ayanova/docs/ops-config-environment-variables.md @@ -12,6 +12,7 @@ These values can all be specified as an environment variable or as a command lin - [AYANOVA_FOLDER_BACKUP_FILES](ops-config-folder-backup-files.md) - [AYANOVA_FOLDER_USER_FILES](ops-config-folder-user-files.md) +- [AYANOVA_FOLDER_TEMPORARY_SERVER_FILES](ops-config-folder-temporary-files.md) ## BACKUP UTILITY "pg_dump" PATH - [AYANOVA_BACKUP_PG_DUMP_PATH](ops-config-backup-pgdump-path.md) @@ -31,8 +32,7 @@ These values can all be specified as an environment variable or as a command lin - [AYANOVA_JWT_SECRET](ops-config-jwt-secret.md) - [AYANOVA_USE_URLS](ops-config-use-urls.md) -- [AYANOVA_FOLDER_USER_FILES](ops-config-folder-user-files.md) -- [AYANOVA_FOLDER_BACKUP_FILES](ops-config-folder-backup-files.md) + ## SECURITY diff --git a/docs/8.0/ayanova/docs/ops-config-folder-backup-files.md b/docs/8.0/ayanova/docs/ops-config-folder-backup-files.md index 7298877d..8dfa7933 100644 --- a/docs/8.0/ayanova/docs/ops-config-folder-backup-files.md +++ b/docs/8.0/ayanova/docs/ops-config-folder-backup-files.md @@ -1,9 +1,8 @@ # BACKUP FILES FOLDER SETTING This setting controls where AyaNova stores backup and restore files used by the backup and restore features built into AyaNova. -In addition this folder is used when importing from an AyaNova 7 export file. -Warning: this folder MUST NOT be the same location set for [AYANOVA_FOLDER_USER_FILES](ops-config-folder-user-files.md) or AyaNova will not start. +Warning: this folder MUST NOT be the same location set for [AYANOVA_FOLDER_USER_FILES](ops-config-folder-user-files.md) or [AYANOVA_FOLDER_TEMPORARY_SERVER_FILES](ops-config-folder-temporary-files.md) or AyaNova will not start. ## Default diff --git a/docs/8.0/ayanova/docs/ops-config-folder-temporary-files.md b/docs/8.0/ayanova/docs/ops-config-folder-temporary-files.md new file mode 100644 index 00000000..aef7e728 --- /dev/null +++ b/docs/8.0/ayanova/docs/ops-config-folder-temporary-files.md @@ -0,0 +1,34 @@ +# TEMPORARY SERVER FILES FOLDER SETTING + +This setting controls where AyaNova stores files temporarily while servicing requests such as report generation etc. + +Warning: this folder MUST NOT be the same location set for [AYANOVA_FOLDER_USER_FILES](ops-config-folder-user-files.md) or [AYANOVA_FOLDER_BACKUP_FILES](ops-config-folder-backup-files.md) or AyaNova will not start. + +## Default + +If no override is specified AyaNova will store temporary files in a `tempfiles` folder in the AyaNova root folder where AyaNova is started from. + +## Overriding + +AyaNova expects the temporary files folder path to be provided by an environment variable or command line parameter named + +`AYANOVA_FOLDER_TEMPORARY_SERVER_FILES` + +The value specified should be a string containing a fully qualified file path for the platform, for example: +`c:\data\ayanova\tempfiles` + +Example command line parameter + +`dotnet run --AYANOVA_FOLDER_TEMPORARY_SERVER_FILES="/var/lib/ayanova/tempfiles"` + +Example environment variable + +Windows + +`set "AYANOVA_FOLDER_TEMPORARY_SERVER_FILES=c:\data\ayanova\tempfiles"` + +Linux / MAC + +`export AYANOVA_FOLDER_TEMPORARY_SERVER_FILES="/var/lib/ayanova/tempfiles"` + +If both a command line parameter and an environment variable are set the command line parameter takes precedence. diff --git a/docs/8.0/ayanova/docs/ops-config-folder-user-files.md b/docs/8.0/ayanova/docs/ops-config-folder-user-files.md index 33402520..4b91fcba 100644 --- a/docs/8.0/ayanova/docs/ops-config-folder-user-files.md +++ b/docs/8.0/ayanova/docs/ops-config-folder-user-files.md @@ -3,7 +3,7 @@ This setting controls where AyaNova stores user uploaded files used by features that allow file attachment or uploads. AyaNova stores these files with random names in the folder specified. -Warning: this folder MUST NOT be the same location set for [AYANOVA_FOLDER_BACKUP_FILES](ops-config-folder-backup-files.md) or AyaNova will not start. +Warning: this folder MUST NOT be the same location set for [AYANOVA_FOLDER_BACKUP_FILES](ops-config-folder-backup-files.md) or [AYANOVA_FOLDER_TEMPORARY_SERVER_FILES](ops-config-folder-temporary-files.md) or AyaNova will not start. ## Default diff --git a/docs/8.0/ayanova/mkdocs.yml b/docs/8.0/ayanova/mkdocs.yml index f5c4036f..40457833 100644 --- a/docs/8.0/ayanova/mkdocs.yml +++ b/docs/8.0/ayanova/mkdocs.yml @@ -114,6 +114,7 @@ nav: - 'Translation / Language': 'ops-config-default-translation.md' - 'Backup files folder': 'ops-config-folder-backup-files.md' - 'User files folder': 'ops-config-folder-user-files.md' + - 'Server temporary files folder': 'ops-config-folder-temporary-files.md' - 'Database configuration': 'ops-config-db.md' - 'PORT and URL configuration': 'ops-config-use-urls.md' - 'Environment variable reference': 'ops-config-environment-variables.md' diff --git a/server/AyaNova/AyaNova.csproj b/server/AyaNova/AyaNova.csproj index 4441b0de..2ffa64ae 100644 --- a/server/AyaNova/AyaNova.csproj +++ b/server/AyaNova/AyaNova.csproj @@ -36,6 +36,7 @@ + diff --git a/server/AyaNova/Controllers/ReportController.cs b/server/AyaNova/Controllers/ReportController.cs index baedd524..238f7823 100644 --- a/server/AyaNova/Controllers/ReportController.cs +++ b/server/AyaNova/Controllers/ReportController.cs @@ -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 \ No newline at end of file diff --git a/server/AyaNova/Controllers/ServerStateController.cs b/server/AyaNova/Controllers/ServerStateController.cs index c496941c..a14ff4d3 100644 --- a/server/AyaNova/Controllers/ServerStateController.cs +++ b/server/AyaNova/Controllers/ServerStateController.cs @@ -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, diff --git a/server/AyaNova/util/FileUtil.cs b/server/AyaNova/util/FileUtil.cs index 29a76331..c3d53098 100644 --- a/server/AyaNova/util/FileUtil.cs +++ b/server/AyaNova/util/FileUtil.cs @@ -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 + /// + /// Get backup file folder + /// + /// + internal static string TemporaryFilesFolder + { + get + { + return ServerBootConfig.AYANOVA_FOLDER_TEMPORARY_SERVER_FILES; + } + } + + + /// + /// Get a random file name with path to temporary files folder + /// + /// + internal static string NewRandomTempFilesFolderFileName + { + get + { + return Path.Combine(TemporaryFilesFolder, NewRandomFileName); + } + } + + #endregion + + #region Utility (BACKUP) file handling @@ -315,17 +353,7 @@ namespace AyaNova.Util } - /// - /// Get a random file name - /// - /// - internal static string NewRandomFileName - { - get - { - return Path.GetRandomFileName(); - } - } + /// /// Get a random file name with path to attachments folder @@ -569,6 +597,18 @@ namespace AyaNova.Util #region General utilities + /// + /// Get a random file name + /// + /// + 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" diff --git a/server/AyaNova/util/ServerBootConfig.cs b/server/AyaNova/util/ServerBootConfig.cs index a932a621..1cef69b5 100644 --- a/server/AyaNova/util/ServerBootConfig.cs +++ b/server/AyaNova/util/ServerBootConfig.cs @@ -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("AYANOVA_FOLDER_BACKUP_FILES"); + //TemporaryFiles + AYANOVA_FOLDER_TEMPORARY_SERVER_FILES = config.GetValue("AYANOVA_FOLDER_TEMPORARY_SERVER_FILES"); + //pgdump backup utility path AYANOVA_BACKUP_PG_DUMP_PATH = config.GetValue("AYANOVA_BACKUP_PG_DUMP_PATH"); diff --git a/startserver.bat b/startserver.bat index 2f0bc02d..66471332 100644 --- a/startserver.bat +++ b/startserver.bat @@ -1 +1 @@ -dotnet run -p ./server/AyaNova -- --AYANOVA_DB_CONNECTION="Server=localhost;Username=postgres;Password=raven;Database=AyaNova;" --AYANOVA_LOG_LEVEL="Info" --AYANOVA_DEFAULT_TRANSLATION="en" --AYANOVA_USE_URLS="http://*:7575;" --AYANOVA_FOLDER_USER_FILES="c:\temp\RavenTestData\userfiles" --AYANOVA_FOLDER_BACKUP_FILES="c:\temp\RavenTestData\backupfiles" \ No newline at end of file +dotnet run -p ./server/AyaNova -- --AYANOVA_DB_CONNECTION="Server=localhost;Username=postgres;Password=raven;Database=AyaNova;" --AYANOVA_LOG_LEVEL="Info" --AYANOVA_DEFAULT_TRANSLATION="en" --AYANOVA_USE_URLS="http://*:7575;" --AYANOVA_FOLDER_USER_FILES="c:\temp\RavenTestData\userfiles" --AYANOVA_FOLDER_BACKUP_FILES="c:\temp\RavenTestData\backupfiles" --AYANOVA_FOLDER_TEMPORARY_SERVER_FILES="c:\temp\RavenTestData\tempfiles" \ No newline at end of file