Skip to content

Commit

Permalink
v3.5.5 20241107 [Backend Module] (#274)
Browse files Browse the repository at this point in the history
**Recent changelog**:
- [Controllers: Core: Fix may duplicate logic for Create
Models](4e76c4a)
- [Bootstrap: Fix may duplicate logic for Create
Models](3e7652e)
- [Routes: Fix duplicate create models due race
conditions](95440f7)
- [Controllers: Convert: Only use pdfCount() when file is
PDF](049bf2a)
- [Controllers: Core: Convert: Fix unproper address python
binary](0894ae7)
- [Controllers: Core: Priority file checking before call
API](e5d60ad)
- [Routes: Console: Fix may-duplicated primary
ID](10988aa)
- [Helpers: Notification: Properly use Laravel Eloquent
models](399c4cb)
  • Loading branch information
Nicklas373 authored Nov 7, 2024
2 parents 83ab7dc + 0e97888 commit cfd8e3d
Show file tree
Hide file tree
Showing 9 changed files with 721 additions and 550 deletions.
298 changes: 168 additions & 130 deletions app/Helpers/NotificationHelper.php

Large diffs are not rendered by default.

286 changes: 136 additions & 150 deletions app/Http/Controllers/Api/Core/compressController.php

Large diffs are not rendered by default.

20 changes: 14 additions & 6 deletions app/Http/Controllers/Api/Core/convertController.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ public function convert(Request $request) {
$newFileSize = AppHelper::instance()->convert($fileSize, "MB");
$procUuid = AppHelper::Instance()->generateUniqueUuid(cnvModel::class, 'processId');
$pdfNameWithExtension = pathinfo($currentFileName, PATHINFO_EXTENSION);
if ($pdfNameWithExtension == "pdf") {
$pdf = new Pdf($newFilePath);
$pdfTotalPages = $pdf->pageCount();
}
if ($pdfNameWithExtension == "pdf") {
$pdf = new Pdf($newFilePath);
$pdfTotalPages = $pdf->pageCount();
}
appLogModel::create([
'processId' => $procUuid,
'groupId' => $batchId,
Expand Down Expand Up @@ -152,7 +152,7 @@ public function convert(Request $request) {
}
}
$asposeAPI = new Process([
'py',
'python3',
public_path().'/ext-python/asposeAPI.py',
env('ASPOSE_CLOUD_CLIENT_ID'),
env('ASPOSE_CLOUD_TOKEN'),
Expand Down Expand Up @@ -308,7 +308,7 @@ public function convert(Request $request) {
}
}
$asposeAPI = new Process([
'py',
'python3',
public_path().'/ext-python/asposeAPI.py',
env('ASPOSE_CLOUD_CLIENT_ID'),
env('ASPOSE_CLOUD_TOKEN'),
Expand Down Expand Up @@ -805,6 +805,8 @@ public function convert(Request $request) {
$relativePath = $file.'.zip';
$zip->addFile($filePath, $relativePath);
} else {
$end = Carbon::parse(AppHelper::instance()->getCurrentTimeZone());
$duration = $end->diff($startProc);
appLogModel::where('groupId', '=', $batchId)
->update([
'errReason' => 'Failed convert PDF file !',
Expand Down Expand Up @@ -851,6 +853,8 @@ public function convert(Request $request) {
unlink($file);
}
}
$end = Carbon::parse(AppHelper::instance()->getCurrentTimeZone());
$duration = $end->diff($startProc);
appLogModel::where('groupId', '=', $batchId)
->update([
'errReason' => null,
Expand All @@ -875,6 +879,8 @@ public function convert(Request $request) {
null
);
} else {
$end = Carbon::parse(AppHelper::instance()->getCurrentTimeZone());
$duration = $end->diff($startProc);
appLogModel::where('groupId', '=', $batchId)
->update([
'errReason' => 'Failed archiving PDF files !',
Expand Down Expand Up @@ -905,6 +911,8 @@ public function convert(Request $request) {
}
}
} else {
$end = Carbon::parse(AppHelper::instance()->getCurrentTimeZone());
$duration = $end->diff($startProc);
appLogModel::where('groupId', '=', $batchId)
->update([
'errReason' => 'PDF convert failed',
Expand Down
264 changes: 154 additions & 110 deletions app/Http/Controllers/Api/Core/mergeController.php

Large diffs are not rendered by default.

42 changes: 42 additions & 0 deletions app/Http/Controllers/Api/Core/splitController.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ public function split(Request $request) {
$pdfDownload_Location = $pdfProcessed_Location;
$batchValue = false;
$str = rand(1000,10000000);
$loopCount = count($files);
$altPoolFiles = array();
$randomizePdfFileName = 'pdfSplit_'.substr(md5(uniqid($str)), 0, 8);
if ($action == 'split' && $usedMethod == 'range') {
if (empty($fromPage) || empty($toPage)) {
Expand Down Expand Up @@ -121,6 +123,15 @@ public function split(Request $request) {
$newFileNameWithoutExtension = str_replace('.', '_', $trimPhase1);
$newFilePath = Storage::disk('local')->path('public/'.$pdfUpload_Location.'/'.$trimPhase1);
if (file_exists($newFilePath)) {
array_push($altPoolFiles, $newFileNameWithoutExtension);
}
}
if ($loopCount == count($altPoolFiles)) {
foreach ($files as $file) {
$currentFileName = basename($file);
$trimPhase1 = str_replace(' ', '_', $currentFileName);
$newFileNameWithoutExtension = str_replace('.', '_', $trimPhase1);
$newFilePath = Storage::disk('local')->path('public/'.$pdfUpload_Location.'/'.$trimPhase1);
$fileSize = filesize($newFilePath);
$newFileSize = AppHelper::instance()->convert($fileSize, "MB");
$procUuid = AppHelper::Instance()->generateUniqueUuid(splitModel::class, 'processId');
Expand Down Expand Up @@ -681,6 +692,37 @@ public function split(Request $request) {
);
}
}
} else {
$end = Carbon::parse(AppHelper::instance()->getCurrentTimeZone());
$duration = $end->diff($startProc);
appLogModel::where('groupId', '=', $batchId)
->update([
'errReason' => 'File not found on the server',
'errStatus' => 'File not found on our end, please try again'
]);
splitModel::where('groupId', '=', $batchId)
->update([
'result' => false,
'procEndAt' => AppHelper::instance()->getCurrentTimeZone(),
'procDuration' => $duration->s.' seconds'
]);
NotificationHelper::Instance()->sendErrNotify(
$currentFileName,
null,
$batchId,
'FAIL',
'split',
'File not found on the server',
'File not found on our end, please try again'
);
return $this->returnDataMesage(
400,
'PDF Split failed !',
null,
$batchId,
null,
'File not found on our end, please try again'
);
}
} else {
$end = Carbon::parse(AppHelper::instance()->getCurrentTimeZone());
Expand Down
44 changes: 43 additions & 1 deletion app/Http/Controllers/Api/Core/watermarkController.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,23 @@ public function watermark(Request $request) {
$batchValue = false;
$str = rand(1000,10000000);
$randomizePdfFileName = 'pdfWatermark_'.substr(md5(uniqid($str)), 0, 8);
$loopCount = count($files);
$altPoolFiles = array();
foreach ($files as $file) {
$currentFileName = basename($file);
$trimPhase1 = str_replace(' ', '_', $currentFileName);
$newFileNameWithoutExtension = str_replace('.', '_', $trimPhase1);
$newFilePath = Storage::disk('local')->path('public/'.$pdfUpload_Location.'/'.$trimPhase1);
if (file_exists($newFilePath)) {
array_push($altPoolFiles, $newFileNameWithoutExtension);
}
}
if ($loopCount == count($altPoolFiles)) {
foreach ($files as $file) {
$currentFileName = basename($file);
$trimPhase1 = str_replace(' ', '_', $currentFileName);
$newFileNameWithoutExtension = str_replace('.', '_', $trimPhase1);
$newFilePath = Storage::disk('local')->path('public/'.$pdfUpload_Location.'/'.$trimPhase1);
$fileSize = filesize($newFilePath);
$procUuid = AppHelper::Instance()->generateUniqueUuid(watermarkModel::class, 'processId');
$newFileSize = AppHelper::instance()->convert($fileSize, "MB");
Expand Down Expand Up @@ -124,7 +135,7 @@ public function watermark(Request $request) {
if (empty($watermarkImage)) {
appLogModel::where('groupId', '=', $batchId)
->update([
'errReason' => 'PDF Watermark failed !',
'errReason' => 'PDF Watermark failed !',
'errStatus' => 'Image file for watermark can not be empty !'
]);
watermarkModel::where('groupId', '=', $batchId)
Expand Down Expand Up @@ -389,6 +400,37 @@ public function watermark(Request $request) {
);
}
}
} else {
$end = Carbon::parse(AppHelper::instance()->getCurrentTimeZone());
$duration = $end->diff($startProc);
appLogModel::where('groupId', '=', $batchId)
->update([
'errReason' => 'File not found on the server',
'errStatus' => 'File not found on our end, please try again'
]);
watermarkModel::where('groupId', '=', $batchId)
->update([
'result' => false,
'procEndAt' => AppHelper::instance()->getCurrentTimeZone(),
'procDuration' => $duration->s.' seconds'
]);
NotificationHelper::Instance()->sendErrNotify(
$currentFileName,
null,
$batchId,
'FAIL',
'compress',
'File not found on the server',
'File not found on our end, please try again'
);
return $this->returnDataMesage(
400,
'PDF Compression failed !',
null,
$batchId,
null,
'File not found on our end, please try again'
);
}
} else {
$end = Carbon::parse(AppHelper::instance()->getCurrentTimeZone());
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Api/Misc/versionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function versioningCheck(Request $request) {
$appServicesReferrerFE = $request->post('appServicesReferrer');
$appMajorVersionBE = 3;
$appMinorVersionBE = 5;
$appPatchVersionBE = 3;
$appPatchVersionBE = 5;
$appGitVersionBE = appHelper::instance()->getGitCommitHash();
$appVersioningBE = null;
$appVersioningFE = null;
Expand Down
Loading

0 comments on commit cfd8e3d

Please sign in to comment.