diff --git a/app/Http/Controllers/Content/FileUploadController.php b/app/Http/Controllers/Content/FileUploadController.php new file mode 100644 index 000000000..62e6423a7 --- /dev/null +++ b/app/Http/Controllers/Content/FileUploadController.php @@ -0,0 +1,28 @@ +file('file')->storeAs(PublicFormController::TMP_FILE_UPLOAD_PATH, $uuid); + + return response()->json([ + 'uuid' => $uuid, + 'key' => $path + ], 201); + } +} diff --git a/app/Http/Controllers/Forms/FormController.php b/app/Http/Controllers/Forms/FormController.php index 6c99b7b07..5865f1db1 100644 --- a/app/Http/Controllers/Forms/FormController.php +++ b/app/Http/Controllers/Forms/FormController.php @@ -177,12 +177,12 @@ public function uploadAsset(UploadAssetRequest $request) // Make sure we retrieve the file in tmp storage, move it to persistent $fileName = PublicFormController::TMP_FILE_UPLOAD_PATH.'/'.$fileNameParser->uuid;; - if (!Storage::disk('s3')->exists($fileName)) { + if (!Storage::exists($fileName)) { // File not found, we skip return null; } $newPath = self::ASSETS_UPLOAD_PATH.'/'.$fileNameParser->getMovedFileName(); - Storage::disk('s3')->move($fileName, $newPath); + Storage::move($fileName, $newPath); return $this->success([ 'message' => 'File uploaded.', @@ -199,12 +199,12 @@ public function viewFile($id, $fileName) $this->authorize('view', $form); $path = Str::of(PublicFormController::FILE_UPLOAD_PATH)->replace('?', $form->id).'/'.$fileName; - if (!Storage::disk('s3')->exists($path)) { + if (!Storage::exists($path)) { return $this->error([ 'message' => 'File not found.' ]); } - return redirect()->to(Storage::disk('s3')->temporaryUrl($path, now()->addMinutes(5))); + return redirect()->to(Storage::temporaryUrl($path, now()->addMinutes(5))); } } diff --git a/app/Http/Controllers/Forms/FormSubmissionController.php b/app/Http/Controllers/Forms/FormSubmissionController.php index ba7a8f8ed..75d1a90d7 100644 --- a/app/Http/Controllers/Forms/FormSubmissionController.php +++ b/app/Http/Controllers/Forms/FormSubmissionController.php @@ -57,14 +57,14 @@ public function submissionFile($id, $fileName) $fileName = Str::of(PublicFormController::FILE_UPLOAD_PATH)->replace('?', $id).'/' .urldecode($fileName); - if (!Storage::disk('s3')->exists($fileName)) { + if (!Storage::exists($fileName)) { return $this->error([ 'message' => 'File not found.', ], 404); } return redirect( - Storage::disk('s3')->temporaryUrl($fileName, now()->addMinute()) + Storage::temporaryUrl($fileName, now()->addMinute()) ); } } diff --git a/app/Http/Controllers/Forms/PublicFormController.php b/app/Http/Controllers/Forms/PublicFormController.php index 69f7e677a..8856ba77d 100644 --- a/app/Http/Controllers/Forms/PublicFormController.php +++ b/app/Http/Controllers/Forms/PublicFormController.php @@ -66,14 +66,14 @@ public function listUsers(Request $request) public function showAsset($assetFileName) { $path = FormController::ASSETS_UPLOAD_PATH.'/'.$assetFileName; - if (!Storage::disk('s3')->exists($path)) { + if (!Storage::exists($path)) { return $this->error([ 'message' => 'File not found.', 'file_name' => $assetFileName ]); } - - return redirect()->to(Storage::disk('s3')->temporaryUrl($path, now()->addMinutes(5))); + + return redirect()->to(Storage::temporaryUrl($path, now()->addMinutes(5))); } public function answer(AnswerFormRequest $request) diff --git a/app/Http/Middleware/VerifyCsrfToken.php b/app/Http/Middleware/VerifyCsrfToken.php index 81cca901f..7d14bf7bf 100644 --- a/app/Http/Middleware/VerifyCsrfToken.php +++ b/app/Http/Middleware/VerifyCsrfToken.php @@ -13,6 +13,7 @@ class VerifyCsrfToken extends Middleware */ protected $except = [ 'stripe/webhook', - 'vapor/signed-storage-url' + 'vapor/signed-storage-url', + 'upload-file' ]; } diff --git a/app/Jobs/Form/StoreFormSubmissionJob.php b/app/Jobs/Form/StoreFormSubmissionJob.php index cf15f085a..c12d932ae 100644 --- a/app/Jobs/Form/StoreFormSubmissionJob.php +++ b/app/Jobs/Form/StoreFormSubmissionJob.php @@ -140,7 +140,7 @@ private function getFormData() private function isSkipForUpload($value) { $newPath = Str::of(PublicFormController::FILE_UPLOAD_PATH)->replace('?', $this->form->id); - return Storage::disk('s3')->exists($newPath.'/'.$value); + return Storage::exists($newPath.'/'.$value); } /** @@ -165,7 +165,7 @@ private function storeFile(?string $value) // Make sure we retrieve the file in tmp storage, move it to persistent $fileName = PublicFormController::TMP_FILE_UPLOAD_PATH.'/'.$fileNameParser->uuid; - if (!Storage::disk('s3')->exists($fileName)) { + if (!Storage::exists($fileName)) { // File not found, we skip return null; } @@ -178,7 +178,7 @@ private function storeFile(?string $value) 'form_id' => $this->form->id, 'form_slug' => $this->form->slug, ]); - Storage::disk('s3')->move($fileName, $completeNewFilename); + Storage::move($fileName, $completeNewFilename); return $fileNameParser->getMovedFileName(); } @@ -193,7 +193,7 @@ private function storeSignature(?string $value) $newPath = Str::of(PublicFormController::FILE_UPLOAD_PATH)->replace('?', $this->form->id); $completeNewFilename = $newPath.'/'.$fileName; - Storage::disk('s3')->put($completeNewFilename, base64_decode(explode(',', $value)[1])); + Storage::put($completeNewFilename, base64_decode(explode(',', $value)[1])); return $fileName; } diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index cdb7f10fc..dd0a30f1a 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -8,7 +8,8 @@ use Laravel\Cashier\Cashier; use Laravel\Dusk\DuskServiceProvider; use Illuminate\Support\Facades\Validator; - +use Illuminate\Support\Facades\Storage; +use Illuminate\Support\Facades\URL; class AppServiceProvider extends ServiceProvider { /** @@ -18,6 +19,16 @@ class AppServiceProvider extends ServiceProvider */ public function boot() { + if(config('filesystems.default') === 'local'){ + Storage::disk('local')->buildTemporaryUrlsUsing(function ($path, $expiration, $options) { + return URL::temporarySignedRoute( + 'local.temp', + $expiration, + array_merge($options, ['path' => $path]) + ); + }); + } + JsonResource::withoutWrapping(); Cashier::calculateTaxes(); diff --git a/app/Rules/StorageFile.php b/app/Rules/StorageFile.php index 49e67a9fa..f2f0a3055 100644 --- a/app/Rules/StorageFile.php +++ b/app/Rules/StorageFile.php @@ -43,7 +43,7 @@ public function passes($attribute, $value): bool // This is use when updating a record, and file uploads aren't changed. if($this->form){ $newPath = Str::of(PublicFormController::FILE_UPLOAD_PATH)->replace('?', $this->form->id); - if(Storage::disk('s3')->exists($newPath.'/'.$value)){ + if(Storage::exists($newPath.'/'.$value)){ return true; } } diff --git a/resources/js/components/pages/welcome/AiFeature.vue b/resources/js/components/pages/welcome/AiFeature.vue index ad4546875..c24fdad14 100644 --- a/resources/js/components/pages/welcome/AiFeature.vue +++ b/resources/js/components/pages/welcome/AiFeature.vue @@ -62,13 +62,16 @@ -