Fix new snip error with git repo
Allow simple raw rendering (in html)
This commit is contained in:
parent
842c936d8c
commit
607435bff0
@ -39,21 +39,44 @@ class SnipController extends AbstractController
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/raw/{snip}', name: '_raw')]
|
||||
public function raw(Snip $snip, Request $request): Response
|
||||
{
|
||||
$response = new Response(
|
||||
$this->snipServiceFactory->create($snip)->get(),
|
||||
Response::HTTP_OK,
|
||||
['Content-Type' => 'text/html']
|
||||
);
|
||||
$response
|
||||
->setVary(['Accept', 'Accept-Encoding'])
|
||||
->setEtag(md5($response->getContent()))
|
||||
->setTtl(3600)
|
||||
->setClientTtl(300);
|
||||
|
||||
if (!$request->isNoCache()) {
|
||||
$response->isNotModified($request);
|
||||
}
|
||||
|
||||
return $response;
|
||||
// return $this->render('snip/single.html.twig', [
|
||||
// 'snip' => $snip,
|
||||
// 'content' => $this->snipServiceFactory->create($snip)->get(),
|
||||
// ]);
|
||||
}
|
||||
|
||||
#[Route('/edit/{snip}', name: '_edit')]
|
||||
public function edit(Snip $snip, Request $request): Response
|
||||
{
|
||||
$snipService = $this->snipServiceFactory->create($snip);
|
||||
|
||||
$form = $this->createForm(SnipType::class, $snip);
|
||||
$form->get('content')->setData($snipService->get());
|
||||
$form->add('Save', SubmitType::class);
|
||||
if ($snip->getId()) {
|
||||
$form->get('content')->setData($this->snipServiceFactory->create($snip)->get());
|
||||
}
|
||||
|
||||
$form->handleRequest($request);
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$snip->setCreatedAtTodayNoSeconds()
|
||||
->setCreatedBy($this->getUser());
|
||||
$this->repository->save($snip);
|
||||
$snipService->update($form->get('content')->getData());
|
||||
$this->snipServiceFactory->create($snip)->update($form->get('content')->getData());
|
||||
|
||||
$this->addFlash('success', sprintf('Snip "%s" saved successfully', $snip));
|
||||
|
||||
@ -72,6 +95,8 @@ class SnipController extends AbstractController
|
||||
public function new(Request $request): Response
|
||||
{
|
||||
$snip = new Snip();
|
||||
$snip->setCreatedAtTodayNoSeconds()
|
||||
->setCreatedBy($this->getUser());
|
||||
|
||||
return $this->edit($snip, $request);
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ class SnipService
|
||||
{
|
||||
$git = new Git();
|
||||
$repoPath = sprintf('%s/%s', $snipBasePath, $snip->getId());
|
||||
dump($repoPath, $snip);
|
||||
if (!is_dir($repoPath)) {
|
||||
$this->repo = $git->init($repoPath);
|
||||
} else {
|
||||
@ -38,6 +39,7 @@ class SnipService
|
||||
|
||||
public function update(string $snipContents): void
|
||||
{
|
||||
dump($this->getSnipPath());
|
||||
file_put_contents($this->getSnipPath(), $snipContents);
|
||||
$this->repo->addFile('snip.txt');
|
||||
if ($this->repo->hasChanges()) {
|
||||
|
Loading…
Reference in New Issue
Block a user