feat: initial commit
This commit is contained in:
commit
e214116e40
253 changed files with 17406 additions and 0 deletions
80
src/includes/fetchers/artist.php.liquid
Normal file
80
src/includes/fetchers/artist.php.liquid
Normal file
|
@ -0,0 +1,80 @@
|
|||
<?php
|
||||
require __DIR__ . "/../../vendor/autoload.php";
|
||||
require __DIR__ . "/../../server/utils/init.php";
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
|
||||
$requestUri = $_SERVER["REQUEST_URI"];
|
||||
$url = trim(parse_url($requestUri, PHP_URL_PATH), "/");
|
||||
$postgrestUrl = $_ENV["POSTGREST_URL"] ?? getenv("POSTGREST_URL");
|
||||
$postgrestApiKey = $_ENV["POSTGREST_API_KEY"] ?? getenv("POSTGREST_API_KEY");
|
||||
|
||||
if (strpos($url, "music/artists/") !== 0) {
|
||||
echo file_get_contents(__DIR__ . "/../../404/index.html");
|
||||
exit();
|
||||
}
|
||||
|
||||
$cacheKey = "artist_" . md5($url);
|
||||
$artist = null;
|
||||
$useRedis = false;
|
||||
|
||||
try {
|
||||
if (extension_loaded('redis')) {
|
||||
$redis = new Redis();
|
||||
$redis->connect('127.0.0.1', 6379);
|
||||
$useRedis = true;
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
error_log("Redis not available: " . $e->getMessage());
|
||||
}
|
||||
|
||||
if ($useRedis && $redis->exists($cacheKey)) {
|
||||
$artist = json_decode($redis->get($cacheKey), true);
|
||||
} else {
|
||||
$apiUrl = "$postgrestUrl/optimized_artists?url=eq./" . $url;
|
||||
$client = new Client();
|
||||
|
||||
try {
|
||||
$response = $client->request("GET", $apiUrl, [
|
||||
"headers" => [
|
||||
"Accept" => "application/json",
|
||||
"Authorization" => "Bearer {$postgrestApiKey}",
|
||||
],
|
||||
]);
|
||||
|
||||
$artistData = json_decode($response->getBody(), true);
|
||||
|
||||
if (!$artistData) {
|
||||
echo file_get_contents(__DIR__ . "/../../404/index.html");
|
||||
exit();
|
||||
}
|
||||
|
||||
$artist = $artistData[0];
|
||||
|
||||
if ($useRedis) {
|
||||
$redis->setex($cacheKey, 3600, json_encode($artist));
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
error_log($e->getMessage());
|
||||
echo file_get_contents(__DIR__ . "/../../404/index.html");
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
$artist["description"] = parseMarkdown($artist["description"]);
|
||||
$pageTitle = htmlspecialchars(
|
||||
"Artists • " . $artist["name"],
|
||||
ENT_QUOTES,
|
||||
"UTF-8"
|
||||
);
|
||||
$pageDescription = truncateText(htmlspecialchars(
|
||||
strip_tags($artist["description"]),
|
||||
ENT_QUOTES,
|
||||
"UTF-8"
|
||||
), 250);
|
||||
$ogImage = htmlspecialchars($artist["image"] . "?class=w800", ENT_QUOTES, "UTF-8");
|
||||
$fullUrl = "https://www.coryd.dev" . $requestUri;
|
||||
|
||||
header("Cache-Control: public, max-age=3600");
|
||||
header("Expires: " . gmdate("D, d M Y H:i:s", time() + 3600) . " GMT");
|
||||
?>
|
103
src/includes/fetchers/book.php.liquid
Normal file
103
src/includes/fetchers/book.php.liquid
Normal file
|
@ -0,0 +1,103 @@
|
|||
<?php
|
||||
require __DIR__ . "/../vendor/autoload.php";
|
||||
require __DIR__ . "/../server/utils/init.php";
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
|
||||
$requestUri = $_SERVER["REQUEST_URI"];
|
||||
$url = trim(parse_url($requestUri, PHP_URL_PATH), "/");
|
||||
$postgrestUrl = $_ENV["POSTGREST_URL"] ?? getenv("POSTGREST_URL");
|
||||
$postgrestApiKey = $_ENV["POSTGREST_API_KEY"] ?? getenv("POSTGREST_API_KEY");
|
||||
|
||||
if (preg_match('/^books\/years\/(\d{4})$/', $url, $matches)) {
|
||||
$year = $matches[1];
|
||||
$filePath = __DIR__ . "/years/{$year}.html";
|
||||
|
||||
if (file_exists($filePath)) {
|
||||
echo file_get_contents($filePath);
|
||||
exit();
|
||||
} else {
|
||||
echo file_get_contents(__DIR__ . "/../404/index.html");
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
if ($url === "books/years") {
|
||||
echo file_get_contents(__DIR__ . "/../404/index.html");
|
||||
exit();
|
||||
}
|
||||
|
||||
if ($url === "books") {
|
||||
readfile("index.html");
|
||||
exit();
|
||||
}
|
||||
|
||||
if (!preg_match('/^books\/[\w-]+$/', $url)) {
|
||||
echo file_get_contents(__DIR__ . "/../404/index.html");
|
||||
exit();
|
||||
}
|
||||
|
||||
$cacheKey = "book_" . md5($url);
|
||||
|
||||
$book = null;
|
||||
$useRedis = false;
|
||||
try {
|
||||
if (extension_loaded('redis')) {
|
||||
$redis = new Redis();
|
||||
$redis->connect('127.0.0.1', 6379);
|
||||
$useRedis = true;
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
error_log("Redis not available: " . $e->getMessage());
|
||||
}
|
||||
|
||||
if ($useRedis && $redis->exists($cacheKey)) {
|
||||
$book = json_decode($redis->get($cacheKey), true);
|
||||
} else {
|
||||
$apiUrl = "$postgrestUrl/optimized_books?url=eq./" . $url;
|
||||
$client = new Client();
|
||||
|
||||
try {
|
||||
$response = $client->request("GET", $apiUrl, [
|
||||
"headers" => [
|
||||
"Accept" => "application/json",
|
||||
"Authorization" => "Bearer {$postgrestApiKey}",
|
||||
],
|
||||
]);
|
||||
|
||||
$bookData = json_decode($response->getBody(), true);
|
||||
|
||||
if (!$bookData) {
|
||||
echo file_get_contents(__DIR__ . "/../404/index.html");
|
||||
exit();
|
||||
}
|
||||
|
||||
$book = $bookData[0];
|
||||
|
||||
if ($useRedis) {
|
||||
$redis->setex($cacheKey, 3600, json_encode($book));
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
error_log($e->getMessage());
|
||||
echo file_get_contents(__DIR__ . "/../404/index.html");
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
$book["description"] = parseMarkdown($book["description"]);
|
||||
$pageTitle = htmlspecialchars(
|
||||
"Books • " . $book["title"] . " by " . $book["author"],
|
||||
ENT_QUOTES,
|
||||
"UTF-8"
|
||||
);
|
||||
$pageDescription = truncateText(htmlspecialchars(
|
||||
strip_tags($book["description"]),
|
||||
ENT_QUOTES,
|
||||
"UTF-8"
|
||||
), 250);
|
||||
$ogImage = htmlspecialchars($book["image"] . "?class=w800", ENT_QUOTES, "UTF-8");
|
||||
$fullUrl = "https://www.coryd.dev" . $requestUri;
|
||||
|
||||
header("Cache-Control: public, max-age=3600");
|
||||
header("Expires: " . gmdate("D, d M Y H:i:s", time() + 3600) . " GMT");
|
||||
?>
|
71
src/includes/fetchers/genre.php.liquid
Normal file
71
src/includes/fetchers/genre.php.liquid
Normal file
|
@ -0,0 +1,71 @@
|
|||
<?php
|
||||
require __DIR__ . "/../../vendor/autoload.php";
|
||||
require __DIR__ . "/../../server/utils/init.php";
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
|
||||
$requestUri = $_SERVER["REQUEST_URI"];
|
||||
$url = trim(parse_url($requestUri, PHP_URL_PATH), "/");
|
||||
$postgrestUrl = $_ENV["POSTGREST_URL"] ?? getenv("POSTGREST_URL");
|
||||
$postgrestApiKey = $_ENV["POSTGREST_API_KEY"] ?? getenv("POSTGREST_API_KEY");
|
||||
|
||||
if (!preg_match('/^music\/genres\/[\w-]+$/', $url)) {
|
||||
echo file_get_contents(__DIR__ . "/../../404/index.html");
|
||||
exit();
|
||||
}
|
||||
|
||||
$cacheKey = "genre_" . md5($url);
|
||||
$genre = null;
|
||||
$useRedis = false;
|
||||
|
||||
try {
|
||||
if (extension_loaded('redis')) {
|
||||
$redis = new Redis();
|
||||
$redis->connect('127.0.0.1', 6379);
|
||||
$useRedis = true;
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
error_log("Redis not available: " . $e->getMessage());
|
||||
}
|
||||
|
||||
if ($useRedis && $redis->exists($cacheKey)) {
|
||||
$genre = json_decode($redis->get($cacheKey), true);
|
||||
} else {
|
||||
$apiUrl = "$postgrestUrl/optimized_genres?url=eq./" . $url;
|
||||
$client = new Client();
|
||||
|
||||
try {
|
||||
$response = $client->request("GET", $apiUrl, [
|
||||
"headers" => [
|
||||
"Accept" => "application/json",
|
||||
"Authorization" => "Bearer {$postgrestApiKey}",
|
||||
],
|
||||
]);
|
||||
|
||||
$genreData = json_decode($response->getBody(), true);
|
||||
|
||||
if (!$genreData) {
|
||||
echo file_get_contents(__DIR__ . "/../../404/index.html");
|
||||
exit();
|
||||
}
|
||||
|
||||
$genre = $genreData[0];
|
||||
|
||||
if ($useRedis) {
|
||||
$redis->setex($cacheKey, 3600, json_encode($genre));
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
error_log($e->getMessage());
|
||||
echo file_get_contents(__DIR__ . "/../../404/index.html");
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
$pageTitle = htmlspecialchars("Genres • " . $genre["name"], ENT_QUOTES, "UTF-8");
|
||||
$pageDescription = truncateText(htmlspecialchars(strip_tags($genre["description"]), ENT_QUOTES, "UTF-8"), 250);
|
||||
$ogImage = htmlspecialchars($genre["artists"][0]["image"] . "?class=w800", ENT_QUOTES, "UTF-8");
|
||||
$fullUrl = "https://www.coryd.dev" . $requestUri;
|
||||
|
||||
header("Cache-Control: public, max-age=3600");
|
||||
header("Expires: " . gmdate("D, d M Y H:i:s", time() + 3600) . " GMT");
|
||||
?>
|
80
src/includes/fetchers/movie.php.liquid
Normal file
80
src/includes/fetchers/movie.php.liquid
Normal file
|
@ -0,0 +1,80 @@
|
|||
<?php
|
||||
require __DIR__ . "/../../vendor/autoload.php";
|
||||
require __DIR__ . "/../../server/utils/init.php";
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
|
||||
$requestUri = $_SERVER["REQUEST_URI"];
|
||||
$url = trim(parse_url($requestUri, PHP_URL_PATH), "/");
|
||||
$postgrestUrl = $_ENV["POSTGREST_URL"] ?? getenv("POSTGREST_URL");
|
||||
$postgrestApiKey = $_ENV["POSTGREST_API_KEY"] ?? getenv("POSTGREST_API_KEY");
|
||||
|
||||
if (!preg_match('/^watching\/movies\/[\w-]+$/', $url)) {
|
||||
echo file_get_contents(__DIR__ . "/../../404/index.html");
|
||||
exit();
|
||||
}
|
||||
|
||||
$cacheKey = "movie_" . md5($url);
|
||||
$movie = null;
|
||||
$useRedis = false;
|
||||
|
||||
try {
|
||||
if (extension_loaded('redis')) {
|
||||
$redis = new Redis();
|
||||
$redis->connect('127.0.0.1', 6379);
|
||||
$useRedis = true;
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
error_log("Redis not available: " . $e->getMessage());
|
||||
}
|
||||
|
||||
if ($useRedis && $redis->exists($cacheKey)) {
|
||||
$movie = json_decode($redis->get($cacheKey), true);
|
||||
} else {
|
||||
$apiUrl = "$postgrestUrl/optimized_movies?url=eq./" . $url;
|
||||
$client = new Client();
|
||||
|
||||
try {
|
||||
$response = $client->request("GET", $apiUrl, [
|
||||
"headers" => [
|
||||
"Accept" => "application/json",
|
||||
"Authorization" => "Bearer {$postgrestApiKey}",
|
||||
],
|
||||
]);
|
||||
|
||||
$movieData = json_decode($response->getBody(), true);
|
||||
|
||||
if (!$movieData) {
|
||||
echo file_get_contents(__DIR__ . "/../../404/index.html");
|
||||
exit();
|
||||
}
|
||||
|
||||
$movie = $movieData[0];
|
||||
|
||||
if ($useRedis) {
|
||||
$redis->setex($cacheKey, 3600, json_encode($movie));
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
error_log($e->getMessage());
|
||||
echo file_get_contents(__DIR__ . "/../../404/index.html");
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
$movie["description"] = parseMarkdown($movie["description"]);
|
||||
$pageTitle = htmlspecialchars(
|
||||
"Movies • " . $movie["title"],
|
||||
ENT_QUOTES,
|
||||
"UTF-8"
|
||||
);
|
||||
$pageDescription = truncateText(htmlspecialchars(
|
||||
strip_tags($movie["description"]),
|
||||
ENT_QUOTES,
|
||||
"UTF-8"
|
||||
), 250);
|
||||
$ogImage = htmlspecialchars($movie["backdrop"] . "?class=w800", ENT_QUOTES, "UTF-8");
|
||||
$fullUrl = "https://www.coryd.dev" . $requestUri;
|
||||
|
||||
header("Cache-Control: public, max-age=3600");
|
||||
header("Expires: " . gmdate("D, d M Y H:i:s", time() + 3600) . " GMT");
|
||||
?>
|
71
src/includes/fetchers/show.php.liquid
Normal file
71
src/includes/fetchers/show.php.liquid
Normal file
|
@ -0,0 +1,71 @@
|
|||
<?php
|
||||
require __DIR__ . "/../../vendor/autoload.php";
|
||||
require __DIR__ . "/../../server/utils/init.php";
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
|
||||
$requestUri = $_SERVER["REQUEST_URI"];
|
||||
$url = trim(parse_url($requestUri, PHP_URL_PATH), "/");
|
||||
$postgrestUrl = $_ENV["POSTGREST_URL"] ?? getenv("POSTGREST_URL");
|
||||
$postgrestApiKey = $_ENV["POSTGREST_API_KEY"] ?? getenv("POSTGREST_API_KEY");
|
||||
|
||||
if (!preg_match('/^watching\/shows\/[\w-]+$/', $url)) {
|
||||
echo file_get_contents(__DIR__ . "/../../404/index.html");
|
||||
exit();
|
||||
}
|
||||
|
||||
$cacheKey = "show_" . md5($url);
|
||||
$show = null;
|
||||
$useRedis = false;
|
||||
|
||||
try {
|
||||
if (extension_loaded('redis')) {
|
||||
$redis = new Redis();
|
||||
$redis->connect('127.0.0.1', 6379);
|
||||
$useRedis = true;
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
error_log("Redis not available: " . $e->getMessage());
|
||||
}
|
||||
|
||||
if ($useRedis && $redis->exists($cacheKey)) {
|
||||
$show = json_decode($redis->get($cacheKey), true);
|
||||
} else {
|
||||
$apiUrl = "$postgrestUrl/optimized_shows?url=eq./" . $url;
|
||||
$client = new Client();
|
||||
|
||||
try {
|
||||
$response = $client->request("GET", $apiUrl, [
|
||||
"headers" => [
|
||||
"Accept" => "application/json",
|
||||
"Authorization" => "Bearer {$postgrestApiKey}",
|
||||
],
|
||||
]);
|
||||
|
||||
$showData = json_decode($response->getBody(), true);
|
||||
|
||||
if (!$showData) {
|
||||
echo file_get_contents(__DIR__ . "/../../404/index.html");
|
||||
exit();
|
||||
}
|
||||
|
||||
$show = $showData[0];
|
||||
|
||||
if ($useRedis) {
|
||||
$redis->setex($cacheKey, 3600, json_encode($show));
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
error_log($e->getMessage());
|
||||
echo file_get_contents(__DIR__ . "/../../404/index.html");
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
$pageTitle = htmlspecialchars("Show • " . $show["title"], ENT_QUOTES, "UTF-8");
|
||||
$pageDescription = truncateText(htmlspecialchars(strip_tags($show["description"]), ENT_QUOTES, "UTF-8"), 250);
|
||||
$ogImage = htmlspecialchars($show["image"] . "?class=w800", ENT_QUOTES, "UTF-8");
|
||||
$fullUrl = "https://www.coryd.dev" . $requestUri;
|
||||
|
||||
header("Cache-Control: public, max-age=3600");
|
||||
header("Expires: " . gmdate("D, d M Y H:i:s", time() + 3600) . " GMT");
|
||||
?>
|
Loading…
Add table
Add a link
Reference in a new issue