Browse Source

change save file to buffer

pull/2/head
Mohammad Khazaee 2 years ago
parent
commit
cfc8ec2616
  1. 89
      app/Http/Controllers/FileController.php
  2. BIN
      storage/stub/00.webp
  3. 0
      storage/stub/000.png
  4. BIN
      storage/stub/001.webp
  5. BIN
      storage/stub/0010.png
  6. BIN
      storage/stub/0011.png
  7. BIN
      storage/stub/0012.png
  8. BIN
      storage/stub/0013.png
  9. BIN
      storage/stub/0014.png
  10. BIN
      storage/stub/0015.png
  11. BIN
      storage/stub/0016.png
  12. BIN
      storage/stub/0017.png
  13. BIN
      storage/stub/0017.webp
  14. BIN
      storage/stub/002.png
  15. BIN
      storage/stub/003.webp
  16. BIN
      storage/stub/004.png
  17. BIN
      storage/stub/005.png
  18. BIN
      storage/stub/006.png
  19. BIN
      storage/stub/007.png
  20. BIN
      storage/stub/008.png
  21. BIN
      storage/stub/009.png
  22. BIN
      storage/stub/01.webp
  23. BIN
      storage/stub/02.webp
  24. BIN
      storage/stub/03.webp
  25. BIN
      storage/stub/04.webp
  26. BIN
      storage/stub/05.webp
  27. BIN
      storage/stub/06.webp
  28. BIN
      storage/stub/07.webp
  29. BIN
      storage/stub/08.webp
  30. BIN
      storage/stub/09.webp
  31. BIN
      storage/stub/10.webp
  32. BIN
      storage/stub/100.png
  33. BIN
      storage/stub/11.webp
  34. BIN
      storage/stub/13.webp
  35. BIN
      storage/stub/14.webp
  36. BIN
      storage/stub/16.webp
  37. BIN
      storage/stub/17.webp
  38. BIN
      storage/stub/19.webp
  39. BIN
      storage/stub/image1.png

89
app/Http/Controllers/FileController.php

@ -1,89 +0,0 @@
<?php
namespace App\Http\Controllers;
use App\Http\Requests\FileStoreRequest;
use App\Http\Requests\FileUpdateRequest;
use App\Http\Resources\FileResource;
use App\Image\ImageProcessor;
use App\Models\File;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Response;
use Illuminate\Support\Facades\Storage;
class FileController extends Controller
{
public function show($collection, $uuid, $ext, Request $request, ImageProcessor $imageProcessor)
{
if ($request->castParams == 'resource') {
return new FileResource(app()->file);
}
if (!is_null(array_intersect(array_keys($request->all()), $this->availableParams))) {
$data = $imageProcessor->processToBuffer(app()->file->getPath(), $request->all());
$response = Response::make($data, 200);
$response->header('Content-Type','image/webp');
return $response;
}
return response()->file(app()->file->getPath());
}
public function store(FileStoreRequest $request, ImageProcessor $imageProcessor)
{
$request->file = $imageProcessor->convertImage($request->file->path(), '/tmp/' . app()->uuid . '.' . app()->collection->ext);
if (!is_null(app()->collection->process)) {
$request->file = $imageProcessor->process($request->file->path(), '/tmp/' . app()->uuid . '.' . app()->collection->ext, app()->collection->process);
}
$fileResource = null;
DB::transaction(function () use ($request, &$fileResource) {
$uuid = app()->uuid;
$fileResource = File::create([
'uuid' => $uuid,
'original_name' => $request->name,
'public' => $request->public,
'ext' => $request->file->extension(),
'mimetype' => $request->file->getMimeType(),
'width' => getimagesize($request->file)[0],
'height' => getimagesize($request->file)[1],
'file_size' => $request->file->getSize(),
'sort' => $request->file->getSize(),
'alts' => $request->alts,
'description' => $request->description,
'user_id' => auth()->id(),
'ip' => $request->ip(),
'collection_id' => app()->collection->id,
'published_at' => $request->published_at,
'server_path' => '/' . date('y') . '/' . date('m') . '/',
]);
if (!app()->collection->tmp_support && app()->collection->count == 1) {
File::where('user_id', auth()->id())->delete();
}
$storedFile = Storage::disk(app()->collection->disk)->putFileAs($fileResource->server_path, $request->file, $fileResource->uuid . '.' . app()->collection->ext);
if (app()->collection->public) {
Storage::disk(app()->collection->disk)->setVisibility($storedFile, 'public');
}
});
return new FileResource($fileResource);
}
public function update(FileUpdateRequest $request)
{
app()->file->update($request->all());
return new FileResource(app()->file);
}
public function destroy()
{
if (app()->file->trashed()) {
return app()->file->restore();
}
return app()->file->delete();
}
}

