Properly implemented OG

This commit is contained in:
Pablo Ferreiro 2022-11-26 23:51:45 +01:00
parent ee6e8b0593
commit 215f984fe4
No known key found for this signature in database
GPG key ID: 41FBCE65B779FA24
16 changed files with 87 additions and 50 deletions

View file

@ -11,8 +11,9 @@ class EmbedController {
$video = $api->video($id);
$video->feed();
if ($video->ok()) {
$data = $video->getFull();
Wrappers::latte('video', new VideoTemplate($data->feed->items[0], $data->info->detail, true));
$item = $video->getFeed()->items[0];
$info = $video->getInfo();
Wrappers::latte('video', new VideoTemplate($item, $info, true));
} else {
ErrorHandler::showMeta($video->error());
}

View file

@ -14,8 +14,9 @@ class MusicController {
$music = $api->music($music_id);
$music->feed($cursor);
if ($music->ok()) {
$data = $music->getFull();
Wrappers::latte('music', new FullTemplate('Music', $data));
$info = $music->getInfo();
$feed = $music->getFeed();
Wrappers::latte('music', new FullTemplate('Music', $info, $feed));
} else {
ErrorHandler::showMeta($music->error());
}

View file

@ -2,7 +2,6 @@
namespace App\Controllers;
use App\Helpers\Cookies;
use TikScraper\Helpers\Converter;
class ProxyController {
const VALID_TIKTOK_DOMAINS = [

View file

@ -15,8 +15,9 @@ class TagController {
$hashtag = $api->hashtag($name);
$hashtag->feed($cursor);
if ($hashtag->ok()) {
$data = $hashtag->getFull();
Wrappers::latte('tag', new FullTemplate($data->info->detail->title, $data));
$info = $hashtag->getInfo();
$feed = $hashtag->getFeed();
Wrappers::latte('tag', new FullTemplate($info->detail->title, $info, $feed));
} else {
ErrorHandler::showMeta($hashtag->error());
}

View file

@ -16,12 +16,13 @@ class UserController {
$user = $api->user($username);
$user->feed($cursor);
if ($user->ok()) {
$data = $user->getFull();
if ($data->info->detail->privateAccount) {
$info = $user->getInfo();
$feed = $user->getFeed();
if ($info->detail->privateAccount) {
ErrorHandler::showText(401, "Private account detected! Not supported");
return;
}
Wrappers::latte('user', new FullTemplate($data->info->detail->nickname, $data));
Wrappers::latte('user', new FullTemplate($info->detail->nickname, $info, $feed));
} else {
ErrorHandler::showMeta($user->error());
}
@ -32,8 +33,9 @@ class UserController {
$video = $api->video($video_id);
$video->feed();
if ($video->ok()) {
$data = $video->getFull();
Wrappers::latte('video', new VideoTemplate($data->feed->items[0], $data->info->detail));
$item = $video->getFeed()->items[0];
$info = $video->getInfo();
Wrappers::latte('video', new VideoTemplate($item, $info));
} else {
ErrorHandler::showMeta($video->error());
}

View file

@ -1,16 +1,19 @@
<?php
namespace App\Models;
use TikScraper\Models\Full;
use TikScraper\Models\Feed;
use TikScraper\Models\Info;
/**
* Base for templates with both info and feed
*/
class FullTemplate extends BaseTemplate {
public Full $data;
public Info $info;
public Feed $feed;
function __construct(string $title, Full $data) {
function __construct(string $title, Info $info, Feed $feed) {
parent::__construct($title);
$this->data = $data;
$this->info = $info;
$this->feed = $feed;
}
}

View file

@ -1,18 +1,20 @@
<?php
namespace App\Models;
use TikScraper\Models\Info;
/**
* Base for templates with a feed
*/
class VideoTemplate extends BaseTemplate {
public object $item;
public object $detail;
public Info $info;
public string $layout = 'hero';
function __construct(object $item, object $detail, bool $isEmbed = false) {
function __construct(object $item, Info $info, bool $isEmbed = false) {
parent::__construct('Video');
$this->item = $item;
$this->detail = $detail;
$this->info = $info;
if ($isEmbed) {
$this->layout = 'embed';
} else {