mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-03-13 06:01:21 +00:00
draft nex protocol support
This commit is contained in:
parent
8944bd2792
commit
71e3c270c4
@ -2,6 +2,11 @@
|
||||
|
||||
At this moment project under development!
|
||||
|
||||
## Protocols
|
||||
|
||||
* [x] Gemini
|
||||
* [ ] Nex
|
||||
|
||||
## Features
|
||||
|
||||
* [x] Custom DNS resolver with memory cache (useful for alt networks like [Yggdrasil](https://github.com/yggdrasil-network/yggdrasil-go))
|
||||
|
@ -6,6 +6,7 @@
|
||||
"type": "project",
|
||||
"require": {
|
||||
"yggverse/gemini": "dev-main",
|
||||
"yggverse/nex": "dev-main",
|
||||
"yggverse/net": "dev-main"
|
||||
},
|
||||
"license": "MIT",
|
||||
|
@ -560,6 +560,14 @@ class Page
|
||||
|
||||
break;
|
||||
|
||||
case str_starts_with($url, 'nex://'):
|
||||
|
||||
$this->_openNex(
|
||||
$url
|
||||
);
|
||||
|
||||
break;
|
||||
|
||||
case str_starts_with($url, 'yoda://'):
|
||||
|
||||
$this->_openYoda(
|
||||
@ -797,6 +805,134 @@ class Page
|
||||
}
|
||||
}
|
||||
|
||||
private function _openNex(
|
||||
string $url,
|
||||
bool $history = true
|
||||
): void
|
||||
{
|
||||
// Init progressbar
|
||||
if ($this->config->progressbar->visible)
|
||||
{
|
||||
$this->setProgress(0);
|
||||
}
|
||||
|
||||
// Init base URL
|
||||
$origin = new \Yggverse\Net\Address(
|
||||
$url
|
||||
);
|
||||
|
||||
// Track response time
|
||||
$start = microtime(true);
|
||||
|
||||
// Init custom resolver
|
||||
$host = null;
|
||||
|
||||
if ($this->config->resolver->enabled)
|
||||
{
|
||||
$address = new \Yggverse\Net\Address(
|
||||
$url
|
||||
);
|
||||
|
||||
$name = $address->getHost();
|
||||
|
||||
if (!$host = $this->dns->get($name))
|
||||
{
|
||||
$resolve = new \Yggverse\Net\Resolve(
|
||||
$this->config->resolver->request->record,
|
||||
$this->config->resolver->request->host,
|
||||
$this->config->resolver->request->timeout,
|
||||
$this->config->resolver->result->shuffle
|
||||
);
|
||||
|
||||
$resolved = $resolve->address(
|
||||
$address
|
||||
);
|
||||
|
||||
if ($resolved)
|
||||
{
|
||||
$host = $resolved->getHost();
|
||||
|
||||
$this->dns->set(
|
||||
$name,
|
||||
$host
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$request = new \Yggverse\Nex\Client\Request(
|
||||
$url,
|
||||
$host
|
||||
);
|
||||
|
||||
$raw = $request->getResponse();
|
||||
|
||||
$end = microtime(true);
|
||||
|
||||
$this->content->set_markup(
|
||||
$raw // @TODO
|
||||
);
|
||||
|
||||
$this->setTitle(
|
||||
$origin->getHost()
|
||||
);
|
||||
|
||||
$this->status->set_markup(
|
||||
str_replace( // Custom macros mask from config.json
|
||||
[
|
||||
'{TIME_C}',
|
||||
'{REQUEST_BASE}',
|
||||
'{REQUEST_BASE_URL}',
|
||||
'{RESPONSE_CODE}',
|
||||
'{RESPONSE_META}',
|
||||
'{RESPONSE_LENGTH}',
|
||||
'{RESPONSE_SECONDS}'
|
||||
],
|
||||
[
|
||||
date(
|
||||
'c'
|
||||
),
|
||||
$origin->getHost(),
|
||||
sprintf(
|
||||
'<a href="%s">%s</a>',
|
||||
$origin->get(
|
||||
true, // scheme
|
||||
true, // user
|
||||
true, // pass
|
||||
true, // host
|
||||
true, // port
|
||||
false, // path
|
||||
false, // query
|
||||
false // fragment
|
||||
),
|
||||
$origin->getHost()
|
||||
),
|
||||
'-', // @TODO
|
||||
'-',
|
||||
number_format(
|
||||
mb_strlen(
|
||||
$raw
|
||||
)
|
||||
),
|
||||
round(
|
||||
$end - $start, 2
|
||||
)
|
||||
],
|
||||
$this->config->footer->status->open->complete
|
||||
)
|
||||
);
|
||||
|
||||
// Update history database
|
||||
if ($history && $this->config->history->database->enabled)
|
||||
{
|
||||
$this->app->history->add(
|
||||
$url,
|
||||
$title,
|
||||
$this->config->history->database->mode->renew
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private function _openYoda(
|
||||
string $url
|
||||
): void
|
||||
|
Loading…
x
Reference in New Issue
Block a user