implement channel alias

This commit is contained in:
yggverse 2024-05-05 01:11:32 +03:00
parent 0c6e5ce8ae
commit 30a7f69083
4 changed files with 54 additions and 18 deletions

View file

@ -123,10 +123,22 @@ class Nex implements MessageComponentInterface
$lines[] = sprintf(
'=> %s',
$channelItem->link
) . PHP_EOL;
);
}
}
// Get channel info
if ($channel = $this->_database->getChannel($channelItem->channelId))
{
$lines[] = sprintf(
'=> /%s %s',
urlencode(
$channel->alias
),
$channel->title
);
}
// Build response
$response = implode(
PHP_EOL,
@ -136,12 +148,12 @@ class Nex implements MessageComponentInterface
break;
// Chanel
case (bool) preg_match('/^\/(?<id>\d+)\/($|index\.gmi)$/i', $request, $attribute):
case (bool) preg_match('/^\/(?<alias>.+)$/i', $request, $attribute):
$lines = [];
// Get channel info
if ($channel = $this->_database->getChannel($attribute['id']))
if ($channel = $this->_database->getChannelByAlias($attribute['alias']))
{
if ($channel->title)
{
@ -208,8 +220,10 @@ class Nex implements MessageComponentInterface
foreach ((array) $this->_database->getChannels() as $channel)
{
$lines[] = sprintf(
'=> /%d/index.gmi %s',
$channel->id,
'=> /%s %s',
urlencode(
$channel->alias
),
$channel->title
);
}