diff --git a/app/Helpers/NextCloudHelper.php b/app/Helpers/NextCloudHelper.php index 49b78ee..b51fb34 100644 --- a/app/Helpers/NextCloudHelper.php +++ b/app/Helpers/NextCloudHelper.php @@ -5,6 +5,7 @@ namespace App\Helpers; use GuzzleHttp\Client; use GuzzleHttp\Exception\RequestException; use Illuminate\Support\Str; +use Illuminate\Support\Facades\Storage; class NextCloudHelper { @@ -102,19 +103,53 @@ class NextCloudHelper } } - public static function getFileUrl($filePath) { $baseUrl = env('NEXT_CLOUD_URL'); - $username = env('NEXT_CLOUD_USERNAME'); + $publicToken = '5ogLDbQEbEMsAbD'; // Replace with your actual token + $relativePath = "/mktia/public.php/webdav/" . ltrim($filePath, '/'); - // Build the user-specific WebDAV file URL - $relativePath = "/mktia/remote.php/dav/files/{$username}/" . ltrim($filePath, '/'); + // Build the full URL + $url = rtrim($baseUrl, '/') . $relativePath . "?token={$publicToken}"; - // Return the full accessible URL - return rtrim($baseUrl, '/') . '/' . $relativePath; + // Initialize cURL + $ch = curl_init($url); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_HTTPHEADER, [ + 'OCS-APIRequest: true', // Ensure Nextcloud recognizes the API request + ]); + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // Disable SSL host verification + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Disable SSL peer verification + + $response = curl_exec($ch); + + // Handle cURL errors + if ($response === false) { + $error = curl_error($ch); + curl_close($ch); + throw new \Exception("cURL error: {$error}"); + } + + curl_close($ch); + return $url; } - + + public static function getNextcloudFile($filePath) + { + // Check if the file exists + if (Storage::disk('webdav')->exists($filePath)) { + // Get the file contents + $content = Storage::disk('webdav')->get($filePath); + + // Return the file as a response for download + return response($content) + ->header('Content-Type', 'application/pdf') + ->header('Content-Disposition', 'inline; filename="' . basename($filePath) . '"'); + } else { + return response()->json(['error' => 'File not found'], 404); + } + } + /** * Create a user in Nextcloud. * diff --git a/composer.json b/composer.json index c646c79..df51847 100644 --- a/composer.json +++ b/composer.json @@ -14,6 +14,7 @@ "laravel/tinker": "^2.9", "laravel/ui": "^4.6", "laravolt/avatar": "^6.0", + "league/flysystem-webdav": "^3.29", "nino/laravel-nextcloud-fs": "^2.0", "phpoffice/phpspreadsheet": "^3.5", "singlequote/laravel-webdav": "^1.1", diff --git a/composer.lock b/composer.lock index fd8a12c..18f4e50 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "83771e2a711327eac79ef3f7b30673da", + "content-hash": "fc2177036b736100113a527777c8cbc8", "packages": [ { "name": "barryvdh/laravel-dompdf", diff --git a/config/filesystems.php b/config/filesystems.php index 1de83d6..37a9b06 100644 --- a/config/filesystems.php +++ b/config/filesystems.php @@ -68,6 +68,16 @@ return [ ], ], + 'webdav' => [ + 'driver' => 'webdav', + 'baseUri' => 'https://mkt.tunggal-pharma.com/mktia/remote.php/dav/files/user_dev/', + 'userName' => env('NEXT_CLOUD_USERNAME'), + 'password' => env('NEXT_CLOUD_PASSWORD'), + 'prefix' => '', + 'options' => [ + 'verify' => false, + ], + ], ], /* diff --git a/resources/views/backend/pages/forms/upcountry/index.blade.php b/resources/views/backend/pages/forms/upcountry/index.blade.php index 2b913f1..0477cbb 100644 --- a/resources/views/backend/pages/forms/upcountry/index.blade.php +++ b/resources/views/backend/pages/forms/upcountry/index.blade.php @@ -115,7 +115,7 @@ {{ number_format($item->total, 0, ',', '.') }} @if ($item->bukti1) - + Download @else