<commit_before><?php

declare(strict_types=1);

namespace App\Controller;

use App\Esa\HtmlHandler;
use App\Esa\Proxy;
use App\Esa\WebhookValidator;
use App\Service\AccessController;
use App\Service\AssetResolver;
use Polidog\Esa\Exception\ClientException;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Annotation\Route;

#[Route('/', name: 'default_')]
class DefaultController extends AbstractController
{
    #[Route('/', name: 'index')]
    public function index(Request $request): Response
    {
        if ($postId = $request->get('post_id')) {
            return $this->redirectToRoute('default_post', ['id' => $postId]);
        }

        return $this->render('default/index.html.twig');
    }

    #[Route('/post/{id}', name: 'post', requirements: ['id' => '\d+'])]
    public function post(
        Request $request,
        int $id,
        Proxy $esa,
        AccessController $accessController,
        HtmlHandler $htmlHandler,
        AssetResolver $assetResolver,
        array $htmlReplacements,
    ): Response {
        $force = boolval($request->get('force', 0));

        try {
            $post = $esa->getPost($id, $force);
        } catch (ClientException $e) {
            throw new NotFoundHttpException();
        }

        if (!$accessController->isPublic($post['category'], $post['tags'])) {
            throw new NotFoundHttpException();
        }

        // fix body_html
        $htmlHandler
            ->initialize($post['body_html'])
            ->replacePostUrls('default_post', 'id')
            ->disableMentionLinks()
            ->replaceEmojiCodes()
            ->replaceHtml($htmlReplacements)
            ->dumpHtml()
        ;
        $post['body_html'] = $htmlHandler->dumpHtml();
        $toc = $htmlHandler->getToc();

        $assetPaths = $assetResolver->getAssetPaths($post['category'], $post['tags']);

        if ($force) {
            return $this->redirectToRoute('default_post', ['id' => $id]);
        }<commit_msg>refactor: Clarify the GET request.<commit_after><?php

declare(strict_types=1);

namespace App\Controller;

use App\Esa\HtmlHandler;
use App\Esa\Proxy;
use App\Esa\WebhookValidator;
use App\Service\AccessController;
use App\Service\AssetResolver;
use Polidog\Esa\Exception\ClientException;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Annotation\Route;

#[Route('/', name: 'default_')]
final class DefaultController extends AbstractController
{
    #[Route('/', name: 'index', methods: ['get'])]
    public function index(Request $request): Response
    {
        if ($postId = $request->query->get('post_id')) {
            return $this->redirectToRoute('default_post', ['id' => $postId]);
        }

        return $this->render('default/index.html.twig');
    }

    #[Route('/post/{id}', name: 'post', requirements: ['id' => '\d+'], methods: ['get'])]
    public function post(
        Request $request,
        int $id,
        Proxy $esa,
        AccessController $accessController,
        HtmlHandler $htmlHandler,
        AssetResolver $assetResolver,
        array $htmlReplacements,
    ): Response {
        $force = $request->query->getBoolean('force');

        try {
            $post = $esa->getPost($id, $force);
        } catch (ClientException $e) {
            throw new NotFoundHttpException();
        }

        if (!$accessController->isPublic($post['category'], $post['tags'])) {
            throw new NotFoundHttpException();
        }

        // fix body_html
        $htmlHandler
            ->initialize($post['body_html'])
            ->replacePostUrls('default_post', 'id')
            ->disableMentionLinks()
            ->replaceEmojiCodes()
            ->replaceHtml($htmlReplacements)
            ->dumpHtml()
        ;
        $post['body_html'] = $htmlHandler->dumpHtml();
        $toc = $htmlHandler->getToc();

        $assetPaths = $assetResolver->getAssetPaths($post['category'], $post['tags']);

        if ($force) {
            return $this->redirectToRoute('default_post', ['id' => $id]);
        }
{'fraction_non_alphanumeric': 0.1481723237597911, 'fraction_numerical': 0.0006527415143603133, 'mean_word_length': 2.983535528596187, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '393208', 'n_tokens_mistral': 1297, 'n_tokens_neox': 1288, 'n_words': 248}