Skip to content

Commit

Permalink
Merge pull request #496 from nextcloud/fix/noid/request-on-frame
Browse files Browse the repository at this point in the history
using nc19request to broadcast the frame
  • Loading branch information
ArtificialOwl authored Oct 6, 2020
2 parents afcdebd + 287e874 commit 3e88484
Showing 1 changed file with 18 additions and 21 deletions.
39 changes: 18 additions & 21 deletions lib/Service/SharingFrameService.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@
namespace OCA\Circles\Service;


use daita\MySmallPhpTools\Model\Nextcloud\NC19Request;
use daita\MySmallPhpTools\Model\Request;
use daita\MySmallPhpTools\Traits\Nextcloud\TNC19Request;
use Exception;
use OCA\Circles\Api\v1\Circles;
use OCA\Circles\AppInfo\Application;
use OCA\Circles\Db\CirclesRequest;
use OCA\Circles\Db\FederatedLinksRequest;
use OCA\Circles\Db\SharingFrameRequest;
Expand All @@ -50,6 +52,10 @@

class SharingFrameService {


use TNC19Request;


/** @var string */
private $userId;

Expand Down Expand Up @@ -297,32 +303,23 @@ public function receiveFrame($token, $uniqueId, SharingFrame $frame) {
* @return bool
* @throws Exception
*/
public function initiateShare($circleUniqueId, $frameUniqueId) {
$args = [
'circleId' => $circleUniqueId,
'frameId' => $frameUniqueId
];

$client = $this->clientService->newClient();
$addr = $this->configService->getLocalAddress() . \OC::$WEBROOT;
$opts = [
'body' => $args,
'timeout' => Application::CLIENT_TIMEOUT,
'connect_timeout' => Application::CLIENT_TIMEOUT
];

if ($this->configService->getAppValue(ConfigService::CIRCLES_SELF_SIGNED) === '1') {
$opts['verify'] = false;
}
public function initiateShare(string $circleUniqueId, string $frameUniqueId) {
$route = $this->urlGenerator->linkToRouteAbsolute('circles.Shares.initShareDelivery');
$request = new NC19Request('', Request::TYPE_POST);
$this->configService->configureRequest($request);
$request->setProtocols(['https', 'http']);
$request->addData('circleId', $circleUniqueId);
$request->addData('frameId', $frameUniqueId);
$request->setAddressFromUrl($route);

try {
$client->post($this->generatePayloadDeliveryURL($addr), $opts);
$this->doRequest($request);

return true;
} catch (Exception $e) {
$this->miscService->log(
'fail to initialise circle share to ' . $addr . ' for circle ' . $circleUniqueId . ' - '
. json_encode($opts) . ' - ' . $e->getMessage(), 3
'fail to initialise circle share with request ' . json_encode($request) . ' - '
. $e->getMessage(), 3
);
throw $e;
}
Expand Down

0 comments on commit 3e88484

Please sign in to comment.