proxitok/routes/index.php

109 lines
2.8 KiB
PHP
Raw Normal View History

<?php
require __DIR__ . '/assets.php';
require __DIR__ . '/settings.php';
require __DIR__ . '/following.php';
use Steampixel\Route;
use Helpers\Misc;
use Helpers\Error;
Route::add('/', function () {
$latte = Misc::latte();
2022-01-25 13:08:31 +00:00
$latte->render(Misc::getView('home'), ['title' => 'Home']);
});
2022-01-08 15:03:57 +00:00
Route::add('/about', function () {
$latte = Misc::latte();
2022-01-25 13:08:31 +00:00
$latte->render(Misc::getView('about'), ['title' => 'About']);
2022-01-08 15:03:57 +00:00
});
Route::add("/trending", function () {
$cursor = 0;
if (isset($_GET['cursor']) && is_numeric($_GET['cursor'])) {
$cursor = (int) $_GET['cursor'];
}
$api = Misc::api();
$feed = $api->getTrendingFeed($cursor);
2022-01-13 15:51:45 +00:00
if ($feed->meta->success) {
$latte = Misc::latte();
2022-01-25 13:08:31 +00:00
$latte->render(Misc::getView('trending'), [
'feed' => $feed,
'title' => 'Trending'
]);
} else {
2022-01-13 15:51:45 +00:00
Error::show($feed->meta);
}
});
Route::add("/@([^/]+)", function (string $username) {
$cursor = 0;
if (isset($_GET['cursor']) && is_numeric($_GET['cursor'])) {
$cursor = (int) $_GET['cursor'];
}
$api = Misc::api();
$feed = $api->getUserFeed($username, $cursor);
2022-01-13 15:51:45 +00:00
if ($feed->meta->success) {
if ($feed->info->detail->user->privateAccount) {
http_response_code(400);
return 'Private account detected! Not supported';
}
$latte = Misc::latte();
2022-01-25 13:08:31 +00:00
$latte->render(Misc::getView('user'), [
'feed' => $feed,
'title' => $feed->info->detail->user->nickname
]);
} else {
2022-01-13 15:51:45 +00:00
Error::show($feed->meta);
}
});
Route::add('/video/([^/]+)', function (string $video_id) {
2022-01-08 15:03:57 +00:00
$api = Misc::api();
$item = $api->getVideoByID($video_id);
2022-01-13 15:51:45 +00:00
if ($item->meta->success) {
$latte = Misc::latte();
2022-01-25 13:08:31 +00:00
$latte->render(Misc::getView('video'), [
'item' => $item,
'title' => $item->info->detail->user->nickname
]);
2022-01-08 15:03:57 +00:00
} else {
2022-01-13 15:51:45 +00:00
Error::show($item->meta);
2022-01-08 15:03:57 +00:00
}
});
2022-01-17 20:11:40 +00:00
Route::add('/music/([^/]+)', function (string $music_id) {
$cursor = 0;
if (isset($_GET['cursor']) && is_numeric($_GET['cursor'])) {
$cursor = (int) $_GET['cursor'];
}
$api = Misc::api();
$feed = $api->getMusicFeed($music_id, $cursor);
if ($feed->meta->success) {
$latte = Misc::latte();
2022-01-25 13:08:31 +00:00
$latte->render(Misc::getView('music'), [
'feed' => $feed,
'title' => 'Music'
]);
2022-01-17 20:11:40 +00:00
} else {
Error::show($feed->meta);
}
});
Route::add('/tag/(\w+)', function (string $name) {
$cursor = 0;
if (isset($_GET['cursor']) && is_numeric($_GET['cursor'])) {
$cursor = (int) $_GET['cursor'];
}
$api = Misc::api();
$feed = $api->getChallengeFeed($name, $cursor);
2022-01-13 15:51:45 +00:00
if ($feed->meta->success) {
$latte = Misc::latte();
2022-01-25 13:08:31 +00:00
$latte->render(Misc::getView('tag'), [
'feed' => $feed,
'title' => 'Tag'
]);
} else {
2022-01-13 15:51:45 +00:00
Error::show($feed->meta);
}
});