Skip to content

Commit 5c29be2

Browse files
committed
WIP
1 parent 15d9146 commit 5c29be2

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

apps/federatedfilesharing/lib/Notifications.php

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,6 @@ protected function getTimestamp() {
275275
* @throws \Exception
276276
*/
277277
protected function tryHttpPostToShareEndpoint($remoteDomain, $urlSuffix, array $fields) {
278-
$client = $this->httpClientService->newClient();
279278

280279
if ($this->addressHandler->urlContainProtocol($remoteDomain) === false) {
281280
$remoteDomain = 'https://' . $remoteDomain;
@@ -286,6 +285,17 @@ protected function tryHttpPostToShareEndpoint($remoteDomain, $urlSuffix, array $
286285
'result' => '',
287286
];
288287

288+
// if possible we use the new OCM API
289+
$ocmEndPoint = $this->getOCMEndPoint($remoteDomain);
290+
if ($ocmEndPoint) {
291+
$ocmResult = $this->sendNotificationToOCMEndPoint($remoteDomain, $urlSuffix, $fields);
292+
$result['result'] = $ocmResult['body'];
293+
$result['success'] = true;
294+
return $result;
295+
}
296+
297+
// Fall back to old API
298+
$client = $this->httpClientService->newClient();
289299
$federationEndpoints = $this->discoveryService->discover($remoteDomain, 'FEDERATED_SHARING');
290300
$endpoint = isset($federationEndpoints['share']) ? $federationEndpoints['share'] : '/ocs/v2.php/cloud/shares';
291301
try {
@@ -307,4 +317,38 @@ protected function tryHttpPostToShareEndpoint($remoteDomain, $urlSuffix, array $
307317

308318
return $result;
309319
}
320+
321+
/**
322+
* check if server supports the new OCM api and ask for the correct end-point
323+
*
324+
* @param string $url
325+
* @return string
326+
*/
327+
protected function getOCMEndPoint($url) {
328+
$client = $this->httpClientService->newClient();
329+
try {
330+
$response = $client->get($url, ['timeout' => 10, 'connect_timeout' => 10]);
331+
} catch (\Exception $e) {
332+
return '';
333+
}
334+
335+
$result = $response->getBody();
336+
$result = json_decode($result, true);
337+
338+
if (isset($result['end-point'])) {
339+
return $result['end-point'];
340+
}
341+
342+
return '';
343+
}
344+
345+
protected function sendNotificationToOCMEndPoint($remoteDomain, $urlSuffix, $fields) {
346+
$client = $this->httpClientService->newClient();
347+
switch ($urlSuffix) {
348+
case '':
349+
null;
350+
break;
351+
}
352+
353+
}
310354
}

0 commit comments

Comments
 (0)