BIN
storage/stub/00.webp

Binary file not shown.

0
storage/stub/000.png

BIN
storage/stub/001.webp

Binary file not shown.

Before

Width: 1920  |  Height: 920  |  Size: 32 KiB

BIN
storage/stub/0010.png

Binary file not shown.

Before

Width: 1920  |  Height: 920  |  Size: 614 KiB

BIN
storage/stub/0011.png

Binary file not shown.

Before

Width: 1920  |  Height: 920  |  Size: 615 KiB

BIN
storage/stub/0012.png

Binary file not shown.

Before

Width: 1920  |  Height: 920  |  Size: 616 KiB

BIN
storage/stub/0013.png

Binary file not shown.

Before

Width: 1920  |  Height: 920  |  Size: 616 KiB

BIN
storage/stub/0014.png

Binary file not shown.

Before

Width: 1920  |  Height: 920  |  Size: 618 KiB

BIN
storage/stub/0015.png

Binary file not shown.

Before

Width: 1920  |  Height: 920  |  Size: 618 KiB

BIN
storage/stub/0016.png

Binary file not shown.

Before

Width: 1920  |  Height: 920  |  Size: 618 KiB

BIN
storage/stub/0017.png

Binary file not shown.

Before

Width: 1920  |  Height: 920  |  Size: 619 KiB

BIN
storage/stub/0017.webp

Binary file not shown.

BIN
storage/stub/002.png

Binary file not shown.

Before

Width: 1920  |  Height: 920  |  Size: 155 KiB

BIN
storage/stub/003.webp

Binary file not shown.

Before

Width: 1920  |  Height: 920  |  Size: 328 KiB

BIN
storage/stub/004.png

Binary file not shown.

Before

Width: 1920  |  Height: 920  |  Size: 577 KiB

BIN
storage/stub/005.png

Binary file not shown.

Before

Width: 1920  |  Height: 920  |  Size: 597 KiB

BIN
storage/stub/006.png

Binary file not shown.

Before

Width: 1920  |  Height: 920  |  Size: 598 KiB

BIN
storage/stub/007.png

Binary file not shown.

Before

Width: 1920  |  Height: 920  |  Size: 600 KiB

BIN
storage/stub/008.png

Binary file not shown.

Before

Width: 1920  |  Height: 920  |  Size: 615 KiB

BIN
storage/stub/009.png

Binary file not shown.

Before

Width: 1920  |  Height: 920  |  Size: 614 KiB

BIN
storage/stub/01.webp

Binary file not shown.

BIN
storage/stub/02.webp

Binary file not shown.

BIN
storage/stub/03.webp

Binary file not shown.

BIN
storage/stub/04.webp

Binary file not shown.

BIN
storage/stub/05.webp

Binary file not shown.

BIN
storage/stub/06.webp

Binary file not shown.

BIN
storage/stub/07.webp

Binary file not shown.

BIN
storage/stub/08.webp

Binary file not shown.

BIN
storage/stub/09.webp

Binary file not shown.

BIN
storage/stub/10.webp

Binary file not shown.

Before

Width: 1920  |  Height: 920  |  Size: 9.9 KiB

BIN
storage/stub/100.png

Binary file not shown.

Before

Width: 1920  |  Height: 920  |  Size: 642 B

BIN
storage/stub/11.webp

Binary file not shown.

Before

Width: 1920  |  Height: 920  |  Size: 12 KiB

BIN
storage/stub/13.webp

Binary file not shown.

Before

Width: 1920  |  Height: 920  |  Size: 11 KiB

BIN
storage/stub/14.webp

Binary file not shown.

BIN
storage/stub/16.webp

Binary file not shown.

Before

Width: 1920  |  Height: 920  |  Size: 9.8 KiB

BIN
storage/stub/17.webp

Binary file not shown.

Before

Width: 1920  |  Height: 920  |  Size: 10 KiB

BIN
storage/stub/19.webp

Binary file not shown.

BIN
storage/stub/image1.png

Binary file not shown.

Before

Width: 600  |  Height: 1200  |  Size: 620 KiB

Loading…
Cancel
Save