From 5da53651d4de5bb08adef41efe642d65f8ed6963 Mon Sep 17 00:00:00 2001 From: Dillon Ngo Date: Sat, 25 May 2024 12:12:18 +0800 Subject: [PATCH] Laravel Vapor - Code Sync from Shipping Portal to use S3 Bucket to replace local storage --- .../Convert1688PurchaseOrderToProductList.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/app/Classes/Modules/Bookings/Services/Convert1688PurchaseOrderToProductList.php b/app/Classes/Modules/Bookings/Services/Convert1688PurchaseOrderToProductList.php index b956aa39..72e4aa83 100644 --- a/app/Classes/Modules/Bookings/Services/Convert1688PurchaseOrderToProductList.php +++ b/app/Classes/Modules/Bookings/Services/Convert1688PurchaseOrderToProductList.php @@ -20,14 +20,28 @@ class Convert1688PurchaseOrderToProductList $productList = []; $shipping = 0; $discount = 0; + $text = ""; + $filepath = ""; + + $filesystemDriver = Storage::getDefaultDriver(); + $file = $file->file->file_info->original->file; + if($filesystemDriver === 's3'){ + $fileContent = Storage::disk('s3')->get($file); + $filepath = storage_path('app/temp.pdf'); + file_put_contents($filepath, $fileContent); + } + else{ + $filepath = Storage::disk('documents')->path($file); + } try { - $pdf = $parser->parseFile(Storage::disk('documents')->path($file->file->file_info->original->file)); + $pdf = $parser->parseFile($filepath); + $text = $pdf->getText(); } catch (Exception $exception) { throw new MalformedRequestException('Invalid file format.'); } - $text = $pdf->getText(); + if(str_contains($text, '订单详情单')) throw new MalformedRequestException('Can\'t process non english documents'); $tables = explode('Amount (yuan)', $text);