From 5bfe1d54f6ff986d27c77bbcfa5bff1f3d379f22 Mon Sep 17 00:00:00 2001 From: "CHIEFSOFT\\ameye" Date: Thu, 1 Jan 2026 09:08:38 -0500 Subject: [PATCH] merms-media data --- .env | 17 +++++-- .env.live | 18 ++++--- app/Config/Database.php | 45 ++++++++++++++++ app/Config/Routes.php | 1 + app/Controllers/BaseController.php | 4 +- app/Controllers/Media.php | 82 ++++++++++++++++++++++++++++++ 6 files changed, 155 insertions(+), 12 deletions(-) diff --git a/.env b/.env index 936e18d..0ff3610 100644 --- a/.env +++ b/.env @@ -4,6 +4,18 @@ UID=1000 SERVER_PATH=production +# UPLOAD PATHS +UPLOAD_FOLDER="/app/uploads/DEV" +MEDIA_SERVER="https://qa-media.mermsemr.com" + +# DATABASE SERVER +MAIN_DATABASE_IP="10.20.30.60" +MAIN_DATABASE_USERNAME="merms_panel" +MAIN_DATABASE_PASSWORD="merms_panel" +MAIN_DATABASE="merms_panel" +MAIN_DATABASE_PORT="5432" + + PATH_MACHINE_LOCAL='/home/chiefsoft/DevSites/MERMS/MermsProvision/ANSIBLE/parts/' # '/home/chiefsoft/MermsProvision/ANSIBLE/parts/' # REMOTE_COMPOSER_PATH='chiefsoft@10.0.0.32:/home/chiefsoft/MermsProvision/ANSIBLE/parts/' @@ -32,11 +44,6 @@ HAPROXY_SERVER_USER="admin" HAPROXY_SERVER_PASS="Hapr0xy001" -MAIN_DATABASE_IP="10.20.30.60" -MAIN_DATABASE_USERNAME="merms_panel" -MAIN_DATABASE_PASSWORD="merms_panel" -MAIN_DATABASE="merms_panel" -MAIN_DATABASE_PORT="5432" PROVISION_MSQL_DATABASE_IP="172.16.4.96" PROVISION_MSQL_DATABASE_USERNAME="root" diff --git a/.env.live b/.env.live index e192447..1c00ceb 100644 --- a/.env.live +++ b/.env.live @@ -5,6 +5,18 @@ CI_ENVIRONMENT=production SERVER_PATH = production +# UPLOAD PATHS +UPLOAD_FOLDER="/app/uploads/LIVE" +MEDIA_SERVER="https://media.mermsemr.com" + +# DATABASE SERVER +MAIN_DATABASE_IP="10.13.3.60" +MAIN_DATABASE_USERNAME="merms_panel" +MAIN_DATABASE_PASSWORD="merms_panel" +MAIN_DATABASE="merms_panel" +MAIN_DATABASE_PORT="5432" + + PATH_MACHINE_LOCAL='/home/chiefsoft/DevSites/MERMS/MermsProvision/ANSIBLE/parts/' # '/home/chiefsoft/MermsProvision/ANSIBLE/parts/' # REMOTE_COMPOSER_PATH = 'chiefsoft@10.0.0.32:/home/chiefsoft/MermsProvision/ANSIBLE/parts/' @@ -32,12 +44,6 @@ HAPROXY_SERVER_USER="admin" HAPROXY_SERVER_PASS="Hapr0xy001" -MAIN_DATABASE_IP="10.13.3.60" -MAIN_DATABASE_USERNAME="merms_panel" -MAIN_DATABASE_PASSWORD="merms_panel" -MAIN_DATABASE="merms_panel" -MAIN_DATABASE_PORT="5432" - PROVISION_MSQL_DATABASE_IP="172.16.4.96" PROVISION_MSQL_DATABASE_USERNAME="root" PROVISION_MSQL_DATABASE_PASSWORD="may12002!" diff --git a/app/Config/Database.php b/app/Config/Database.php index 29f6f4a..c57d2e0 100644 --- a/app/Config/Database.php +++ b/app/Config/Database.php @@ -24,7 +24,52 @@ class Database extends Config * * @var array */ + public array $default = [ + 'DSN' => '', + 'hostname' => '10.20.30.60', + 'username' => 'merms_panel', + 'password' => 'merms_panel', + 'database' => 'merms_panel', + 'schema' => 'public', + 'DBDriver' => 'Postgre', + 'DBPrefix' => '', + 'pConnect' => false, + 'DBDebug' => true, + 'charset' => 'utf8', + 'swapPre' => '', + 'failover' => [], + 'port' => 5432, + 'dateFormat' => [ + 'date' => 'Y-m-d', + 'datetime' => 'Y-m-d H:i:s', + 'time' => 'H:i:s', + ], + ]; + + public array $production = [ + 'DSN' => '', + 'hostname' => '10.13.3.60', + 'username' => 'merms_panel', + 'password' => 'merms_panel', + 'database' => 'merms_panel', + 'schema' => 'public', + 'DBDriver' => 'Postgre', + 'DBPrefix' => '', + 'pConnect' => false, + 'DBDebug' => true, + 'charset' => 'utf8', + 'swapPre' => '', + 'failover' => [], + 'port' => 5432, + 'dateFormat' => [ + 'date' => 'Y-m-d', + 'datetime' => 'Y-m-d H:i:s', + 'time' => 'H:i:s', + ], + ]; + + public array $default_old = [ 'DSN' => '', 'hostname' => 'localhost', 'username' => '', diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 9ddab6c..6c46a7b 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -8,3 +8,4 @@ use CodeIgniter\Router\RouteCollection; $routes->get('/', 'Home::index'); $routes->get('/media/test', 'Media::index'); $routes->get('/media/show/(:any)', 'Media::imageGate/$1'); +$routes->get('/website/(:any)', 'Media::WebsiteGate/$1'); \ No newline at end of file diff --git a/app/Controllers/BaseController.php b/app/Controllers/BaseController.php index 689405b..defaf5e 100644 --- a/app/Controllers/BaseController.php +++ b/app/Controllers/BaseController.php @@ -43,6 +43,8 @@ abstract class BaseController extends Controller */ // protected $session; + protected $db; + /** * @return void */ @@ -52,7 +54,7 @@ abstract class BaseController extends Controller parent::initController($request, $response, $logger); // Preload any models, libraries, etc, here. - + $this->db = \Config\Database::connect(); // E.g.: $this->session = service('session'); } } diff --git a/app/Controllers/Media.php b/app/Controllers/Media.php index 2704fab..45cccf7 100644 --- a/app/Controllers/Media.php +++ b/app/Controllers/Media.php @@ -80,6 +80,88 @@ class Media extends BaseController exit(); } + // + #[NoReturn] public function WebsiteGate(): void + { + $uriSegments = explode("/", parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)); + $segLen = count($uriSegments); +// var_dump($uriSegments); +// 0 => string '' (length=0) +// 1 => string 'website' (length=7) +// 2 => string '4bdc1594-a0d4-4eba-9dff-9e62f5c28d69' (length=36) +// 3 => string 'coronary-artery-disease.png' (length=27) + + $filename = $uriSegments[$segLen - 1]; + $webFileUid = $uriSegments[$segLen - 2]; + $fileDetails = $this->getWebFileDetails($webFileUid); + + // var_dump($fileDetails); +//'id' => string '12' (length=2) +//'uid' => string '4bdc1594-a0d4-4eba-9dff-9e62f5c28d69' (length=36) +//'member_id' => string '20' (length=2) +//'member_uid' => string '2f1f9c8a-d50b-4fac-9de3-081bbc07cc64' (length=36) +//'file_group' => string 'WEBSITE' (length=7) +//'filename' => string 'coronary-artery-disease.png' (length=27) +//'save_filename' => string '1767224858-coronary-artery-disease.png' (length=38) +//'file_type' => string 'png' (length=3) +//'file_size' => string '0' (length=1) +//'status' => string '1' (length=1) +//'added' => string '2025-12-31 18:47:38.905934' (length=26) +//'updated' => string '2025-12-31 18:47:38.905943' (length=26) + + // exit; +///var/www/html/uploads/uploads/DEV/WEBSITE/W0000000020/1767055095-practice-in-ai_1.jpg + $target_file = "/var/www/html/uploads/uploads/DEV/WEBSITE/W0000000020/1767055095-practice-in-ai_1.jpg"; + //$target_file = "/var/www/html/SITEFILES/TEST/" . $filename; + $file_extension = "jpg"; // strtolower(substr(strrchr($filename, "."), 1)); + $ctype = "image/jpeg"; + switch ($file_extension) { + case "gif": + $ctype = "image/gif"; + break; + case "png": + $ctype = "image/png"; + break; + case "jpeg": + case "jpg": + $ctype = "image/jpeg"; + break; + case "svg": + $ctype = "image/svg+xml"; + break; + case "mp4": + $ctype = "application/octet-stream"; + break; + // case "mp4": $ctype="video/mp4"; break; + default: + } + + $selectedFile = $target_file; + header('Content-type: ' . $ctype); + readfile($selectedFile); + exit(); + } + + private function getWebFileDetails($webFileUid): array + { + try { + $sqlP = "SELECT * FROM members_webfiles WHERE uid::text = '$webFileUid' "; + $query = $this->db->query($sqlP); + $row = $query->getResultArray(); + if (isset($row)) { + return $row; + } + } catch (Exception $e) { + // Handle the specific exception + //echo "Caught exception: " . $e->getMessage() . "\n"; + log_message('error', 'Error in getWebFileDetails :: :: ' . $e->getMessage()); + } finally { + // Cleanup code, always runs + log_message('info', "Consider CACHE IN getWebFileDetails - $webFileUid"); + } + return []; + } + private function imageSets($selImg): string { $image_set = [