1
0
Fork 0

Add API endpoint to make IAR files downloadable

master
Anonymous Contributor 2023-09-11 06:05:50 +02:00
parent 6a4c343b03
commit 891f1dff70
2 changed files with 26 additions and 1 deletions

View File

@ -22,7 +22,8 @@ class Mcp implements ConnectionProvider
'getAccessList' => 'Api\\GetAccessList', 'getAccessList' => 'Api\\GetAccessList',
'onlineDisplay' => 'Api\\OnlineDisplay', 'onlineDisplay' => 'Api\\OnlineDisplay',
'viewerWelcomeSite' => 'Api\\ViewerWelcomePage', 'viewerWelcomeSite' => 'Api\\ViewerWelcomePage',
'runCron' => 'Api\\CronStarter' 'runCron' => 'Api\\CronStarter',
'downloadIar' => 'Api\\DownloadIar'
], ],
'page' => [ 'page' => [
'dashboard' => 'Page\\Dashboard', 'dashboard' => 'Page\\Dashboard',

24
app/api/DownloadIar.php Normal file
View File

@ -0,0 +1,24 @@
<?php
declare(strict_types=1);
namespace Mcp\Api;
class DownloadIar extends \Mcp\RequestHandler
{
public function get(): void
{
if (preg_match('/^[a-f0-9]{32}$/', $_GET['id'])) {
$path = $this->app->getDataDir().DIRECTORY_SEPARATOR.'iars'.DIRECTORY_SEPARATOR.$_GET['id'].'.iar';
if (file_exists($path)) {
header('Content-Type: '.mime_content_type($path));
header('Content-Disposition: attachment; filename='.$_GET['id'].'.iar');
header('Content-Length: '.filesize($path));
readfile($path);
return;
}
}
http_response_code(404);
}
}