Skip to content

Commit

Permalink
update index.php
Browse files Browse the repository at this point in the history
  • Loading branch information
Bosun18 committed Dec 11, 2023
1 parent bb1867d commit 5497752
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,20 @@
$router = $app->getRouteCollector()->getRouteParser();

$app->get('/', function ($request, $response) {
$this->get('pdo')->exec("CREATE TABLE IF NOT EXISTS urls (
id bigint PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
name varchar(255) NOT NULL UNIQUE,
created_at timestamp
);");
$this->get('pdo')->exec("CREATE TABLE IF NOT EXISTS url_checks (
id bigint PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
url_id bigint REFERENCES urls (id),
status_code int,
h1 text,
title text,
description text,
created_at timestamp
);");
return $this->get('renderer')->render($response, 'main.phtml');
})->setName('main');

Expand All @@ -72,7 +86,7 @@
try {
$pdo = $this->get('pdo');

$url = strtolower($urls['url']['name']);
$url = mb_strtolower($urls['url']['name']);
$parsedUrl = parse_url($url);
$name = "{$parsedUrl['scheme']}://{$parsedUrl['host']}";
$createdAt = Carbon::now();
Expand Down Expand Up @@ -145,10 +159,10 @@
$statusCode = $e->getResponse()->getStatusCode();
$this->get('flash')->addMessage('error', 'Ошибка ' .
$statusCode . ' при проверке страницы (внутренняя ошибка сервера)');
return $response->withRedirect($this->get('router')->urlFor('show', ['id' => $urlId]));
return $response->withRedirect($router->urlFor('show', ['id' => $urlId]));
} catch (GuzzleHttp\Exception\GuzzleException) {
$this->get('flash')->addMessage('error', 'Ошибка при проверке страницы (Connection timed out)');
return $response->withRedirect($this->get('router')->urlFor('show', ['id' => $urlId]));
return $response->withRedirect($router->urlFor('show', ['id' => $urlId]));
}
$document = new Document((string) $result->getBody());
$h1 = optional($document->first('h1'))->text();
Expand Down

0 comments on commit 5497752

Please sign in to comment.