mirror of
https://github.com/NyaaStudios/nyaabooru.git
synced 2025-12-10 05:42:58 +00:00
This commit is contained in:
parent
21e59d775a
commit
f60ae41bf6
26 changed files with 741 additions and 70 deletions
|
|
@ -15,8 +15,8 @@ class Upload extends Component
|
|||
{
|
||||
use WithFileUploads;
|
||||
|
||||
#[Validate('image|max:65536')]
|
||||
public $file;
|
||||
#[Validate(['files.*' => 'required|image|max:65536'])]
|
||||
public $files = [];
|
||||
|
||||
#[Validate('required|in:safe,suggestive,explicit')]
|
||||
public $rating = 'safe';
|
||||
|
|
@ -32,33 +32,35 @@ class Upload extends Component
|
|||
$this->validate();
|
||||
$author = Auth::user();
|
||||
|
||||
if ($this->file)
|
||||
foreach ($this->files as $file)
|
||||
{
|
||||
$post = Post::create([
|
||||
'extension' => $this->file->getClientOriginalExtension(),
|
||||
'rating' => $this->rating,
|
||||
]);
|
||||
|
||||
if ($post)
|
||||
if ($file)
|
||||
{
|
||||
$author->posts()->save($post);
|
||||
$post = Post::create([
|
||||
'extension' => $file->getClientOriginalExtension(),
|
||||
'rating' => $this->rating,
|
||||
'hash' => $file->hashName(),
|
||||
]);
|
||||
|
||||
// Save the full image
|
||||
$this->file->storeAs("posts/$post->id", 'full');
|
||||
$fullImg = Storage::get("posts/$post->id/full");
|
||||
if ($post)
|
||||
{
|
||||
$author->posts()->save($post);
|
||||
|
||||
// Create thumbnail preview
|
||||
$thumb = Image::read($fullImg)->cover(width: 512, height: 512);
|
||||
Storage::put("posts/$post->id/thumb", $thumb->encodeByMediaType());
|
||||
// Save the full image
|
||||
$file->storeAs("posts/$post->id", 'full');
|
||||
$fullImg = Storage::get("posts/$post->id/full");
|
||||
|
||||
// Create smaller preview image
|
||||
$preview = Image::read($fullImg)->scaleDown(width: 1280, height: 720);
|
||||
Storage::put("posts/$post->id/preview", $preview->encodeByMediaType());
|
||||
// Create thumbnail preview
|
||||
$thumb = Image::read($fullImg)->cover(width: 512, height: 512);
|
||||
Storage::put("posts/$post->id/thumb", $thumb->encodeByMediaType());
|
||||
|
||||
return $this->redirect("/posts/$post->id");
|
||||
// Create smaller preview image
|
||||
$preview = Image::read($fullImg)->scaleDown(width: 1280, height: 720);
|
||||
Storage::put("posts/$post->id/preview", $preview->encodeByMediaType());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->redirect('/upload');
|
||||
return $this->redirect('/posts');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue