Skip to content
Snippets Groups Projects

Resolve "Data ingress for context information for tiki-wiki"

12 files
+ 1244
59
Compare changes
  • Side-by-side
  • Inline
Files
12
+ 53
1
@@ -44,12 +44,64 @@ function context($url, $domain, $content) {
return $response;
}
try {
function handle_unstructured_add() {
// Validate certificate usage and domain usage (certificate only)
$backend = new Backend(null);
$domain = $backend->domainInUse();
// Check if the required URL parameters are set
if (isset($_GET['smartDataContextId'])) {
// Retrieve headers from the original request
$headers = getallheaders();
if (isset($headers['Content-Type'], $headers['Filename'])) {
// Extract the smartdatacontextid from the URL parameters
$smartDataContextId = $_GET['smartDataContextId'];
$targetUrl = Config::config()::SMARTDATACONTEXT_API . "/unstructured/add/$domain/$smartDataContextId";
// Initialize cURL session
$ch = curl_init($targetUrl);
// Set cURL options
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: ' . $headers['Content-Type'],
'Filename: ' . $headers['Filename'],
]);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
$inputData = file_get_contents('php://input');
curl_setopt($ch, CURLOPT_POSTFIELDS, $inputData); // Use php://input to directly stream input
curl_setopt($ch, CURLOPT_INFILESIZE, $_SERVER['CONTENT_LENGTH']); // Set the expected content length
// Execute the cURL request
$response = curl_exec($ch);
$http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($http_status == 0) {
# Could not connect to the smartdatacontext API
$http_status = 503; # Service Unavailable
$response = '{"errors": ["SmartDataContext API not available"]}';
}
http_response_code($http_status);
return $response;
} else {
http_response_code(400);
}
} else {
http_response_code(400);
}
}
try {
if (array_key_exists('docs', $_GET)) {
echo context("/docs", null, null);
} else if (array_key_exists('openapi', $_GET)) {
echo context("/openapi", null, null);
} else if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_GET['action']) && $_GET['action'] === 'add-unstructured') {
echo handle_unstructured_add();
} else {
$content = file_get_contents('php://input');
$json = json_decode($content, false, 512, JSON_BIGINT_AS_STRING);
Loading