Edit File: VideoCreate.php
<?php namespace App\Livewire\Admin\Video; use App\Models\Anime; use App\Models\Video; use App\Models\History; use Livewire\Component; use Livewire\WithFileUploads; use Livewire\Attributes\Layout; use Livewire\Attributes\Validate; use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Session; class VideoCreate extends Component { use WithFileUploads; public $anime_id; #[Validate('string|required|max:100')] public $anime_name; #[Validate('required|mimes:mp4')] public $video_file; #[Validate('image|required|max:1024')] public $thumbnail; #[Validate('numeric|required')] public int $order; public $max_order; public $progress = 0; public function mount($id) { $this->anime_id = $id; // $this->max_order = Anime::whereHas("videos", function ($q) { // $q->where("anime_id", $this->anime_id); // })->count() + 1; $this->max_order = Video::where("anime_id", $id)->count() + 1; $this->order = $this->max_order; $anime = Anime::find($id); $this->anime_name = $anime->name; } public function store() { dd($this->video_file); try { Log::info('Mulai proses upload'); $this->validate(); Log::info('Validasi sukses'); Log::info('File berhasil disimpan'); } catch (\Exception $e) { Log::error('Error upload: ' . $e->getMessage()); session()->flash('error', $e->getMessage()); } $anime = Anime::find($this->anime_id); $sanitized_anime_name = $anime->name; $sanitized_anime_name = str_replace("?", "", $sanitized_anime_name); $sanitized_anime_name = str_replace(":", "-", $sanitized_anime_name); $video = new Video(); $video->name = $anime->name . " episode " . $this->order . " subtitle indonesia"; $video->anime_id = $this->anime_id; if ($this->order != $this->max_order) { $check = Video::where("anime_id", $this->anime_id)->where("order", $this->order)->first(); if ($check) { $get_all_video_with_higher_order = Video::where("anime_id", $this->anime_id)->where('order', ">=", $this->order)->get(); foreach ($get_all_video_with_higher_order as $high) { $high->order = $high->order + 1; $high->name = $anime->name . " episode " . $high->order; $high->save(); } } $video->order = $this->order; } else { $video->order = $this->order; } $extension = $this->thumbnail->getClientOriginalExtension(); $newname = $sanitized_anime_name . "-episode-" . $this->order . ".$extension"; $this->thumbnail->storeAs("anime/$sanitized_anime_name", $newname); $thumbnail_path = "/storage/anime/$sanitized_anime_name/$newname"; $video->thumbnail = $thumbnail_path; $extension = $this->video_file->getClientOriginalExtension(); $newname = $sanitized_anime_name . "-episode-" . $this->order . ".$extension"; $this->video_file->storeAs("anime/$sanitized_anime_name", $newname); $video_path = "/storage/anime/$sanitized_anime_name/$newname"; $video->video = $video_path; $video->save(); $video->load("anime"); $this->progress = 100; Session::flash('status', 'success'); Session::flash('message', 'Berhasil Menambah Episode Baru'); History::create([ 'name' => Auth::user()->name, 'page' => 'Video', 'title' => Auth::user()->name . ' Menambahkan Anime ' . $video->name . " Episode Baru", 'status' => 'success', ]); $bot_token = "7736992119:AAEoC6wLHNHQ1ad7zsS0ocFCEG9UcmgjsxU"; $chat_id = "-1002375031126"; $message_thread_id = 76; $message = "š„š„ Update !!\n\nš¬ Judul : $video->name\n\nš Kini telah diupload di website Gudang Anime Movie, ayo tonton sekarang juga disini š\n\nš : https://gudanganimemovie.com/anime/$anime->slug/episode/$video->order"; // $message = "š¬ $video->name !!\n\nCek juga anime favorit mu disini š š : https://gudanganimemovie.com/"; // $send_url = "https://api.telegram.org/bot{$bot_token}/sendVideo"; $send_url = "https://api.telegram.org/bot{$bot_token}/sendMessage"; // $start = microtime(true); // $response = Http::attach( // 'video', // file_get_contents(storage_path(path: 'app/public/' . "anime/$sanitized_anime_name/$newname")), // pastikan path sesuai // "$video->name.mp4" // )->post($send_url, [ // 'chat_id' => $chat_id, // 'caption' => $message, // 'supports_streaming' => true, // ]); if($video->anime->is_film) { $response = Http::asForm()->post($send_url, [ 'chat_id' => $chat_id, 'text' => $message, 'message_thread_id' => $message_thread_id, ]); } else { $response = Http::asForm()->post($send_url, [ 'chat_id' => $chat_id, 'text' => $message, ]); } // $end = microtime(true); // $duration = $end - $start; return redirect()->route("admin.video.index", $this->anime_id); } #[Layout("layouts.admin")] public function render() { return view('livewire.admin.video.video-create'); } }
Back