src/Controller/DownloadController.php line 232
<?phpnamespace App\Controller;use App\AppHelper\Helper;use App\AppHelper\Settings;use App\Entity\ApiLog;use App\Entity\DatabaseBackups;use App\Entity\Patch;use App\Entity\Product;use App\Entity\SystemSettings;use App\Entity\UpdateChecker;use Doctrine\ORM\EntityManagerInterface;use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;use Symfony\Component\HttpFoundation\Request;use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;use Symfony\Component\HttpFoundation\BinaryFileResponse;use Symfony\Component\HttpFoundation\JsonResponse;use Symfony\Component\HttpFoundation\Response;use Symfony\Component\HttpFoundation\ResponseHeaderBag;use Symfony\Component\Routing\Annotation\Route;use Symfony\Component\Serializer\Exception\ExceptionInterface;use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;use Symfony\Component\Serializer\Serializer;use Symfony\Contracts\Translation\TranslatorInterface;#[Route('/download', name: 'app_download')]class DownloadController extends AbstractController{use Settings;public function __construct(private readonly TranslatorInterface $translator,private readonly EntityManagerInterface $em,){}/*** @param DatabaseBackups $databaseBackups* @return BinaryFileResponse|void*/#[IsGranted('ROLE_ADMIN')]#[Route('/{id}/sql-dump', name: '_sql_dump')]public function download_sql_dump(DatabaseBackups $databaseBackups){$file = $this->getParameter('sql_backup_dir') . '/' . $databaseBackups->getDescription();if (is_file($file)) {return new BinaryFileResponse($file);}}/*** @param $type* @param $dezimal* @return BinaryFileResponse|void*/#[IsGranted('ROLE_ADMIN')]#[Route('/icons/{type}/{dezimal}', name: '_icon_download')]public function icon_download($type, $dezimal){$helper = Helper::instance();$filename = '';switch ($type) {case 'fa47':$fileDir = $this->getParameter('fa47_icon_dir') . DIRECTORY_SEPARATOR;$svgDir = $fileDir . 'icons' . DIRECTORY_SEPARATOR;if (is_file($fileDir . 'fa-icons.json')) {$faJson = json_decode(file_get_contents($fileDir . 'fa-icons.json'), true);foreach ($faJson as $tmp) {if (dechex((int)$dezimal) === $tmp['code']) {$filename = $tmp['title'] . '.svg';break;}}}if ($filename) {$file = $svgDir . $filename;if (is_file($file)) {$response = new BinaryFileResponse($file);$response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT,basename($file));return $response;}}break;case'fa640':$raw = '';$fileDir = $this->getParameter('fa640_icon_dir') . DIRECTORY_SEPARATOR;if (is_dir($fileDir . 'icon')) {$helper->recursive_destroy_dir($fileDir . 'icon');}if (is_file($fileDir . 'fa640.json')) {$faJson = json_decode(file_get_contents($fileDir . 'fa640.json'), true);foreach ($faJson as $tmp) {if (dechex((int)$dezimal) === $tmp['hex']) {$filename = $tmp['icon'] . '.svg';$raw = $tmp['raw'];break;}}}if ($filename && $raw) {if (!is_dir($fileDir . 'icon')) {mkdir($fileDir . 'icon');}$file = $fileDir . 'icon' . DIRECTORY_SEPARATOR . $filename;file_put_contents($file, $raw);if (is_file($file)) {$response = new BinaryFileResponse($file);$response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT,basename($file));return $response;}}break;case 'bs':$fileDir = $this->getParameter('bs_icon_dir') . DIRECTORY_SEPARATOR . 'font' . DIRECTORY_SEPARATOR;$svgDir = $this->getParameter('bs_icon_dir') . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR;if (is_file($fileDir . 'bootstrap-icons.json')) {$bsJson = json_decode(file_get_contents($fileDir . 'bootstrap-icons.json'), true);foreach ($bsJson as $key => $val) {if ((int)$val === (int)$dezimal) {$filename = $key . '.svg';break;}}}if ($filename) {$file = $svgDir . $filename;if (is_file($file)) {$response = new BinaryFileResponse($file);$response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT,basename($file));return $response;}}break;case'md':$url = '';$name = '';$fileDir = $this->getParameter('material_design_icon_dir') . DIRECTORY_SEPARATOR;$helper->recursive_destroy_dir($fileDir . 'icon');if (is_file($fileDir . 'material-design.json')) {$mdJson = json_decode(file_get_contents($fileDir . 'material-design.json'), true);foreach ($mdJson as $tmp) {if ($tmp['dezimal'] === (int)$dezimal) {$name = $tmp['name'];$url = sprintf('https://raw.githubusercontent.com/google/material-design-icons/master/src/%s/%s/materialicons/24px.svg', $tmp['category'], $tmp['name']);}}}if ($url && $helper->url_check($url)) {$icon = file_get_contents($url);if ($icon) {if (!is_dir($fileDir . 'icon')) {mkdir($fileDir . 'icon');}$newFile = $fileDir . 'icon' . DIRECTORY_SEPARATOR . $name . '.svg';file_put_contents($newFile, $icon);$response = new BinaryFileResponse($newFile);$response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT,basename($newFile));return $response;}}break;}}/*** @param Patch $patch* @return BinaryFileResponse|void*/#[IsGranted('ROLE_ADMIN')]#[Route('/{id}/patch', name: '_patch')]public function download_patch(Patch $patch){$file = $this->getParameter('patch_dir') . DIRECTORY_SEPARATOR . $patch->getPatchBezeichnung() . '.zip';if (is_file($file)) {$response = new BinaryFileResponse($file);$response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT,$patch->getPatchBezeichnung() . '.zip');return $response;}}/*** @param Product $product* @return BinaryFileResponse|void*/// #[IsGranted('ROLE_ADMIN')]// #[IsGranted('ROLE_OAUTH2_PRODUCT')]// /**// * @Security("is_granted('ROLE_ADMIN') or is_granted('ROLE_OAUTH2_PRODUCT')")// */#[Security("is_granted('ROLE_ADMIN') or is_granted('ROLE_OAUTH2_PRODUCT')")]#[Route('/{id}/product', name: '_download_product')]public function download_product(Product $product){$file = $this->getParameter('product_dir') . '/' . $product->getSlug() . '/' . $product->getSlug() . '.zip';if (is_file($file)) {$response = new BinaryFileResponse($file);$response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT,$product->getSlug() . '.zip');return $response;}}/*** @param Request $request* @return BinaryFileResponse|Response*/#[Route('/{slug}/update', name: '_download_update')]public function download_update(Request $request){$file = $this->getParameter('product_dir') . '/' . $request->get('slug') . '/' . $request->get('slug') . '.zip';if (is_file($file)) {$response = new BinaryFileResponse($file);$response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT,$request->get('slug') . '.zip');return $response;} else {return $this->render('main/404.html.twig', []);}}#[Route('/{slug}/{logId}/{pt}/update-json', name: '_update_json')]public function product_update_json(Request $request): JsonResponse{$product = $this->em->getRepository(Product::class)->findOneBy(['slug' => $request->get('slug')]);if (!$product->getUpdateChecker()) {return new JsonResponse((object)[],403);}$apiLog = $this->em->getRepository(ApiLog::class)->find($request->get('logId'));if (!$apiLog) {$updateAktiv = 0;} else {$updateAktiv = $apiLog->getUpdateAktiv();}$update_config = json_decode($product->getUpdateChecker()->getUpdateData(), true);if ($product->getUpdateChecker()->getType() == 'plugin') {if (!$product->getUpdateChecker()->isRatingAktiv()) {unset($update_config['rating']);unset($update_config['num_ratings']);unset($update_config['downloaded']);unset($update_config['active_installs']);}if (!$product->getUpdateChecker()->isLanguageAktiv()) {unset($update_config['translations']);}}$selfUrl = $request->getSchemeAndHttpHost();if ($request->get('pt') == 1) {$data = ['is_git' => (int)$product->isIsGit(),'update_aktiv' => $updateAktiv,'self' => $selfUrl,'git_config' => json_decode($product->getUpdateChecker()->getGitData()),'update_config' => $update_config];} else {$data = $update_config;}return new JsonResponse($data,200);}}