|
1 | 1 | <?php |
| 2 | + |
2 | 3 | /** |
3 | 4 | * JUZAWEB CMS - Laravel CMS for Your Project |
4 | 5 | * |
|
20 | 21 | use Juzaweb\Modules\Admin\Networks\Facades\Network; |
21 | 22 | use Juzaweb\Modules\Core\Contracts\Viewable; |
22 | 23 | use Juzaweb\Modules\Core\Http\Controllers\Controller; |
| 24 | +use Juzaweb\Modules\Core\Services\ImgProxyService; |
23 | 25 |
|
24 | 26 | class AddonController extends Controller |
25 | 27 | { |
@@ -201,4 +203,46 @@ private function getMimeType(string $extension): string |
201 | 203 | default => 'application/octet-stream', |
202 | 204 | }; |
203 | 205 | } |
| 206 | + |
| 207 | + /** |
| 208 | + * Handle image proxy request |
| 209 | + */ |
| 210 | + public function proxy(string $methodParam, string $hash, Request $request, ImgProxyService $imgProxyService) |
| 211 | + { |
| 212 | + try { |
| 213 | + // Parse method and dimensions from methodParam (e.g., "resize:800x600") |
| 214 | + $method = $methodParam; |
| 215 | + $width = null; |
| 216 | + $height = null; |
| 217 | + |
| 218 | + if (str_contains($methodParam, ':')) { |
| 219 | + [$method, $size] = explode(':', $methodParam, 2); |
| 220 | + [$width, $height] = array_pad(explode('x', $size), 2, null); |
| 221 | + $width = $width === 'auto' ? null : (int)$width; |
| 222 | + $height = $height === 'auto' ? null : (int)$height; |
| 223 | + } |
| 224 | + |
| 225 | + // Handle image via service |
| 226 | + $result = $imgProxyService->handle($method, $hash, $width, $height); |
| 227 | + |
| 228 | + // Clear any output buffers |
| 229 | + while (ob_get_level() > 0) { |
| 230 | + ob_end_clean(); |
| 231 | + } |
| 232 | + |
| 233 | + // Return response with proper headers |
| 234 | + return response($result['data']) |
| 235 | + ->header('Content-Type', $result['contentType']) |
| 236 | + ->header('Content-Length', $result['contentLength']) |
| 237 | + ->header('X-Content-Type-Options', 'nosniff') |
| 238 | + ->header('X-Accel-Buffering', 'no') |
| 239 | + ->header('Cache-Control', 'public, max-age=31536000'); |
| 240 | + } catch (\InvalidArgumentException $e) { |
| 241 | + return response('Error: ' . $e->getMessage(), 400) |
| 242 | + ->header('Content-Type', 'text/plain'); |
| 243 | + } catch (\Throwable $e) { |
| 244 | + return response('Error: ' . $e->getMessage(), 500) |
| 245 | + ->header('Content-Type', 'text/plain'); |
| 246 | + } |
| 247 | + } |
204 | 248 | } |
0 commit comments