|
@@ -59,6 +59,33 @@ class VideoController implements IRouteController
|
|
|
|
|
|
public static function getInfo(string $id): string
|
|
|
{
|
|
|
+ $signed_in = signed_in(request());
|
|
|
+ if(!$signed_in) {
|
|
|
+ $data = [];
|
|
|
+ $titles = explode(",", Hajeebtok::$Config->GetByDotKey("Service.FakeTitles"));
|
|
|
+ $descriptions = explode(",", Hajeebtok::$Config->GetByDotKey("Service.FakeDescriptions"));
|
|
|
+ $usernames = explode(",", Hajeebtok::$Config->GetByDotKey("Service.FakeUsernames"));
|
|
|
+ for($i = 0; $i < rand(1, 13); $i++) {
|
|
|
+ $data[] = [
|
|
|
+ "id" => rand(0, 203222),
|
|
|
+ "title" => $titles[rand(0, count($titles) - 1)],
|
|
|
+ "description" => $descriptions[rand(0, count($descriptions) - 1)],
|
|
|
+ "likes" => rand(0, 48573),
|
|
|
+ "dislikes" => rand(0, 202),
|
|
|
+ "comments" => rand(0, 2029),
|
|
|
+ "shares" => rand(15, 2321),
|
|
|
+ "author" => [
|
|
|
+ "id" => rand(2, 2020),
|
|
|
+ "username" => $usernames[rand(0, count($usernames) - 1)],
|
|
|
+ "verified" => rand(1, 10) > 8
|
|
|
+ ],
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ CORSHelper();
|
|
|
+ return api_json($data);
|
|
|
+ }
|
|
|
+
|
|
|
$video_information = new Video($id);
|
|
|
$video_information->Load();
|
|
|
$author_information = new Account($video_information->author_id);
|
|
@@ -75,7 +102,7 @@ class VideoController implements IRouteController
|
|
|
"shares" => $video_information->shares,
|
|
|
"author" => [
|
|
|
"id" => $author_information->id,
|
|
|
- "pictureHash" => $author_information->picture_hash,
|
|
|
+ "verified" => $author_information->verified,
|
|
|
"username" => $author_information->username
|
|
|
],
|
|
|
]);
|
|
@@ -83,16 +110,42 @@ class VideoController implements IRouteController
|
|
|
|
|
|
public static function search(): string
|
|
|
{
|
|
|
+ $signed_in = signed_in(request());
|
|
|
+ if(!$signed_in) {
|
|
|
+ $data = [];
|
|
|
+ $titles = explode(",", Hajeebtok::$Config->GetByDotKey("Service.FakeTitles"));
|
|
|
+ $descriptions = explode(",", Hajeebtok::$Config->GetByDotKey("Service.FakeDescriptions"));
|
|
|
+ $usernames = explode(",", Hajeebtok::$Config->GetByDotKey("Service.FakeUsernames"));
|
|
|
+ for($i = 0; $i < rand(1, 13); $i++) {
|
|
|
+ $data[] = [
|
|
|
+ "id" => rand(0, 203222),
|
|
|
+ "title" => $titles[rand(0, count($titles) - 1)],
|
|
|
+ "description" => $descriptions[rand(0, count($descriptions) - 1)],
|
|
|
+ "likes" => rand(0, 48573),
|
|
|
+ "dislikes" => rand(0, 202),
|
|
|
+ "comments" => rand(0, 2029),
|
|
|
+ "shares" => rand(15, 2321),
|
|
|
+ "author" => [
|
|
|
+ "id" => rand(2, 2020),
|
|
|
+ "username" => $usernames[rand(0, count($usernames) - 1)],
|
|
|
+ "verified" => rand(1, 10) > 8
|
|
|
+ ],
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ CORSHelper();
|
|
|
+ return api_json($data);
|
|
|
+ }
|
|
|
+
|
|
|
$query = input("query");
|
|
|
$video = new Video(title: $query);
|
|
|
$videos = $video->LoadMany();
|
|
|
|
|
|
- // idk if this is the greatest thing to do but jetbrains phpfart ai recommended it and it looks fine to me /shurg
|
|
|
- $accounts = Hajeebtok::$Database->Query("SELECT * FROM accounts WHERE id IN (SELECT author_id FROM videos WHERE title LIKE :title)", ["title" => "%$query%"]);
|
|
|
- if (empty($accounts)) throw new AccountNotFoundException(0, 404);
|
|
|
-
|
|
|
$data = [];
|
|
|
foreach ($videos as $vid) {
|
|
|
+ $account = new Account(id: $vid["author_id"]);
|
|
|
+ $account->Load();
|
|
|
+
|
|
|
$data[] = [
|
|
|
"id" => $vid["id"],
|
|
|
"title" => $vid["title"],
|
|
@@ -102,9 +155,9 @@ class VideoController implements IRouteController
|
|
|
"comments" => Hajeebtok::$Database->Single("SELECT COUNT(*) FROM comments WHERE video_id = :id", ["id" => $vid["id"]]),
|
|
|
"shares" => Hajeebtok::$Database->Single("SELECT COUNT(*) FROM messages INNER JOIN videos ON messages.video_id = videos.id WHERE videos.id = :id", ["id" => $vid["id"]]),
|
|
|
"author" => [
|
|
|
- "id" => $vid["author_id"],
|
|
|
- "pictureHash" => $accounts[$vid["author_id"] - 1]["picture_hash"], // kinda scuffed fix
|
|
|
- "username" => $accounts[$vid["author_id"] - 1]["username"]
|
|
|
+ "id" => $account->id,
|
|
|
+ "verified" => $account->verified,
|
|
|
+ "username" => $account->username
|
|
|
],
|
|
|
];
|
|
|
}
|
|
@@ -166,7 +219,7 @@ class VideoController implements IRouteController
|
|
|
|
|
|
for($i = 0; $i < $limit; $i++) {
|
|
|
$feed[] = [
|
|
|
- "id" => rand(1, 10),
|
|
|
+ "id" => rand(1, 10000),
|
|
|
"title" => $titles[rand(0, count($titles) - 1)],
|
|
|
"description" => $descriptions[rand(0, count($descriptions) - 1)],
|
|
|
"likes" => rand(20000, 37020),
|
|
@@ -175,7 +228,7 @@ class VideoController implements IRouteController
|
|
|
"shares" => rand(2, 200000),
|
|
|
"author" => [
|
|
|
"id" => rand(2, 59),
|
|
|
- "pictureHash" => null,
|
|
|
+ "verified" => rand(1, 10) > 8,
|
|
|
"username" => $usernames[rand(0, count($usernames) - 1)],
|
|
|
],
|
|
|
];
|
|
@@ -209,7 +262,7 @@ class VideoController implements IRouteController
|
|
|
"shares" => Hajeebtok::$Database->Single("SELECT COUNT(*) FROM messages INNER JOIN videos ON messages.video_id = videos.id WHERE videos.id = :id", ["id" => $video["id"]]),
|
|
|
"author" => [
|
|
|
"id" => $video["author_id"],
|
|
|
- "pictureHash" => $account->picture_hash,
|
|
|
+ "verified" => $account->verified,
|
|
|
"username" => $account->username,
|
|
|
],
|
|
|
];
|
|
@@ -267,6 +320,73 @@ class VideoController implements IRouteController
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
+ public static function getExplore() {
|
|
|
+ $video_num = intval(input("video") ?? "0");
|
|
|
+ $offset = intval(input("offset") ?? "0");
|
|
|
+ $limit = intval(Hajeebtok::$Config->GetByDotKey("Service.VideoFeedLimit"));
|
|
|
+
|
|
|
+ $signed_in = signed_in(request());
|
|
|
+ if (!$signed_in) {
|
|
|
+ $feed = [];
|
|
|
+ for($i = 0; $i < $limit; $i++) {
|
|
|
+ $titles = explode(",", Hajeebtok::$Config->GetByDotKey("Service.FakeTitles"));
|
|
|
+ $descriptions = explode(",", Hajeebtok::$Config->GetByDotKey("Service.FakeDescriptions"));
|
|
|
+ $usernames = explode(",", Hajeebtok::$Config->GetByDotKey("Service.FakeUsernames"));
|
|
|
+
|
|
|
+ $feed[] = [
|
|
|
+ "id" => rand(1, 100000),
|
|
|
+ "title" => $titles[rand(0, count($titles) - 1)],
|
|
|
+ "description" => $descriptions[rand(0, count($descriptions) - 1)],
|
|
|
+ "likes" => rand(20000, 37020),
|
|
|
+ "dislikes" => rand(2, 12343),
|
|
|
+ "comments" => rand(2, 1029),
|
|
|
+ "shares" => rand(2, 200000),
|
|
|
+ "author" => [
|
|
|
+ "id" => rand(2, 59),
|
|
|
+ "verified" => rand(1, 10) > 8,
|
|
|
+ "username" => $usernames[rand(0, count($usernames) - 1)],
|
|
|
+ ],
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ CORSHelper();
|
|
|
+ return api_json($feed);
|
|
|
+ }
|
|
|
+ $id = get_token_id(request());
|
|
|
+
|
|
|
+ $videos = Hajeebtok::$Database->Query("SELECT * FROM videos ORDER BY RAND() LIMIT :limit OFFSET :offset", ["offset" => $offset, "limit" => $limit]);
|
|
|
+
|
|
|
+ $feed = [];
|
|
|
+ $valid_video = false;
|
|
|
+ foreach ($videos as $video) {
|
|
|
+ if ($video_num === 0) $valid_video = true;
|
|
|
+ if ($video["id"] == $video_num) $valid_video = true;
|
|
|
+ Logger::Debug($video["id"] . " -> " . $video["title"]);
|
|
|
+ if (!$valid_video) continue;
|
|
|
+
|
|
|
+ $account = new Account($video["author_id"]);
|
|
|
+ $account->Load();
|
|
|
+
|
|
|
+ $feed[] = [
|
|
|
+ "id" => $video["id"],
|
|
|
+ "title" => $video["title"],
|
|
|
+ "description" => $video["description"],
|
|
|
+ "likes" => $video["likes"],
|
|
|
+ "dislikes" => $video["dislikes"],
|
|
|
+ "comments" => Hajeebtok::$Database->Single("SELECT COUNT(*) FROM comments WHERE video_id = :id", ["id" => $video["id"]]),
|
|
|
+ "shares" => Hajeebtok::$Database->Single("SELECT COUNT(*) FROM messages INNER JOIN videos ON messages.video_id = videos.id WHERE videos.id = :id", ["id" => $video["id"]]),
|
|
|
+ "author" => [
|
|
|
+ "id" => $video["author_id"],
|
|
|
+ "verified" => $account->verified,
|
|
|
+ "username" => $account->username,
|
|
|
+ ],
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ CORSHelper();
|
|
|
+ return api_json($feed);
|
|
|
+ }
|
|
|
+
|
|
|
public static function RegisterRoutes(): void
|
|
|
{
|
|
|
SimpleRouter::group([
|
|
@@ -275,15 +395,17 @@ class VideoController implements IRouteController
|
|
|
SimpleRouter::get("/{id}/get", [VideoController::class, "getVideo"]);
|
|
|
SimpleRouter::get("/{id}/info", [VideoController::class, "getInfo"]);
|
|
|
SimpleRouter::get("/{id}/thumbnail", [VideoController::class, "getThumbnail"]);
|
|
|
+ SimpleRouter::get("/feed", [VideoController::class, "getFeed"]);
|
|
|
+ SimpleRouter::get("/explore", [VideoController::class, "getExplore"]);
|
|
|
SimpleRouter::post("/upload", [VideoController::class, "uploadVideo"]);
|
|
|
SimpleRouter::post("/search", [VideoController::class, "search"]);
|
|
|
- SimpleRouter::get("/feed", [VideoController::class, "getFeed"]);
|
|
|
SimpleRouter::options("/{id}/get", "CORSHelper");
|
|
|
SimpleRouter::options("/{id}/info", "CORSHelper");
|
|
|
SimpleRouter::options("/{id}/thumbnail", "CORSHelper");
|
|
|
SimpleRouter::options("/upload", "CORSHelper");
|
|
|
SimpleRouter::options("/search", "CORSHelper");
|
|
|
SimpleRouter::options("/feed", "CORSHelper");
|
|
|
+ SimpleRouter::options("/explore", "CORSHelper");
|
|
|
});
|
|
|
}
|
|
|
}
|