Skip to content

Commit

Permalink
[HOTFIX][BE] Fix wrong file downloaded on split PDF (#186)
Browse files Browse the repository at this point in the history
## What's Fixed:
- Add logic to delete previous downloaded file, if previous downloaded
filename are same with
new generated processed filename. This to prevent BE accidentally return
wrong response into FE, when
notification service catch actual response.
> Ex: BE response 200 with download link, although notification service
threw error notification
> "Cannot download from iLovePDF API !". Actual condition is BE process
is fail, but since logic
> for decision process is success or not have another depend to check if
processed filename is exist or not,
> and in this scenario. User processed the same filename, then that
logic will think previous file is the new
> 		file due the same filename.
- Add more filter validation on split and watermark to provide "-"
characters (Now user can input page: 2-5, not only 2,3,4,5)
- Add new params 'usedMethod' that will declare as identifier process,
is that split or delete.
This will fixed issue sometimes logic can not catch correctly what
actual request from FE, since FE
are not declare what are the request properly
- Bump BE services to 3.3.0
  • Loading branch information
Nicklas373 authored Jul 16, 2024
2 parents bf6a215 + fa8e333 commit 80c9ebb
Show file tree
Hide file tree
Showing 19 changed files with 492 additions and 375 deletions.
5 changes: 5 additions & 0 deletions app/Http/Controllers/Api/Core/compressController.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ public function compress(Request $request) {
$newFilePath = Storage::disk('local')->path('public/'.$pdfUpload_Location.'/'.$trimPhase1);
$fileSize = filesize($newFilePath);
$newFileSize = AppHelper::instance()->convert($fileSize, "MB");
if ($loopCount <= 1) {
if (Storage::disk('local')->exists('public/'.$pdfDownload_Location.'/'.$trimPhase1)) {
Storage::disk('local')->delete('public/'.$pdfDownload_Location.'/'.$trimPhase1);
}
}
try {
$ilovepdf = new Ilovepdf(env('ILOVEPDF_PUBLIC_KEY'),env('ILOVEPDF_SECRET_KEY'));
$ilovepdfTask = $ilovepdf->newTask('compress');
Expand Down
27 changes: 27 additions & 0 deletions app/Http/Controllers/Api/Core/convertController.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ public function convert(Request $request) {
$pdfTotalPages = AppHelper::instance()->count($newFilePath);
$pdfNameWithExtension = pathinfo($currentFileName, PATHINFO_EXTENSION);
if ($convertType == 'xlsx') {
if ($loopCount <= 1) {
if (Storage::disk('local')->exists('public/'.$pdfDownload_Location.'/'.$newFileNameWithoutExtension.'.xlsx')) {
Storage::disk('local')->delete('public/'.$pdfDownload_Location.'/'.$newFileNameWithoutExtension.'.xlsx');
}
}
$asposeAPI = new Process([
'python3',
public_path().'/ext-python/asposeAPI.py',
Expand Down Expand Up @@ -535,6 +540,11 @@ public function convert(Request $request) {
}
}
} else if ($convertType == 'pptx') {
if ($loopCount <= 1) {
if (Storage::disk('local')->exists('public/'.$pdfDownload_Location.'/'.$newFileNameWithoutExtension.'.pptx')) {
Storage::disk('local')->delete('public/'.$pdfDownload_Location.'/'.$newFileNameWithoutExtension.'.pptx');
}
}
$asposeAPI = new Process([
'python3',
public_path().'/ext-python/asposeAPI.py',
Expand Down Expand Up @@ -924,6 +934,11 @@ public function convert(Request $request) {
}
}
} else if ($convertType == 'docx') {
if ($loopCount <= 1) {
if (Storage::disk('local')->exists('public/'.$pdfDownload_Location.'/'.$newFileNameWithoutExtension.'.docx')) {
Storage::disk('local')->delete('public/'.$pdfDownload_Location.'/'.$newFileNameWithoutExtension.'.docx');
}
}
try {
$wordsApi = new WordsApi(env('ASPOSE_CLOUD_CLIENT_ID'), env('ASPOSE_CLOUD_TOKEN'));
$uploadFileRequest = new UploadFileRequest($newFilePath, $currentFileName);
Expand Down Expand Up @@ -1192,6 +1207,13 @@ public function convert(Request $request) {
}
}
} else if ($convertType == 'jpg') {
if ($loopCount <= 1) {
if (Storage::disk('local')->exists('public/'.$pdfDownload_Location.'/'.$newFileNameWithoutExtension.'.jpg')) {
Storage::disk('local')->delete('public/'.$pdfDownload_Location.'/'.$newFileNameWithoutExtension.'.jpg');
} else if (Storage::disk('local')->exists('public/'.$pdfDownload_Location.'/'.$newFileNameWithoutExtension.'-0001.jpg')) {
Storage::disk('local')->delete('public/'.$pdfDownload_Location.'/'.$newFileNameWithoutExtension.'-0001.jpg');
}
}
try {
$ilovepdfTask = new PdfjpgTask(env('ILOVEPDF_PUBLIC_KEY'),env('ILOVEPDF_SECRET_KEY'));
$ilovepdfTask->setFileEncryption($pdfEncKey);
Expand Down Expand Up @@ -1890,6 +1912,11 @@ public function convert(Request $request) {
}
}
} else if ($convertType == 'pdf') {
if ($loopCount <= 1) {
if (Storage::disk('local')->exists('public/'.$pdfDownload_Location.'/'.$newFileNameWithoutExtension.'.pdf')) {
Storage::disk('local')->delete('public/'.$pdfDownload_Location.'/'.$newFileNameWithoutExtension.'.pdf');
}
}
if ($pdfNameWithExtension == "jpg" || $pdfNameWithExtension == "jpeg" || $pdfNameWithExtension == "png" || $pdfNameWithExtension == "tiff") {
try {
$ilovepdfTask = new ImagepdfTask(env('ILOVEPDF_PUBLIC_KEY'),env('ILOVEPDF_SECRET_KEY'));
Expand Down
3 changes: 3 additions & 0 deletions app/Http/Controllers/Api/Core/htmltopdfController.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ public function html(Request $request) {
}
}
}
if (Storage::disk('local')->exists('public/'.$pdfProcessed_Location.'/'.$pdfDefaultFileName)) {
Storage::disk('local')->delete('public/'.$pdfProcessed_Location.'/'.$pdfDefaultFileName);
}
try {
$ilovepdfTask = new HtmlpdfTask(env('ILOVEPDF_PUBLIC_KEY'),env('ILOVEPDF_SECRET_KEY'));
$ilovepdfTask->setEncryptKey($pdfEncKey);
Expand Down
Loading

0 comments on commit 80c9ebb

Please sign in to comment.