From 72417d3d94b4260ffd62f2eee35e48c24703c9cf Mon Sep 17 00:00:00 2001 From: Tiavina Date: Tue, 25 Mar 2025 17:13:11 +0300 Subject: [PATCH] when sharing a file that is already shared, the api shares throw an exception , so we catched it to bypass the reshares error --- gestion/lib/Service/GestionService.php | 51 +++++++++++++++----------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/gestion/lib/Service/GestionService.php b/gestion/lib/Service/GestionService.php index 5ca5232..030f581 100644 --- a/gestion/lib/Service/GestionService.php +++ b/gestion/lib/Service/GestionService.php @@ -26,6 +26,7 @@ declare(strict_types=1); namespace OCA\Gestion\Service; +use GuzzleHttp\Exception\GuzzleException; use OCP\DB\Exception; use OCP\IUserSession; use OCP\Mail\IMailer; @@ -454,26 +455,34 @@ class GestionService { } public function sendFileAttachmentToTalk($roomToken, $cookie , $fileName ) { - $host = 'http://127.0.0.1'; - $client = \OC::$server->getHTTPClientService()->newClient(); - $token = file_get_contents("$host/ocs/v2.php/core/getcsrftoken", false, stream_context_create([ - 'http' => [ - 'header' => "OCS-APIRequest: true\r\n" - ] - ])); - $client->post("$host/ocs/v2.php/apps/files_sharing/api/v1/shares", [ - 'body' => [ - "path" => "//Talk/$fileName", - "referenceId" => Uuid::uuid4()->toString(), - "shareWith" => $roomToken, - "shareType" => 10, - 'talkMetaData' => "{\"messageType\":\"\"}" - ], - 'headers' => [ - 'Cookie' =>$cookie, - 'OCS-APIRequest' => 'true', - 'requesttoken' => $token - ] - ]); + try{ + $host = 'http://127.0.0.1'; + $client = \OC::$server->getHTTPClientService()->newClient(); + $token = file_get_contents("$host/ocs/v2.php/core/getcsrftoken", false, stream_context_create([ + 'http' => [ + 'header' => "OCS-APIRequest: true\r\n" + ] + ])); + $client->post("$host/ocs/v2.php/apps/files_sharing/api/v1/shares", [ + 'body' => [ + "path" => "//Talk/$fileName", + "referenceId" => Uuid::uuid4()->toString(), + "shareWith" => $roomToken, + "shareType" => 10, + 'talkMetaData' => "{\"messageType\":\"\"}" + ], + 'headers' => [ + 'Cookie' =>$cookie, + 'OCS-APIRequest' => 'true', + 'requesttoken' => $token + ] + ]); + } + catch(GuzzleException $e){ + $this->logger->debug("error sending file to talk"); + } + catch(Exception $e){ + $this->logger->debug("error sending file to talk"); + } } }