From f9b7fb4fe79bb195b2a99f77aa1ff5f57837ca1f Mon Sep 17 00:00:00 2001 From: "CHIEFSOFT\\ameye" Date: Thu, 10 Aug 2023 20:05:44 -0400 Subject: [PATCH] Media finder --- wrenchboard/src/include/media.h | 11 +++ wrenchboard/src/shared_tool/media.cc | 86 +++++++++++++++++++ .../src/shared_tool/wrenchboard_api_main.cc | 1 + www-api/app/Controllers/WrenchMedia.php | 46 +++++++--- 4 files changed, 131 insertions(+), 13 deletions(-) create mode 100644 wrenchboard/src/include/media.h create mode 100644 wrenchboard/src/shared_tool/media.cc diff --git a/wrenchboard/src/include/media.h b/wrenchboard/src/include/media.h new file mode 100644 index 00000000..17705e20 --- /dev/null +++ b/wrenchboard/src/include/media.h @@ -0,0 +1,11 @@ +#ifndef __mx_media_h__ +#define __mx_media_h__ + +#include "vars.h" + +//long WrenchPurchaseHx( CVars in, CVars &out ); +//long WrenchRefferHx( CVars in, CVars &out ); +//long WrenchMyFilesList( CVars in, CVars &out ); +long WrenchFindStoredMedia(CVars in, CVars &out); + +#endif \ No newline at end of file diff --git a/wrenchboard/src/shared_tool/media.cc b/wrenchboard/src/shared_tool/media.cc new file mode 100644 index 00000000..4ce17dc2 --- /dev/null +++ b/wrenchboard/src/shared_tool/media.cc @@ -0,0 +1,86 @@ + +// History Listing +#include "clog.h" +#include "cgi.h" +#include "input.h" +#include "wrenchboard_api.h" +#include "history.h" +#include "media.h" +#include "email.h" +#include "payments.h" +#include "safestring.h" +#include +#include "pgsql.h" +#include "pgsql_wrapper.h" +#include "cfg.h" +#include + +/* +CREATE TABLE members_myfiles ( + id SERIAL, + member_id INT REFERENCES members(id) NOT NULL, + uid uuid DEFAULT uuid_generate_v4(), + file_name VARCHAR(35), + saved_file_name VARCHAR(35) UNIQUE NOT NULL, + file_size INT DEFAULT 0, + file_type VARCHAR(15), + title VARCHAR(35), + description VARCHAR(100), + status INT DEFAULT 1, + added timestamp without time zone DEFAULT now(), + updated timestamp without time zone DEFAULT now() + ); + ALTER TABLE ONLY members_myfiles + ADD CONSTRAINT members_myfiles_id_key UNIQUE (id); +*/ + +/* This profile apps*/ +long WrenchFindStoredMedia(CVars in, CVars &out) { + logfmt(logINFO, "WrenchUpdateUserProfile()"); + long ret = PHP_API_BAD_PARAM; + try { + REQ_STRING(in, "firstname", 3, 49, "(.*)"); + REQ_STRING(in, "lastname", 3, 49, "(.*)"); + REQ_STRING(in, "email", 5, 150, "(.*)"); + REQ_STRING(in, "state", 3, 150, "(.*)"); + REQ_STRING(in, "city", 3, 150, "(.*)"); + long member_id = REQ_LONG(in, "member_id", 1, -1); + REQ_STRING(in, "uid", 3, 150, "(.*)"); + OPTIONAL(in, "online_name") REQ_STRING(in, "online_name", 3, 15, "(.*)"); + REQ_LONG(in, "pref_email", 1, -1); + REQ_LONG(in, "pref_phone", 1, -1); + + const PGresult *res; + res = pgsql_query("SELECT * FROM members WHERE id = %lu AND uid='%s'", member_id, in["uid"].c_str() ); + if (res != NULL && pgsql_num_rows(res) > 0) { + CVars x; + x["firstname"] = in["firstname"]; + x["firstname"].set_valid(true); + x["lastname"] = in["lastname"]; + x["lastname"].set_valid(true); + x["email"] = in["email"]; + x["email"].set_valid(true); + x["state"] = in["state"]; + x["state"].set_valid(true); + x["city"] = in["city"]; + x["city"].set_valid(true); + + x["online_name"] = in["online_name"]; + x["online_name"].set_valid(true); + + x["pref_email"] = in["pref_email"]; + x["pref_email"].set_valid(true); + + x["pref_phone"] = in["pref_phone"]; + x["pref_phone"].set_valid(true); + + update_db_record(DBS_VALID, "members", x, member_id); + ret = PHP_API_OK; + } + + } catch (bad_parameter) { + logfmt(logINFO, "ERROR CALL long WrenchUpdateUserProfile(CVars in, CVars &out)"); + } + logfmt(logINFO, "/WrenchUpdateUserProfile()"); + return ret; +} diff --git a/wrenchboard/src/shared_tool/wrenchboard_api_main.cc b/wrenchboard/src/shared_tool/wrenchboard_api_main.cc index 43218fe3..4b873d8f 100644 --- a/wrenchboard/src/shared_tool/wrenchboard_api_main.cc +++ b/wrenchboard/src/shared_tool/wrenchboard_api_main.cc @@ -22,6 +22,7 @@ #include "coupons.h" #include "cards.h" #include "family_acc.h" +#include "media.h" #include "twilo.h" //extern CSQL *sql; diff --git a/www-api/app/Controllers/WrenchMedia.php b/www-api/app/Controllers/WrenchMedia.php index 2b9ebebc..0cc0ea6d 100644 --- a/www-api/app/Controllers/WrenchMedia.php +++ b/www-api/app/Controllers/WrenchMedia.php @@ -30,21 +30,41 @@ class WrenchMedia extends BaseController public function apigate(){ -// $file = __DIR__ . DIRECTORY_SEPARATOR . "books.png"; -// $fileData = exif_read_data($file); -// ob_start(); -// header("Content-Type: " . $fileData["MimeType"]); -// header("Content-Length: " . $fileData["FileSize"]); -// readfile($file); -// ob_end_flush(); - $segs = $this->uri->segment_array(); + $uriSegments = explode("/", parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)); + $segLen = count($uriSegments); + echo $segLen; - foreach ($segs as $segment) - { - echo $segment; - echo '
'; + if ( $segLen < 4 ){ + return; } - + + $sessionId = $uriSegments[$segLen-3]; + $fileSection = $uriSegments[$segLen-2]; + $fileUID = $uriSegments[$segLen-1]; + + $supportedSections = ['profile','myfile','contracts','family']; + if (!in_array($fileSection, $supportedSections)) { + // section not supported + return; + } + + /* + * VERIFY ALL PARAMETERS ARE GOOD + */ + + //We can check cache for the file or + // OR + // WE need to ask backend for this file now / + + $data = [ + 'action' => WRENCHBOARD_GET_MEDIA, + 'sessionid' => $sessionId, + 'file_section' => $fileSection, + 'file_uid' => $fileUID, + ]; + + + $file = 'books.png'; if (file_exists($file)) {