• Модуль: disk
  • Путь к файлу: ~/bitrix/modules/disk/lib/controller/integration/b24documents.php
  • Класс: BitrixDiskControllerIntegrationB24Documents
  • Вызов: B24Documents::listAllowedServersAction
public function listAllowedServersAction(): array
{
	$primarySettings = Configuration::getInstance()->get('b24documents');
	if (!empty($primarySettings['proxyServers']))
	{
		return [
			'servers' => $primarySettings['proxyServers'],
		];
	}

	$configuration = new DocumentOnlyOfficeConfiguration();
	$serverListUrl = $configuration->getB24DocumentsServerListEndpoint();
	if (!$serverListUrl)
	{
		return [];
	}

	$http = new HttpClient([
		'socketTimeout' => 5,
		'streamTimeout' => 5,
		'version' => HttpClient::HTTP_1_1,
	]);

	if ($http->get($serverListUrl) === false)
	{
		$this->addError(new Error('Server is not available.'));

		return [];
	}
	if ($http->getStatus() !== 200)
	{
		$this->addError(new Error('Server is not available. Status ' . $http->getStatus()));

		return [];
	}

	$response = Json::decode($http->getResult());
	if (!$response)
	{
		$this->addError(new Error('Could not decode response.'));

		return [];
	}

	if (empty($response['servers']))
	{
		$this->addError(new Error('Empty server list.'));

		return [];
	}

	$servers = [];
	foreach ($response['servers'] as $server)
	{
		$servers[] = [
			'proxy' => $server['proxy'],
			'region' => $server['region'] ?? null,
		];
	}

	return [
		'servers' => $servers,
	];
}