Load(); $mimeTypes = new MimeTypes(); if($signedIn) { // Signed in $videoPath = APP_ROOT . "/usercontent/videos/$id/video.mp4"; } else { // not signed in $videoPath = APP_ROOT . "/usercontent/videos/1/video.mp4"; } if (file_exists($videoPath)) { $videoContents = file_get_contents($videoPath); $videoSize = filesize($videoPath); $mime = $mimeTypes->getMimeType(pathinfo($videoPath, PATHINFO_EXTENSION)); $response = response(); $response->header("Content-Type: $mime"); $response->header("Content-Length: $videoSize"); $response->header("Cache-Control: max-age=86400, public"); return $videoContents; } else { throw new VideoNotFoundException($id, 404); } } public static function getInfo(string $id): string { $videoInformation = new Video($id); $videoInformation->Load(); $authorInformation = new Account($videoInformation->author_id); $authorInformation->Load(); return api_json([ "title" => $videoInformation->title, "description" => $videoInformation->description, "likes" => $videoInformation->likes, "dislikes" => $videoInformation->dislikes, "comments" => $videoInformation->comments, "shares" => $videoInformation->shares, "author" => [ "id" => $authorInformation->id, "pictureHash" => $authorInformation->picture_hash, "username" => $authorInformation->username ], ]); } public static function search(): string { $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) { $data[] = [ "title" => $vid["title"], "description" => $vid["description"], "likes" => $vid["likes"], "dislikes" => $vid["dislikes"], "comments" => $vid["comments"], "shares" => $vid["shares"], "author" => [ "id" => $vid["author_id"], "pictureHash" => $accounts[$vid["author_id"] - 1]["picture_hash"], // kinda scuffed fix "username" => $accounts[$vid["author_id"] - 1]["username"] ], ]; } return api_json($data); } public static function RegisterRoutes(): void { SimpleRouter::group([ "prefix" => "/video", ], function () { SimpleRouter::get("/{id}", [VideoController::class, "getVideo"]); //SimpleRouter::post("/upload", [VideoController::class, "uploadVideo"]); SimpleRouter::get("/{id}/info", [VideoController::class, "getInfo"]); SimpleRouter::post("/search", [VideoController::class, "search"]); }); } }