mirror of
https://github.com/kevachat/webapp.git
synced 2025-01-22 20:44:59 +00:00
add clitor protocol viewer
This commit is contained in:
parent
ca6b4d9744
commit
6f9d6509c1
96
src/Controller/ViewController.php
Normal file
96
src/Controller/ViewController.php
Normal file
@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
class ViewController extends AbstractController
|
||||
{
|
||||
#[Route(
|
||||
'/view/{namespace}',
|
||||
name: 'view_raw',
|
||||
requirements:
|
||||
[
|
||||
'namespace' => '^N[A-z0-9]{33}$',
|
||||
],
|
||||
methods:
|
||||
[
|
||||
'GET'
|
||||
]
|
||||
)]
|
||||
public function raw(
|
||||
Request $request
|
||||
): Response
|
||||
{
|
||||
// Connect kevacoin
|
||||
$client = new \Kevachat\Kevacoin\Client(
|
||||
$this->getParameter('app.kevacoin.protocol'),
|
||||
$this->getParameter('app.kevacoin.host'),
|
||||
$this->getParameter('app.kevacoin.port'),
|
||||
$this->getParameter('app.kevacoin.username'),
|
||||
$this->getParameter('app.kevacoin.password')
|
||||
);
|
||||
|
||||
// Detect clitor-is-protocol
|
||||
if ($clitor = $client->kevaGet($request->get('namespace'), '_CLITOR_IS_'))
|
||||
{
|
||||
$reader = new \ClitorIsProtocol\Kevacoin\Reader(
|
||||
$clitor['value']
|
||||
);
|
||||
|
||||
if ($reader->valid())
|
||||
{
|
||||
if ($pieces = $client->kevaFilter($request->get('namespace')))
|
||||
{
|
||||
if ($data = $reader->data($pieces))
|
||||
{
|
||||
$response = new Response();
|
||||
|
||||
if ($mime = $reader->fileMime())
|
||||
{
|
||||
$response->headers->set(
|
||||
'Content-type',
|
||||
$mime
|
||||
);
|
||||
}
|
||||
|
||||
if ($length = $reader->fileLength())
|
||||
{
|
||||
if ($length == strlen($data))
|
||||
{
|
||||
$response->headers->set(
|
||||
'Content-length',
|
||||
$length
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ($name = $reader->fileName())
|
||||
{
|
||||
$response->headers->set(
|
||||
'Content-Disposition',
|
||||
sprintf(
|
||||
'inline; filename="%s";',
|
||||
$name
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$response->sendHeaders();
|
||||
|
||||
return $response->setContent(
|
||||
$data
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Nothing to view by this namespace
|
||||
throw $this->createNotFoundException();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user