mirror of https://github.com/kevachat/webapp.git
ghost
12 months ago
1 changed files with 96 additions and 0 deletions
@ -0,0 +1,96 @@
@@ -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…
Reference in new issue