Browse Source

implement media viewer

main
ghost 10 months ago
parent
commit
4804fbe181
  1. 2
      README.md
  2. 3
      composer.json
  3. 50
      src/controller/media.php
  4. 37
      src/server.php

2
README.md

@ -18,7 +18,7 @@ KevaChat Application for Gemini Protocol
* [ ] Post publication * [ ] Post publication
* [ ] Post replies * [ ] Post replies
* [ ] Rooms publication * [ ] Rooms publication
* [ ] Media viewer * [x] Media viewer
* [ ] Users auth * [ ] Users auth
* [x] Error handlers * [x] Error handlers

3
composer.json

@ -10,6 +10,7 @@
}, },
"require": { "require": {
"yggverse/titan-ii": "^1.0", "yggverse/titan-ii": "^1.0",
"kevachat/kevacoin": "^1.6" "kevachat/kevacoin": "^1.6",
"clitor-is-protocol/kevacoin": "^1.0"
} }
} }

50
src/controller/media.php

@ -0,0 +1,50 @@
<?php
namespace Kevachat\Geminiapp\Controller;
class Media
{
private $_config;
private \Kevachat\Kevacoin\Client $_kevacoin;
public function __construct($config)
{
// Init config
$this->_config = $config;
// Init kevacoin
$this->_kevacoin = new \Kevachat\Kevacoin\Client(
$this->_config->kevacoin->server->protocol,
$this->_config->kevacoin->server->host,
$this->_config->kevacoin->server->port,
$this->_config->kevacoin->server->username,
$this->_config->kevacoin->server->password
);
}
public function raw(string $namespace, ?string &$mime = null): mixed
{
if ($clitoris = $this->_kevacoin->kevaGet($namespace, '_CLITOR_IS_'))
{
$reader = new \ClitorIsProtocol\Kevacoin\Reader(
$clitoris['value']
);
if ($reader->valid())
{
if ($pieces = $this->_kevacoin->kevaFilter($namespace))
{
if ($data = $reader->data($pieces))
{
$mime = $reader->fileMime();
return $data;
}
}
}
}
return null;
}
}

37
src/server.php

@ -104,18 +104,21 @@ foreach ((array) scandir(__DIR__ . '/../host') as $host)
// Dynamical requests // Dynamical requests
default: default:
// Room posts by namespace if (preg_match('/^\/([A-z]+)\/(N[A-z0-9]{33})$/', $request->getPath(), $matches))
if (preg_match('/^\/room\/(N[A-z0-9]{33})$/', $request->getPath(), $matches))
{ {
if (!empty($matches[1])) if (!empty($matches[1]) && !empty($matches[2]))
{ {
switch ($matches[1])
{
case 'room':
include_once __DIR__ . '/controller/room.php'; include_once __DIR__ . '/controller/room.php';
$room = new \Kevachat\Geminiapp\Controller\Room( $room = new \Kevachat\Geminiapp\Controller\Room(
$config $config
); );
if ($posts = $room->posts($matches[1])) if ($posts = $room->posts($matches[2]))
{ {
$response->setContent( $response->setContent(
$posts $posts
@ -123,6 +126,32 @@ foreach ((array) scandir(__DIR__ . '/../host') as $host)
return $response; return $response;
} }
break;
case 'raw':
include_once __DIR__ . '/controller/media.php';
$media = new \Kevachat\Geminiapp\Controller\Media(
$config
);
if ($data = $media->raw($matches[2], $mime))
{
$response->setMeta(
$mime
);
$response->setContent(
$data
);
return $response;
}
break;
}
} }
} }
} }

Loading…
Cancel
Save