1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Yeelight\Http\Controllers; |
4
|
|
|
|
5
|
|
|
use Exception; |
6
|
|
|
use Illuminate\Http\Request; |
7
|
|
|
use Yeelight\Services\Image\Controllers\YeelightImageController; |
8
|
|
|
use Yeelight\Services\Image\YeelightImageService; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class ImageController |
12
|
|
|
* |
13
|
|
|
* @category Yeelight |
14
|
|
|
* |
15
|
|
|
* @package Yeelight\Http\Controllers |
16
|
|
|
* |
17
|
|
|
* @author Sheldon Lee <[email protected]> |
18
|
|
|
* |
19
|
|
|
* @license https://opensource.org/licenses/MIT MIT |
20
|
|
|
* |
21
|
|
|
* @link https://www.yeelight.com |
22
|
|
|
*/ |
23
|
|
|
class ImageController extends BaseController |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* PostImage |
27
|
|
|
* |
28
|
|
|
* @param Request $request Request |
29
|
|
|
* |
30
|
|
|
* @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response |
31
|
|
|
*/ |
32
|
|
|
public function postImage(Request $request) |
33
|
|
|
{ |
34
|
|
|
$yeelightImageService = new YeelightImageService(); |
35
|
|
|
$file = $request->file('image'); |
36
|
|
|
|
37
|
|
|
$yeelightImage = null; |
|
|
|
|
38
|
|
|
|
39
|
|
|
try { |
40
|
|
|
// @var YeelightImage $yeelightImage |
41
|
|
|
$yeelightImage = $yeelightImageService->handleUploadedFile($file); |
42
|
|
|
} catch (Exception $e) { |
43
|
|
|
return response('Failed to save: '.$e->getMessage(), 422); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
if (!$yeelightImage) { |
|
|
|
|
47
|
|
|
return response('Failed to save uploaded image.', 422); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
//$yeelightImageId = $yeelightImage->getYeelightImageId(); |
51
|
|
|
|
52
|
|
|
return response([ |
|
|
|
|
53
|
|
|
'data' => [ |
54
|
|
|
'yeelight_image_id' => $yeelightImage->getYeelightImageId(), |
55
|
|
|
'yeelight_image_url' => $yeelightImage->getImageUrl(), |
56
|
|
|
'thumbnail_image_url' => $yeelightImage->getTypeImageUrl('thumbnail'), |
57
|
|
|
], |
58
|
|
|
]); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* ShowOriginalImage |
63
|
|
|
* |
64
|
|
|
* @param string $imageName imageName |
65
|
|
|
* |
66
|
|
|
* @return mixed|\Symfony\Component\HttpFoundation\BinaryFileResponse |
67
|
|
|
*/ |
68
|
|
|
public function showOriginalImage($imageName) |
69
|
|
|
{ |
70
|
|
|
return YeelightImageController::showImage('original', $imageName); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* ShowTypeImage |
75
|
|
|
* |
76
|
|
|
* @param string $type type |
77
|
|
|
* @param string $imageName imageName |
78
|
|
|
* |
79
|
|
|
* @return mixed|\Symfony\Component\HttpFoundation\BinaryFileResponse |
80
|
|
|
*/ |
81
|
|
|
public function showTypeImage($type, $imageName) |
82
|
|
|
{ |
83
|
|
|
return YeelightImageController::showImage($type, $imageName); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|