Skip to content

Commit c97ee7f

Browse files
authored
v3.6.7 20250105 [Backend Module] (#307)
## 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
2 parents b4c0fd8 + 767310d commit c97ee7f

File tree

5 files changed

+114
-80
lines changed

5 files changed

+114
-80
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,4 @@ The HANA PDF is a open source Laravel Project that has licensed under the [MIT l
7171

7272
---
7373

74-
## HANA-CI Build Project 2016 - 2024
74+
## HANA-CI Build Project 2016 - 2025

app/Http/Controllers/Api/File/fileController.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public function upload(Request $request) {
8585
201,
8686
'File uploaded successfully !',
8787
Storage::disk('minio')->exists($pdfUpload_Location.'/'.$pdfFileName),
88-
null
88+
null,
8989
);
9090
} else {
9191
return $this->returnFileMesage(
@@ -103,7 +103,6 @@ public function upload(Request $request) {
103103
$e->getMessage()
104104
);
105105
}
106-
107106
} else {
108107
return $this->returnFileMesage(
109108
400,

app/Http/Controllers/Api/File/thumbnailController.php

+50-14
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,24 @@ public function getThumbnail(Request $request)
3939
$pdfUpload_Location = env('PDF_UPLOAD');
4040
$pdfPool_Location = env('PDF_POOL');
4141
$currentFileName = basename($files);
42-
$pdfFileName = str_replace(' ', '_', $currentFileName);
43-
$pdfRealExtension = pathinfo($pdfFileName, PATHINFO_EXTENSION);
44-
$newFilePath = Storage::disk('local')->path('public/'.$pdfUpload_Location.'/'.$pdfFileName);
45-
$thumbnailFilePath = Storage::disk('local')->path('public/'.$pdfThumbnail_Location.'/'.$pdfFileName.'.png');
42+
$trimPhase1 = str_replace(' ', '_', $currentFileName);
43+
$newFileNameWithoutExtension = str_replace('.', '_', $trimPhase1);
44+
$pdfRealExtension = pathinfo($currentFileName, PATHINFO_EXTENSION);
45+
$pdfRealName = pathinfo($trimPhase1, PATHINFO_FILENAME);
46+
$newFormattedFilename = str_replace('_'.$pdfRealExtension, '', $newFileNameWithoutExtension);
47+
$minioUpload = Storage::disk('minio')->get($pdfUpload_Location.'/'.$trimPhase1);
48+
if (Storage::disk('local')->exists('public/'.$pdfUpload_Location.'/'.$newFormattedFilename.'.'.$pdfRealExtension)) {
49+
Storage::disk('local')->delete('public/'.$pdfUpload_Location.'/'.$newFormattedFilename.'.'.$pdfRealExtension);
50+
}
51+
file_put_contents(Storage::disk('local')->path('public/'.$pdfUpload_Location.'/'.$newFormattedFilename.'.'.$pdfRealExtension), $minioUpload);
52+
$newFilePath = Storage::disk('local')->path('public/'.$pdfUpload_Location.'/'.$newFormattedFilename.'.'.$pdfRealExtension);
53+
$thumbnailFilePath = Storage::disk('local')->path('public/'.$pdfThumbnail_Location.'/'.$pdfRealName.'.png');
4654
try {
55+
ini_set("pcre.backtrack_limit", "5000000");
4756
Settings::setPdfRendererPath(base_path('vendor/mpdf/mpdf'));
4857
Settings::setPdfRendererName('MPDF');
4958

50-
$pdfPath = Storage::disk('local')->path('public/'.$pdfPool_Location.'/'.$pdfFileName);
59+
$pdfPath = Storage::disk('local')->path('public/'.$pdfPool_Location.'/'.$newFormattedFilename.'.'.$pdfRealExtension);
5160
if ($pdfRealExtension == 'docx' || $pdfRealExtension == 'doc') {
5261
$phpWord = WordIOFactory::load($newFilePath);
5362
$phpWord->save($pdfPath, 'PDF');
@@ -60,7 +69,7 @@ public function getThumbnail(Request $request)
6069
return $this->returnFileMesage(
6170
400,
6271
'Failed to generate thumbnail !',
63-
$pdfFileName,
72+
$pdfRealName,
6473
'Invalid or unsupported file extension: '.$pdfRealExtension
6574
);
6675
}
@@ -69,18 +78,45 @@ public function getThumbnail(Request $request)
6978
->format(\Spatie\PdfToImage\Enums\OutputFormat::Png)
7079
->quality(90)
7180
->save($thumbnailFilePath);
72-
return $this->returnFileMesage(
73-
201,
74-
'Thumbnail generated !',
75-
Storage::disk('local')->url(env('PDF_IMG_POOL').'/'.$pdfFileName.'.png'),
76-
$pdfFileName
77-
);
81+
if (Storage::disk('local')->exists('public/'.$pdfThumbnail_Location.'/'.$pdfRealName.'.png')) {
82+
Storage::disk('minio')->put($pdfThumbnail_Location.'/'.$pdfRealName.'.png', file_get_contents($thumbnailFilePath));
83+
Storage::disk('local')->delete('public/'.$pdfThumbnail_Location.'/'.$pdfRealName.'.png');
84+
Storage::disk('local')->delete('public/'.$pdfPool_Location.'/'.$newFormattedFilename.'.'.$pdfRealExtension);
85+
try {
86+
if (Storage::disk('minio')->exists($pdfThumbnail_Location.'/'.$pdfRealName.'.png')) {
87+
return $this->returnFileMesage(
88+
201,
89+
'Thumbnail generated !',
90+
Storage::disk('minio')->temporaryUrl(
91+
env('PDF_IMG_POOL').'/'.$pdfRealName.'.png',
92+
now()->addMinutes(5)
93+
),
94+
Storage::disk('local')->url(env('PDF_IMG_POOL').'/'.$pdfRealName.'.png'),
95+
null,
96+
);
97+
} else {
98+
return $this->returnFileMesage(
99+
400,
100+
'Failed to upload file !',
101+
$pdfFileName,
102+
$pdfFileName.' could not be found in the object storage'
103+
);
104+
}
105+
} catch (\Exception $e) {
106+
return $this->returnFileMesage(
107+
400,
108+
'Failed to upload thumbnail to object storage !',
109+
$pdfFileName,
110+
$e->getMessage()
111+
);
112+
}
113+
}
78114
} catch (Exception $e) {
79115
return $this->returnFileMesage(
80116
500,
81117
'Failed to generate thumbnail !',
82-
$pdfFileName,
83-
$pdfFileName.' could not generate thumbnail with error: '.$e->getMessage()
118+
$pdfRealName,
119+
'Could not generate thumbnail with error: '.$e->getMessage()
84120
);
85121
}
86122
}

app/Http/Controllers/Api/Misc/versionController.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function versioningCheck(Request $request) {
4242
$appServicesReferrerFE = $request->post('appServicesReferrer');
4343
$appMajorVersionBE = 3;
4444
$appMinorVersionBE = 6;
45-
$appPatchVersionBE = 5;
45+
$appPatchVersionBE = 7;
4646
$appVersioningBE = null;
4747
$appVersioningFE = null;
4848
$appServicesReferrerBE = "BE";

0 commit comments

Comments
 (0)