when sharing a file that is already shared, the api shares throw an exception , so we catched it to bypass the reshares error

This commit is contained in:
Tiavina 2025-03-25 17:13:11 +03:00
parent 1e780a7eaf
commit 72417d3d94

View File

@ -26,6 +26,7 @@ declare(strict_types=1);
namespace OCA\Gestion\Service; namespace OCA\Gestion\Service;
use GuzzleHttp\Exception\GuzzleException;
use OCP\DB\Exception; use OCP\DB\Exception;
use OCP\IUserSession; use OCP\IUserSession;
use OCP\Mail\IMailer; use OCP\Mail\IMailer;
@ -454,26 +455,34 @@ class GestionService {
} }
public function sendFileAttachmentToTalk($roomToken, $cookie , $fileName ) { public function sendFileAttachmentToTalk($roomToken, $cookie , $fileName ) {
$host = 'http://127.0.0.1'; try{
$client = \OC::$server->getHTTPClientService()->newClient(); $host = 'http://127.0.0.1';
$token = file_get_contents("$host/ocs/v2.php/core/getcsrftoken", false, stream_context_create([ $client = \OC::$server->getHTTPClientService()->newClient();
'http' => [ $token = file_get_contents("$host/ocs/v2.php/core/getcsrftoken", false, stream_context_create([
'header' => "OCS-APIRequest: true\r\n" 'http' => [
] 'header' => "OCS-APIRequest: true\r\n"
])); ]
$client->post("$host/ocs/v2.php/apps/files_sharing/api/v1/shares", [ ]));
'body' => [ $client->post("$host/ocs/v2.php/apps/files_sharing/api/v1/shares", [
"path" => "//Talk/$fileName", 'body' => [
"referenceId" => Uuid::uuid4()->toString(), "path" => "//Talk/$fileName",
"shareWith" => $roomToken, "referenceId" => Uuid::uuid4()->toString(),
"shareType" => 10, "shareWith" => $roomToken,
'talkMetaData' => "{\"messageType\":\"\"}" "shareType" => 10,
], 'talkMetaData' => "{\"messageType\":\"\"}"
'headers' => [ ],
'Cookie' =>$cookie, 'headers' => [
'OCS-APIRequest' => 'true', 'Cookie' =>$cookie,
'requesttoken' => $token '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");
}
} }
} }