mirror of
https://codeberg.org/streams/streams.git
synced 2024-09-19 21:55:15 +00:00
add alsoKnownAs entities to actor record.
This commit is contained in:
parent
43fe5d4d15
commit
dde59ffbe5
4 changed files with 149 additions and 2 deletions
|
@ -1702,16 +1702,42 @@ class Activity
|
|||
}
|
||||
$auto_follow = intval(PConfig::Get($channel['channel_id'],'system','autoperms'));
|
||||
}
|
||||
|
||||
$aka = [];
|
||||
if ($channel) {
|
||||
$locations = self::nomadic_locations(['author_xchan' => $channel['channel_hash']]);
|
||||
$aplocations = self::nomadic_locations(['author_xchan' => Channel::getDid($channel)]);
|
||||
$aka[] = Channel::getDidResolver($channel, true);
|
||||
$aka[] = z_root() . '/.well-known/nomad-gateway/' . $channel['xchan_hash'] . '/actor';
|
||||
$aka[] = z_root() . '/channel/' . $channel['channel_address'];
|
||||
$gateways[] = z_root();
|
||||
if ($locations) {
|
||||
foreach ($locations as $location) {
|
||||
if ($location['hubloc_url'] === z_root()) {
|
||||
continue;
|
||||
}
|
||||
if (! in_array($location['hubloc_url'], $gateways)) {
|
||||
$gateways[] = $location['hubloc_url'];
|
||||
}
|
||||
if (! in_array($location['hubloc_url'] . '/.well-known/nomad-gateway/' . $location['hubloc_hash'] . '/actor', $aka)) {
|
||||
$aka[] = $location['hubloc_url'] . '/.well-known/nomad-gateway/' . $location['hubloc_hash'] . '/actor';
|
||||
}
|
||||
if (! in_array($location['hubloc_id_url'], $aka)) {
|
||||
$aka[] = $location['hubloc_id_url'];
|
||||
}
|
||||
}
|
||||
foreach ($aplocations as $location) {
|
||||
if (! in_array($location['hubloc_url'], $gateways)) {
|
||||
$gateways[] = $location['hubloc_url'];
|
||||
}
|
||||
if (! in_array($location['hubloc_id_url'], $aka)) {
|
||||
$aka[] = $location['hubloc_id_url'];
|
||||
}
|
||||
}
|
||||
$actor->setAlsoKnownAs($aka);
|
||||
$actor->setGateways($gateways);
|
||||
}
|
||||
$actor->setId($nomadic ? Channel::getDidResolver($channel, true) : Channel::url($channel));
|
||||
|
||||
} else {
|
||||
$actor->setId((str_starts_with($p['xchan_hash'], 'http')) ? $p['xchan_hash'] : $current_url);
|
||||
}
|
||||
|
|
|
@ -2092,6 +2092,11 @@ class Channel
|
|||
return z_root() . '/.well-known/apgateway/' . self::getDid($channel) . (($isActor) ? '/actor' : '');
|
||||
}
|
||||
|
||||
public static function getNomadResolver($channel, $isActor = false)
|
||||
{
|
||||
return z_root() . '/.well-known/nomad-gateway/' . $channel['channel_hash']. (($isActor) ? '/actor' : '');
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get a channel array by a channel_hash.
|
||||
*
|
||||
|
|
109
src/Module/Nomad_gateway.php
Normal file
109
src/Module/Nomad_gateway.php
Normal file
|
@ -0,0 +1,109 @@
|
|||
<?php
|
||||
|
||||
namespace Code\Module;
|
||||
|
||||
use App;
|
||||
use Code\Web\Controller;
|
||||
use Code\Web\Router;
|
||||
|
||||
class Nomad_gateway extends Controller
|
||||
{
|
||||
|
||||
protected $module;
|
||||
|
||||
public function init()
|
||||
{
|
||||
|
||||
$url = null;
|
||||
for ($index = 1; $index < argc(); $index ++) {
|
||||
if ($index != 1) {
|
||||
$url .= '/';
|
||||
}
|
||||
$url .= argv($index);
|
||||
}
|
||||
// Extract the portable_id from the URL.
|
||||
$key = $url;
|
||||
$key = rtrim($key, '/');
|
||||
$index = strpos($key, '/');
|
||||
$key = substr($key, 0, $index ?: null);
|
||||
|
||||
// Find a channel on this site which has that ed25519 key.
|
||||
$query = q("select * from xchan left join channel
|
||||
on xchan_hash = channel_hash where xchan_hash = '%s'",
|
||||
dbesc($key)
|
||||
);
|
||||
if (!($query && isset($query[0]['channel_id']))) {
|
||||
http_status_exit(404, 'Not found');
|
||||
}
|
||||
$mappedPath = $this->mapObject(str_replace($key, '', rtrim($url, '/')), $query[0]);
|
||||
$localPath = ltrim($mappedPath, '/');
|
||||
App::$cmd = $localPath;
|
||||
App::$argv = explode('/', App::$cmd);
|
||||
|
||||
App::$argc = count(App::$argv);
|
||||
if ((array_key_exists('0', App::$argv)) && strlen(App::$argv[0])) {
|
||||
if (strpos(App::$argv[0],'.')) {
|
||||
$_REQUEST['module_format'] = substr(App::$argv[0],strpos(App::$argv[0], '.') + 1);
|
||||
App::$argv[0] = substr(App::$argv[0], 0, strpos(App::$argv[0], '.'));
|
||||
}
|
||||
|
||||
App::$module = str_replace(".", "_", App::$argv[0]);
|
||||
App::$module = str_replace("-", "_", App::$module);
|
||||
if (str_starts_with(App::$module, '_')) {
|
||||
App::$module = substr(App::$module, 1);
|
||||
}
|
||||
}
|
||||
else {
|
||||
App::$argc = 1;
|
||||
App::$argv = ['home'];
|
||||
App::$module = 'home';
|
||||
}
|
||||
header('Link: ' . '<' . $url . '>; rel="alternate"', false);
|
||||
// recursively call the router.
|
||||
App::$module_loaded = false;
|
||||
$router = new Router();
|
||||
$router->Dispatch();
|
||||
|
||||
}
|
||||
|
||||
protected function mapObject($path, $channel)
|
||||
{
|
||||
// lookup abstract paths
|
||||
$systemPaths = [
|
||||
'' => '/channel/' . $channel['channel_address'],
|
||||
'/inbox' => '/inbox/' . $channel['channel_address'],
|
||||
'/outbox' => '/outbox/' . $channel['channel_address'],
|
||||
'/followers' => '/followers/' . $channel['channel_address'],
|
||||
'/following' => '/following/' . $channel['channel_address'],
|
||||
'/permissions' => '/permissions/' . $channel['channel_address'],
|
||||
'/actor' => '/channel/' . $channel['channel_address'],
|
||||
'/actor/inbox' => '/inbox/' . $channel['channel_address'],
|
||||
'/actor/outbox' => '/outbox/' . $channel['channel_address'],
|
||||
'/actor/followers' => '/followers/' . $channel['channel_address'],
|
||||
'/actor/following' => '/following/' . $channel['channel_address'],
|
||||
'/actor/permissions' => '/permissions/' . $channel['channel_address'],
|
||||
];
|
||||
|
||||
$partialPaths = [
|
||||
'/files/' => '/cloud/' . $channel['channel_address'],
|
||||
'/photos/' => '/photos/' . $channel['channel_address'],
|
||||
'/album/' => '/album/' . $channel['channel_address'],
|
||||
];
|
||||
|
||||
foreach ($systemPaths as $index => $localPath) {
|
||||
if ($path === $index) {
|
||||
return $localPath;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($partialPaths as $index => $localPath) {
|
||||
if (str_starts_with($path, $index)) {
|
||||
$suffix = substr($path, strlen($index));
|
||||
return $localPath . '/' . ltrim($suffix, '/');
|
||||
}
|
||||
}
|
||||
return $path;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -46,6 +46,13 @@ class Well_known extends Controller
|
|||
$module = new Apgateway();
|
||||
$module->init();
|
||||
break;
|
||||
case 'nomad-gateway':
|
||||
App::$argc -= 1;
|
||||
array_shift(App::$argv);
|
||||
App::$argv[0] = 'nomad-gateway';
|
||||
$module = new Nomad_gateway();
|
||||
$module->init();
|
||||
break;
|
||||
case 'oauth-authorization-server':
|
||||
case 'openid-configuration':
|
||||
App::$argc -= 1;
|
||||
|
|
Loading…
Reference in a new issue