Apply code style
This commit is contained in:
@@ -62,7 +62,7 @@ class Enum
|
|||||||
*/
|
*/
|
||||||
public static function getMessage(int $messageIndex, string $defaultMessage = 'Unknown'): string
|
public static function getMessage(int $messageIndex, string $defaultMessage = 'Unknown'): string
|
||||||
{
|
{
|
||||||
if(array_key_exists($messageIndex, self::$messages) === true) {
|
if (array_key_exists($messageIndex, self::$messages) === true) {
|
||||||
return self::$messages[$messageIndex];
|
return self::$messages[$messageIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ class AttachmentController extends ApiController
|
|||||||
/**
|
/**
|
||||||
* Store a newly created resource in storage.
|
* Store a newly created resource in storage.
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Http\Request $request
|
* @param \Illuminate\Http\Request $request
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
public function store(Request $request)
|
public function store(Request $request)
|
||||||
@@ -40,7 +40,7 @@ class AttachmentController extends ApiController
|
|||||||
/**
|
/**
|
||||||
* Display the specified resource.
|
* Display the specified resource.
|
||||||
*
|
*
|
||||||
* @param \App\Models\Attachment $attachment
|
* @param \App\Models\Attachment $attachment
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
public function show(Attachment $attachment)
|
public function show(Attachment $attachment)
|
||||||
@@ -51,7 +51,7 @@ class AttachmentController extends ApiController
|
|||||||
/**
|
/**
|
||||||
* Show the form for editing the specified resource.
|
* Show the form for editing the specified resource.
|
||||||
*
|
*
|
||||||
* @param \App\Models\Attachment $attachment
|
* @param \App\Models\Attachment $attachment
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
public function edit(Attachment $attachment)
|
public function edit(Attachment $attachment)
|
||||||
@@ -62,11 +62,11 @@ class AttachmentController extends ApiController
|
|||||||
/**
|
/**
|
||||||
* Update the specified resource in storage.
|
* Update the specified resource in storage.
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Http\Request $request
|
* @param \Illuminate\Http\Request $request
|
||||||
* @param \App\Models\Attachment $attachment
|
* @param \App\Models\Attachment $attachment
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
public function update(Request $request, Attachment $attachment)
|
public function update(Request $request, Attachment $attachment)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
@@ -74,10 +74,10 @@ class AttachmentController extends ApiController
|
|||||||
/**
|
/**
|
||||||
* Remove the specified resource from storage.
|
* Remove the specified resource from storage.
|
||||||
*
|
*
|
||||||
* @param \App\Models\Attachment $attachment
|
* @param \App\Models\Attachment $attachment
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
public function destroy(Attachment $attachment)
|
public function destroy(Attachment $attachment)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ class OCRController extends ApiController
|
|||||||
$data = ['ocr' => []];
|
$data = ['ocr' => []];
|
||||||
|
|
||||||
$filters = $request->get('filters', ['tesseract']);
|
$filters = $request->get('filters', ['tesseract']);
|
||||||
if(is_array($filters) === false) {
|
if (is_array($filters) === false) {
|
||||||
$filters = explode(',', $filters);
|
$filters = explode(',', $filters);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,9 +52,12 @@ class OCRController extends ApiController
|
|||||||
// We need progress updates to break the connection mid-way
|
// We need progress updates to break the connection mid-way
|
||||||
curl_setopt($ch, CURLOPT_BUFFERSIZE, 128); // more progress info
|
curl_setopt($ch, CURLOPT_BUFFERSIZE, 128); // more progress info
|
||||||
curl_setopt($ch, CURLOPT_NOPROGRESS, false);
|
curl_setopt($ch, CURLOPT_NOPROGRESS, false);
|
||||||
curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, function(
|
curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, function (
|
||||||
$downloadSize, $downloaded, $uploadSize, $uploaded
|
$downloadSize,
|
||||||
) use($maxDownloadSize) {
|
$downloaded,
|
||||||
|
$uploadSize,
|
||||||
|
$uploaded
|
||||||
|
) use ($maxDownloadSize) {
|
||||||
return ($downloaded > $maxDownloadSize) ? 1 : 0;
|
return ($downloaded > $maxDownloadSize) ? 1 : 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -62,9 +65,9 @@ class OCRController extends ApiController
|
|||||||
$curlError = curl_errno($ch);
|
$curlError = curl_errno($ch);
|
||||||
$curlSize = curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD);
|
$curlSize = curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD);
|
||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
if($curlError !== 0) {
|
if ($curlError !== 0) {
|
||||||
$error = 'File size is larger then allowed';
|
$error = 'File size is larger then allowed';
|
||||||
if($curlError !== CurlErrorCodes::CURLE_ABORTED_BY_CALLBACK) {
|
if ($curlError !== CurlErrorCodes::CURLE_ABORTED_BY_CALLBACK) {
|
||||||
$error = CurlErrorCodes::getMessage($curlError);
|
$error = CurlErrorCodes::getMessage($curlError);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,8 +80,8 @@ class OCRController extends ApiController
|
|||||||
|
|
||||||
// tesseract (overall)
|
// tesseract (overall)
|
||||||
$ocr = null;
|
$ocr = null;
|
||||||
foreach($filters as $filterItem) {
|
foreach ($filters as $filterItem) {
|
||||||
if(str_starts_with($filterItem, 'tesseract') === true) {
|
if (str_starts_with($filterItem, 'tesseract') === true) {
|
||||||
$ocr = new TesseractOCR();
|
$ocr = new TesseractOCR();
|
||||||
$ocr->image($urlDownloadFilePath);
|
$ocr->image($urlDownloadFilePath);
|
||||||
if ($tesseractOEM !== null) {
|
if ($tesseractOEM !== null) {
|
||||||
@@ -95,11 +98,10 @@ class OCRController extends ApiController
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Image Filter Function
|
// Image Filter Function
|
||||||
$tesseractImageFilterFunc = function($filter, $options = null) use($curlResult, $curlSize, $ocr) {
|
$tesseractImageFilterFunc = function ($filter, $options = null) use ($curlResult, $curlSize, $ocr) {
|
||||||
$result = '';
|
$result = '';
|
||||||
$img = imagecreatefromstring($curlResult);
|
$img = imagecreatefromstring($curlResult);
|
||||||
if ($img !== false && (($options !== null && imagefilter($img, $filter, $options) === true) || ($options === null && imagefilter($img, $filter) === true))) {
|
if ($img !== false && (($options !== null && imagefilter($img, $filter, $options) === true) || ($options === null && imagefilter($img, $filter) === true))) {
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
imagepng($img);
|
imagepng($img);
|
||||||
$imgData = ob_get_contents();
|
$imgData = ob_get_contents();
|
||||||
@@ -116,7 +118,7 @@ class OCRController extends ApiController
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Image Scale Function
|
// Image Scale Function
|
||||||
$tesseractImageScaleFunc = function($scaleFunc) use ($curlResult, $ocr) {
|
$tesseractImageScaleFunc = function ($scaleFunc) use ($curlResult, $ocr) {
|
||||||
$result = '';
|
$result = '';
|
||||||
$srcImage = imagecreatefromstring($curlResult);
|
$srcImage = imagecreatefromstring($curlResult);
|
||||||
$srcWidth = imagesx($srcImage);
|
$srcWidth = imagesx($srcImage);
|
||||||
@@ -143,7 +145,7 @@ class OCRController extends ApiController
|
|||||||
};
|
};
|
||||||
|
|
||||||
// filter: tesseract
|
// filter: tesseract
|
||||||
if(in_array('tesseract', $filters) === true) {
|
if (in_array('tesseract', $filters) === true) {
|
||||||
$data['ocr']['tesseract'] = $ocr->run(500);
|
$data['ocr']['tesseract'] = $ocr->run(500);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,14 +156,14 @@ class OCRController extends ApiController
|
|||||||
|
|
||||||
// filter: tesseract.double_scale
|
// filter: tesseract.double_scale
|
||||||
if (in_array('tesseract.double_scale', $filters) === true) {
|
if (in_array('tesseract.double_scale', $filters) === true) {
|
||||||
$data['ocr']['tesseract.double_scale'] = $tesseractImageScaleFunc(function($size) {
|
$data['ocr']['tesseract.double_scale'] = $tesseractImageScaleFunc(function ($size) {
|
||||||
return $size * 2;
|
return $size * 2;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// filter: tesseract.half_scale
|
// filter: tesseract.half_scale
|
||||||
if (in_array('tesseract.half_scale', $filters) === true) {
|
if (in_array('tesseract.half_scale', $filters) === true) {
|
||||||
$data['ocr']['tesseract.half_scale'] = $tesseractImageScaleFunc(function($size) {
|
$data['ocr']['tesseract.half_scale'] = $tesseractImageScaleFunc(function ($size) {
|
||||||
return $size / 2;
|
return $size / 2;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -187,12 +189,12 @@ class OCRController extends ApiController
|
|||||||
}
|
}
|
||||||
|
|
||||||
// filter: keras
|
// filter: keras
|
||||||
if(in_array('keras', $filters) === true) {
|
if (in_array('keras', $filters) === true) {
|
||||||
$cmd = '/usr/bin/python3 ' . base_path() . '/scripts/keras_oc.py ' . urlencode($url);
|
$cmd = '/usr/bin/python3 ' . base_path() . '/scripts/keras_oc.py ' . urlencode($url);
|
||||||
$command = escapeshellcmd($cmd);
|
$command = escapeshellcmd($cmd);
|
||||||
$output = shell_exec($cmd);
|
$output = shell_exec($cmd);
|
||||||
if ($output !== null && strlen($output) > 0) {
|
if ($output !== null && strlen($output) > 0) {
|
||||||
$output = substr($output, strpos($output, '----------START----------') + 25);
|
$output = substr($output, (strpos($output, '----------START----------') + 25));
|
||||||
} else {
|
} else {
|
||||||
$output = '';
|
$output = '';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,8 @@ class SubscriptionController extends ApiController
|
|||||||
return $this->respondAsResource(
|
return $this->respondAsResource(
|
||||||
$collection,
|
$collection,
|
||||||
['isCollection' => true,
|
['isCollection' => true,
|
||||||
'appendData' => ['total' => $total]]
|
'appendData' => ['total' => $total]
|
||||||
|
]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ class Permission extends Model
|
|||||||
'user',
|
'user',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the User associated with this model
|
* Get the User associated with this model
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
@@ -6,6 +7,7 @@ class ContactFormTest extends TestCase
|
|||||||
{
|
{
|
||||||
use RefreshDatabase;
|
use RefreshDatabase;
|
||||||
|
|
||||||
|
|
||||||
public function testContactForm()
|
public function testContactForm()
|
||||||
{
|
{
|
||||||
$formData = [
|
$formData = [
|
||||||
|
|||||||
Reference in New Issue
Block a user