Browse Source

implement media viewer

main
ghost 9 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 @@ -18,7 +18,7 @@ KevaChat Application for Gemini Protocol
* [ ] Post publication
* [ ] Post replies
* [ ] Rooms publication
* [ ] Media viewer
* [x] Media viewer
* [ ] Users auth
* [x] Error handlers

3
composer.json

@ -10,6 +10,7 @@ @@ -10,6 +10,7 @@
},
"require": {
"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 @@ @@ -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) @@ -104,18 +104,21 @@ foreach ((array) scandir(__DIR__ . '/../host') as $host)
// Dynamical requests
default:
// Room posts by namespace
if (preg_match('/^\/room\/(N[A-z0-9]{33})$/', $request->getPath(), $matches))
if (preg_match('/^\/([A-z]+)\/(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';
$room = new \Kevachat\Geminiapp\Controller\Room(
$config
);
if ($posts = $room->posts($matches[1]))
if ($posts = $room->posts($matches[2]))
{
$response->setContent(
$posts
@ -123,6 +126,32 @@ foreach ((array) scandir(__DIR__ . '/../host') as $host) @@ -123,6 +126,32 @@ foreach ((array) scandir(__DIR__ . '/../host') as $host)
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