You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
2.8 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Http\Requests\FileStoreRequest;
  4. use App\Http\Resources\FileResource;
  5. use App\Image\ImageProcessor;
  6. use App\Jobs\FileConversionQueue;
  7. use App\Models\File;
  8. use Illuminate\Http\Request;
  9. use Illuminate\Support\Facades\DB;
  10. use Illuminate\Support\Facades\Storage;
  11. use Illuminate\Support\Facades\Validator;
  12. use Symfony\Component\Console\Input\Input;
  13. use function PHPUnit\Framework\isNull;
  14. class FileController extends Controller
  15. {
  16. public function show($collection, $uuid, $ext)
  17. {
  18. dump($collection, $uuid, $ext);
  19. }
  20. public function private($collection, $path)
  21. {
  22. Storage::disk('local')->download($path);
  23. }
  24. public function store(FileStoreRequest $request, ImageProcessor $imageProcessor)
  25. {
  26. $request->file = $imageProcessor->convertImage($request->file->path(),'/tmp/' . app()->uuid . '.' . app()->collection->ext);
  27. if (!is_null(app()->collection->process)) {
  28. $request->file = $imageProcessor->process($request->file->path(),'/tmp/' . app()->uuid. '.' . app()->collection->ext, app()->collection->process);
  29. }
  30. DB::transaction(function () use ($request) {
  31. $uuid = app()->uuid;
  32. $request->resourceFile = File::create([
  33. 'uuid' => $uuid,
  34. 'original_name' => $request->name,
  35. 'public' => $request->public,
  36. 'ext' => $request->file->extension(),
  37. 'mimetype' => $request->file->getMimeType(),
  38. 'width' => getimagesize($request->file)[0],
  39. 'height' => getimagesize($request->file)[1],
  40. 'file_size' => $request->file->getSize(),
  41. 'sort' => $request->file->getSize(),
  42. 'alts' => $request->alts,
  43. 'description' => $request->description,
  44. 'user_id' => auth()->id(),
  45. 'ip' => $request->ip(),
  46. 'collection_id' => app()->collection->id,
  47. 'published_at' => $request->published_at,
  48. 'server_path' => '/' . date('y') . '/' . date('m') . '/',
  49. ]);
  50. if (!app()->collection->tmp_support && app()->collection->count == 1) {
  51. File::where('user_id', auth()->id())->delete();
  52. }
  53. $storedFile = Storage::disk(app()->collection->disk)->putFileAs('', $request->file,$request->resourceFile->server_path . $request->resourceFile->uuid . '.' . app()->collection->ext);
  54. if (app()->collection->public) {
  55. Storage::disk(app()->collection->disk)->setVisibility($storedFile, 'public');
  56. }
  57. });
  58. return new FileResource($request->resourceFile);
  59. }
  60. public function update(Request $request, $id)
  61. {
  62. //
  63. }
  64. public function destroy($id)
  65. {
  66. //
  67. }
  68. }