Add API endpoint to make IAR files downloadable
							parent
							
								
									6a4c343b03
								
							
						
					
					
						commit
						891f1dff70
					
				|  | @ -22,7 +22,8 @@ class Mcp implements ConnectionProvider | |||
|             'getAccessList' => 'Api\\GetAccessList', | ||||
|             'onlineDisplay' => 'Api\\OnlineDisplay', | ||||
|             'viewerWelcomeSite' => 'Api\\ViewerWelcomePage', | ||||
|             'runCron' => 'Api\\CronStarter' | ||||
|             'runCron' => 'Api\\CronStarter', | ||||
|             'downloadIar' => 'Api\\DownloadIar' | ||||
|         ], | ||||
|         'page' => [ | ||||
|             'dashboard' => 'Page\\Dashboard', | ||||
|  |  | |||
|  | @ -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); | ||||
|     } | ||||
| } | ||||
		Loading…
	
		Reference in New Issue
	
	 Anonymous Contributor
						Anonymous Contributor