Skip to content

Commit

Permalink
v3.6.7 20250105 [Backend Module] (#307)
Browse files Browse the repository at this point in the history
## Background
As users, i want to preview or see thumbnail for every task or upload.
In current condition when i upload any document or spreadsheet. No
thumbnail was loaded or processed, but fine on other files like PDF and
image.

## Current condition
Since almost all controller already moved to min.io for data storage and
not stored anymore on local, somehow thumbnail controller are not
following changes and result thumbnail can't be processed at all

## Next condition
Properly store and generate temporary URL from min.io to generate and
served back to front-end services after processing
  • Loading branch information
Nicklas373 authored Jan 5, 2025
2 parents b4c0fd8 + 767310d commit c97ee7f
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 80 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,4 @@ The HANA PDF is a open source Laravel Project that has licensed under the [MIT l

---

## HANA-CI Build Project 2016 - 2024
## HANA-CI Build Project 2016 - 2025
3 changes: 1 addition & 2 deletions app/Http/Controllers/Api/File/fileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function upload(Request $request) {
201,
'File uploaded successfully !',
Storage::disk('minio')->exists($pdfUpload_Location.'/'.$pdfFileName),
null
null,
);
} else {
return $this->returnFileMesage(
Expand All @@ -103,7 +103,6 @@ public function upload(Request $request) {
$e->getMessage()
);
}

} else {
return $this->returnFileMesage(
400,
Expand Down
64 changes: 50 additions & 14 deletions app/Http/Controllers/Api/File/thumbnailController.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,24 @@ public function getThumbnail(Request $request)
$pdfUpload_Location = env('PDF_UPLOAD');
$pdfPool_Location = env('PDF_POOL');
$currentFileName = basename($files);
$pdfFileName = str_replace(' ', '_', $currentFileName);
$pdfRealExtension = pathinfo($pdfFileName, PATHINFO_EXTENSION);
$newFilePath = Storage::disk('local')->path('public/'.$pdfUpload_Location.'/'.$pdfFileName);
$thumbnailFilePath = Storage::disk('local')->path('public/'.$pdfThumbnail_Location.'/'.$pdfFileName.'.png');
$trimPhase1 = str_replace(' ', '_', $currentFileName);
$newFileNameWithoutExtension = str_replace('.', '_', $trimPhase1);
$pdfRealExtension = pathinfo($currentFileName, PATHINFO_EXTENSION);
$pdfRealName = pathinfo($trimPhase1, PATHINFO_FILENAME);
$newFormattedFilename = str_replace('_'.$pdfRealExtension, '', $newFileNameWithoutExtension);
$minioUpload = Storage::disk('minio')->get($pdfUpload_Location.'/'.$trimPhase1);
if (Storage::disk('local')->exists('public/'.$pdfUpload_Location.'/'.$newFormattedFilename.'.'.$pdfRealExtension)) {
Storage::disk('local')->delete('public/'.$pdfUpload_Location.'/'.$newFormattedFilename.'.'.$pdfRealExtension);
}
file_put_contents(Storage::disk('local')->path('public/'.$pdfUpload_Location.'/'.$newFormattedFilename.'.'.$pdfRealExtension), $minioUpload);
$newFilePath = Storage::disk('local')->path('public/'.$pdfUpload_Location.'/'.$newFormattedFilename.'.'.$pdfRealExtension);
$thumbnailFilePath = Storage::disk('local')->path('public/'.$pdfThumbnail_Location.'/'.$pdfRealName.'.png');
try {
ini_set("pcre.backtrack_limit", "5000000");
Settings::setPdfRendererPath(base_path('vendor/mpdf/mpdf'));
Settings::setPdfRendererName('MPDF');

$pdfPath = Storage::disk('local')->path('public/'.$pdfPool_Location.'/'.$pdfFileName);
$pdfPath = Storage::disk('local')->path('public/'.$pdfPool_Location.'/'.$newFormattedFilename.'.'.$pdfRealExtension);
if ($pdfRealExtension == 'docx' || $pdfRealExtension == 'doc') {
$phpWord = WordIOFactory::load($newFilePath);
$phpWord->save($pdfPath, 'PDF');
Expand All @@ -60,7 +69,7 @@ public function getThumbnail(Request $request)
return $this->returnFileMesage(
400,
'Failed to generate thumbnail !',
$pdfFileName,
$pdfRealName,
'Invalid or unsupported file extension: '.$pdfRealExtension
);
}
Expand All @@ -69,18 +78,45 @@ public function getThumbnail(Request $request)
->format(\Spatie\PdfToImage\Enums\OutputFormat::Png)
->quality(90)
->save($thumbnailFilePath);
return $this->returnFileMesage(
201,
'Thumbnail generated !',
Storage::disk('local')->url(env('PDF_IMG_POOL').'/'.$pdfFileName.'.png'),
$pdfFileName
);
if (Storage::disk('local')->exists('public/'.$pdfThumbnail_Location.'/'.$pdfRealName.'.png')) {
Storage::disk('minio')->put($pdfThumbnail_Location.'/'.$pdfRealName.'.png', file_get_contents($thumbnailFilePath));
Storage::disk('local')->delete('public/'.$pdfThumbnail_Location.'/'.$pdfRealName.'.png');
Storage::disk('local')->delete('public/'.$pdfPool_Location.'/'.$newFormattedFilename.'.'.$pdfRealExtension);
try {
if (Storage::disk('minio')->exists($pdfThumbnail_Location.'/'.$pdfRealName.'.png')) {
return $this->returnFileMesage(
201,
'Thumbnail generated !',
Storage::disk('minio')->temporaryUrl(
env('PDF_IMG_POOL').'/'.$pdfRealName.'.png',
now()->addMinutes(5)
),
Storage::disk('local')->url(env('PDF_IMG_POOL').'/'.$pdfRealName.'.png'),
null,
);
} else {
return $this->returnFileMesage(
400,
'Failed to upload file !',
$pdfFileName,
$pdfFileName.' could not be found in the object storage'
);
}
} catch (\Exception $e) {
return $this->returnFileMesage(
400,
'Failed to upload thumbnail to object storage !',
$pdfFileName,
$e->getMessage()
);
}
}
} catch (Exception $e) {
return $this->returnFileMesage(
500,
'Failed to generate thumbnail !',
$pdfFileName,
$pdfFileName.' could not generate thumbnail with error: '.$e->getMessage()
$pdfRealName,
'Could not generate thumbnail with error: '.$e->getMessage()
);
}
}
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 @@ -42,7 +42,7 @@ public function versioningCheck(Request $request) {
$appServicesReferrerFE = $request->post('appServicesReferrer');
$appMajorVersionBE = 3;
$appMinorVersionBE = 6;
$appPatchVersionBE = 5;
$appPatchVersionBE = 7;
$appVersioningBE = null;
$appVersioningFE = null;
$appServicesReferrerBE = "BE";
Expand Down
Loading

0 comments on commit c97ee7f

Please sign in to comment.