1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace AbterPhp\Admin\Http\Controllers\Api; |
6
|
|
|
|
7
|
|
|
use AbterPhp\Admin\Config\Routes; |
8
|
|
|
use AbterPhp\Framework\Constant\Env as FrameworkEnv; |
9
|
|
|
use AbterPhp\Website\Constant\Env as WebsiteEnv; |
|
|
|
|
10
|
|
|
use Opulence\Environments\Environment; |
11
|
|
|
use Opulence\Http\Responses\JsonResponse; |
12
|
|
|
use Opulence\Http\Responses\Response; |
13
|
|
|
use Opulence\Http\Responses\ResponseHeaders; |
14
|
|
|
use Opulence\Routing\Controller; |
15
|
|
|
|
16
|
|
|
class Editor extends Controller |
17
|
|
|
{ |
18
|
|
|
/** @var Routes */ |
19
|
|
|
protected $routes; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Editor constructor. |
23
|
|
|
* |
24
|
|
|
* @param Routes $routes |
25
|
|
|
*/ |
26
|
|
|
public function __construct(Routes $routes) |
27
|
|
|
{ |
28
|
|
|
$this->routes = $routes; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @return Response |
33
|
|
|
*/ |
34
|
|
|
public function fileUpload(): Response |
35
|
|
|
{ |
36
|
|
|
$actualClientId = explode(' ', $this->request->getHeaders()->get('authorization'))[1]; |
37
|
|
|
|
38
|
|
|
$expectedClientId = Environment::getVar(FrameworkEnv::CRYPTO_CLIENT_ID); |
|
|
|
|
39
|
|
|
if ($actualClientId != $expectedClientId) { |
40
|
|
|
$response = new JsonResponse( |
41
|
|
|
[ |
42
|
|
|
'success' => false, |
43
|
|
|
'status' => ResponseHeaders::HTTP_FORBIDDEN, |
44
|
|
|
], |
45
|
|
|
ResponseHeaders::HTTP_FORBIDDEN |
46
|
|
|
); |
47
|
|
|
$response->send(); |
48
|
|
|
|
49
|
|
|
return $response; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
$image = $this->request->getFiles()->get('image'); |
53
|
|
|
if ($image->hasErrors()) { |
54
|
|
|
$response = new JsonResponse( |
55
|
|
|
[ |
56
|
|
|
'success' => false, |
57
|
|
|
'status' => ResponseHeaders::HTTP_INTERNAL_SERVER_ERROR, |
58
|
|
|
], |
59
|
|
|
ResponseHeaders::HTTP_INTERNAL_SERVER_ERROR |
60
|
|
|
); |
61
|
|
|
$response->send(); |
62
|
|
|
|
63
|
|
|
return $response; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
$basePath = mb_substr(basename($image->getPathname()), 3); |
67
|
|
|
$extension = pathinfo($image->getTempFilename())['extension']; |
68
|
|
|
$filename = sprintf('%s.%s', $basePath, $extension); |
69
|
|
|
|
70
|
|
|
$path = sprintf('%s/editor-file-upload', Environment::getVar(FrameworkEnv::DIR_PUBLIC)); |
71
|
|
|
$url = Environment::getVar(WebsiteEnv::WEBSITE_BASE_URL) . 'editor-file-upload/' . $filename; |
72
|
|
|
|
73
|
|
|
$image->move($path, $filename); |
74
|
|
|
|
75
|
|
|
$response = new JsonResponse( |
76
|
|
|
[ |
77
|
|
|
'data' => ['url' => $url], |
78
|
|
|
'success' => true, |
79
|
|
|
'status' => ResponseHeaders::HTTP_OK, |
80
|
|
|
], |
81
|
|
|
ResponseHeaders::HTTP_OK |
82
|
|
|
); |
83
|
|
|
$response->send(); |
84
|
|
|
|
85
|
|
|
return $response; |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths