mirror of
https://github.com/NyaaStudios/nyaabooru.git
synced 2025-12-10 05:42:58 +00:00
add models, setup livewire, setup mongodb
This commit is contained in:
parent
c0590a3412
commit
be4c848eee
27 changed files with 2508 additions and 0 deletions
64
app/Livewire/Pages/Upload.php
Normal file
64
app/Livewire/Pages/Upload.php
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
|
||||
namespace App\Livewire\Pages;
|
||||
|
||||
use App\Models\Post;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Intervention\Image\Laravel\Facades\Image;
|
||||
use Livewire\Attributes\Title;
|
||||
use Livewire\Attributes\Validate;
|
||||
use Livewire\Component;
|
||||
use Livewire\WithFileUploads;
|
||||
|
||||
class Upload extends Component
|
||||
{
|
||||
use WithFileUploads;
|
||||
|
||||
#[Validate('extensions:jpg,jpeg,bmp,gif,png,webp,apng,mp4,wmv,mkv|mimes:jpg,jpeg,bmp,gif,png,webp,apng,mp4,wmv,mkv|max:81920')]
|
||||
public $file;
|
||||
|
||||
#[Validate('required|in:safe,suggestive,explicit')]
|
||||
public $rating = 'safe';
|
||||
|
||||
#[Title('Upload')]
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.pages.upload');
|
||||
}
|
||||
|
||||
public function createPost()
|
||||
{
|
||||
$this->validate();
|
||||
$author = Auth::user();
|
||||
|
||||
if ($this->file)
|
||||
{
|
||||
$post = Post::create([
|
||||
'extension' => $this->file->getClientOriginalExtension(),
|
||||
'rating' => $this->rating,
|
||||
]);
|
||||
|
||||
if ($post)
|
||||
{
|
||||
$author->posts()->save($post);
|
||||
|
||||
// Save the full image
|
||||
$this->file->storeAs("posts/$post->id", 'full');
|
||||
$fullImg = Storage::get("posts/$post->id/full");
|
||||
|
||||
// Create thumbnail preview
|
||||
$thumb = Image::read($fullImg)->scaleDown(width: 512, height: 512);
|
||||
Storage::put("posts/$post->id/thumb", $thumb->encodeByExtension($post->extension, quality: 70));
|
||||
|
||||
// Create smaller preview image
|
||||
$preview = Image::read($fullImg)->scaleDown(width: 1280, height: 720);
|
||||
Storage::put("posts/$post->id/preview", $preview->encodeByExtension($post->extension, quality: 70));
|
||||
|
||||
return $this->redirect('/');
|
||||
}
|
||||
}
|
||||
|
||||
return $this->redirect('/upload');
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue