From 627c28bd4d665d03ea82dc36617670b0886910f5 Mon Sep 17 00:00:00 2001 From: flashwave Date: Wed, 22 May 2024 20:51:44 +0000 Subject: [PATCH] Added Satori redirects table and read endpoint. --- ...24_05_22_204323_add_satori_redirs_table.php | 16 ++++++++++++++++ src/RedirectorRoutes.php | 18 ++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 database/2024_05_22_204323_add_satori_redirs_table.php diff --git a/database/2024_05_22_204323_add_satori_redirs_table.php b/database/2024_05_22_204323_add_satori_redirs_table.php new file mode 100644 index 0000000..535cc8b --- /dev/null +++ b/database/2024_05_22_204323_add_satori_redirs_table.php @@ -0,0 +1,16 @@ +execute(' + CREATE TABLE awk_satori_redirects ( + redir_id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + redir_url VARCHAR(255) NOT NULL, + redir_created TIMESTAMP NOT NULL DEFAULT current_timestamp(), + PRIMARY KEY (redir_id) + ) ENGINE=InnoDB COLLATE=utf8mb4_bin; + '); + } +} diff --git a/src/RedirectorRoutes.php b/src/RedirectorRoutes.php index fc20125..586f416 100644 --- a/src/RedirectorRoutes.php +++ b/src/RedirectorRoutes.php @@ -3,6 +3,7 @@ namespace Awaki; use Index\Data\IDbConnection; use Index\Http\Routing\IRouter; +use Index\Serialisation\Base62; use Syokuhou\IConfig; final class RedirectorRoutes { @@ -19,6 +20,9 @@ final class RedirectorRoutes { $router->get('/[up]([0-9]+)', $this->redirectProfile(...)); $router->get('/[up]/([A-Za-z0-9\-_]+)', $this->redirectProfile(...)); + // satori short urls + $router->get('/[bg]/([A-Za-z0-9]+)', $this->redirectSatoriShort(...)); + // forum categories $router->get('/fc?/?([0-9]+)', $this->redirectForumCategory(...)); @@ -62,6 +66,20 @@ final class RedirectorRoutes { $this->redirect($response, $request, $info->getString(1)); } + public function redirectSatoriShort($response, $request, string $linkId) { + $linkId = Base62::decode($linkId); + + $getInfo = $this->dbConn->prepare('SELECT redir_url FROM awk_satori_redirects WHERE redir_id = ?'); + $getInfo->addParameter(1, $linkId); + $getInfo->execute(); + $info = $getInfo->getResult(); + + if(!$info->next()) + return 404; + + $this->redirect($response, $request, $info->getString(0)); + } + private function redirectSimple($response, $request, string $format, string $argument) { $scheme = empty($_SERVER['HTTPS']) ? 'http' : 'https'; $argument = rawurlencode($argument);