File read

This commit is contained in:
CHIEFSOFT\ameye
2023-08-10 20:25:23 -04:00
parent f9b7fb4fe7
commit 28cebaa508
4 changed files with 47 additions and 126 deletions
+8 -91
View File
@@ -29,10 +29,9 @@ class WrenchMedia extends BaseController
}
public function apigate(){
$call_backend = false;
$uriSegments = explode("/", parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
$segLen = count($uriSegments);
echo $segLen;
if ( $segLen < 4 ){
return;
@@ -55,7 +54,7 @@ class WrenchMedia extends BaseController
//We can check cache for the file or
// OR
// WE need to ask backend for this file now /
$call_backend = true;
$data = [
'action' => WRENCHBOARD_GET_MEDIA,
'sessionid' => $sessionId,
@@ -63,7 +62,12 @@ class WrenchMedia extends BaseController
'file_uid' => $fileUID,
];
if ($data["action"] !=''){
$wrenchboard = new \App\Models\BackendModel();
$ret = $wrenchboard->wrenchboard_api($data, $out);
$out['internal_return'] = $ret;
}
print_r($out);
$file = 'books.png';
@@ -81,93 +85,6 @@ class WrenchMedia extends BaseController
}
public function apigate33(){
log_message('critical', "Oauth-Gate");
header('Access-Control-Allow-Origin: *');
log_message('critical', "0002");
$call_backend = true;
header("Access-Control-Allow-Headers: Origin, X-API-KEY, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method, Access-Control-Allow-Headers, Authorization, observe, enctype, Content-Length, X-Csrf-Token");
log_message('critical', "0003");
header("Access-Control-Allow-Methods: GET, PUT, POST, DELETE, PATCH, OPTIONS");
header("Access-Control-Allow-Credentials: true");
header("Access-Control-Max-Age: 3600");
header('content-type: application/json; charset=utf-8');
$method = $_SERVER['REQUEST_METHOD'];
if ($method == "OPTIONS") {
header("HTTP/1.1 200 OK CORS");
log_message('critical', " apigate()-> OPTIONS DIE*****" );
die();
}
//$request = service('request');
// what is the endpoint
$uri = urldecode(current_url(true));
$findme = '?';
$pos = strpos($uri, $findme);
if ($pos > 5) {
$uri = substr($uri, 0, $pos);
}
log_message('critical', "API-GATE URI -> ".$uri );
$pieces = explode('/', $uri);
$psc = count($pieces);
$endpoint = $psc > 0 ? $pieces[$psc - 1] : '';
log_message('critical', "Enpoint-> ".$endpoint );
$endpoints = $this->endPointList();
$out = array();
$res1 = [];
if (array_key_exists($endpoint, $endpoints)) {
} else {
http_response_code(404);
// tell the user product does not exist
return json_encode([
'message' => 'Endpoint not found.',
'URI' => $uri,
]);
}
// echo "EXYTACT INPUT DATA HERE";
$raw_json = file_get_contents('php://input');
$raw_array = json_decode($raw_json, true);
$local_out =[];
if ($_SERVER["REQUEST_METHOD"] == "POST") { // if upload lets modify all the data
if (isset($_FILES) && is_array($_FILES) && count($_FILES)>0) {
$raw_array = array_merge($_POST,$_FILES);
}
}
if ($_SERVER['REQUEST_METHOD'] == 'GET') {
log_message('critical', "Enpoint LOC2 HERE -> ".$endpoint );
$get_param = $_GET['reqData'] ?? null;
$raw_array = ($get_param!=null) ? json_decode($get_param, true):[];
}
//$in = $raw_array;
log_message('critical', "wrenchboard_api-CALL RAW DATA".serialize($raw_array) );
//-- move to another module start
$in["loc"] = $_SERVER["REMOTE_ADDR"];
// $in = $this->prepareOauthEndPointData($endpoint, $raw_array,$call_backend,$local_out);
log_message('critical', "wrenchboard_api-CALL PREPARE DATA".serialize($in) );
if ( $call_backend == true && $in["action"] !='' ){
$wrenchboard = new \App\Models\BackendModel();
$ret = $wrenchboard->wrenchboard_api($in, $out);
$out['internal_return'] = $ret;
}
else
{
$out = $local_out;
}
//$this->doCacheStep($in, $out);
return json_encode( ( new \App\Models\ResultFormatter() )->processOutJson($in, $out));
}
}