mirror of
https://github.com/bitinflow/expose.git
synced 2026-03-13 13:35:54 +00:00
wip
This commit is contained in:
@@ -2,13 +2,20 @@
|
||||
|
||||
namespace App\Commands;
|
||||
|
||||
use App\Client\Exceptions\InvalidServerProvided;
|
||||
use App\Logger\CliRequestLogger;
|
||||
use Illuminate\Console\Parser;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use LaravelZero\Framework\Commands\Command;
|
||||
use Symfony\Component\Console\Output\ConsoleOutput;
|
||||
|
||||
abstract class ServerAwareCommand extends Command
|
||||
{
|
||||
const DEFAULT_HOSTNAME = 'sharedwithexpose.com';
|
||||
const DEFAULT_PORT = 443;
|
||||
const DEFAULT_SERVER_ENDPOINT = 'https://beyondco.de/api/expose/servers';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
@@ -31,11 +38,81 @@ abstract class ServerAwareCommand extends Command
|
||||
|
||||
protected function getServerHost()
|
||||
{
|
||||
return $this->option('server-host') ?? config('expose.servers.'.$this->option('server').'.host', 'localhost');
|
||||
if ($this->option('server-host')) {
|
||||
return $this->option('server-host');
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to find the server in the servers array.
|
||||
* If no array exists at all (when upgrading from v1),
|
||||
* always return sharedwithexpose.com
|
||||
*/
|
||||
if (config('expose.servers') === null) {
|
||||
return static::DEFAULT_HOSTNAME;
|
||||
}
|
||||
|
||||
$server = $this->option('server');
|
||||
$host = config('expose.servers.'.$server.'.host');
|
||||
|
||||
if (! is_null($host)) {
|
||||
return $host;
|
||||
}
|
||||
|
||||
return $this->lookupRemoteServerHost($server);
|
||||
}
|
||||
|
||||
protected function getServerPort()
|
||||
{
|
||||
return $this->option('server-port') ?? config('expose.servers.'.$this->option('server').'.port', 8080);
|
||||
if ($this->option('server-port')) {
|
||||
return $this->option('server-port');
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to find the server in the servers array.
|
||||
* If no array exists at all (when upgrading from v1),
|
||||
* always return sharedwithexpose.com
|
||||
*/
|
||||
if (config('expose.servers') === null) {
|
||||
return static::DEFAULT_PORT;
|
||||
}
|
||||
|
||||
|
||||
$server = $this->option('server');
|
||||
$host = config('expose.servers.'.$server.'.port');
|
||||
|
||||
if (! is_null($host)) {
|
||||
return $host;
|
||||
}
|
||||
|
||||
return $this->lookupRemoteServerPort($server);
|
||||
}
|
||||
|
||||
protected function lookupRemoteServers()
|
||||
{
|
||||
try {
|
||||
return Http::get(config('expose.server_endpoint', static::DEFAULT_SERVER_ENDPOINT))->json();
|
||||
} catch (\Throwable $e) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
protected function lookupRemoteServerHost($server)
|
||||
{
|
||||
$servers = $this->lookupRemoteServers();
|
||||
$host = Arr::get($servers, $server.'.host');
|
||||
|
||||
throw_if(is_null($host), new InvalidServerProvided($server));
|
||||
|
||||
return $host;
|
||||
}
|
||||
|
||||
protected function lookupRemoteServerPort($server)
|
||||
{
|
||||
$servers = $this->lookupRemoteServers();
|
||||
$port = Arr::get($servers, $server.'.port');
|
||||
|
||||
throw_if(is_null($port), new InvalidServerProvided($server));
|
||||
|
||||
return $port;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace App\Commands;
|
||||
|
||||
class ShareCurrentWorkingDirectoryCommand extends ShareCommand
|
||||
{
|
||||
protected $signature = 'share-cwd {host?} {--subdomain=} {--auth=}';
|
||||
protected $signature = 'share-cwd {host?} {--subdomain=} {--auth=} {--dns=}';
|
||||
|
||||
public function handle()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user