diff --git a/app/Http/Controllers/ImageProxyController.php b/app/Http/Controllers/ImageProxyController.php new file mode 100644 index 00000000..a6f881bb --- /dev/null +++ b/app/Http/Controllers/ImageProxyController.php @@ -0,0 +1,82 @@ +get('url'); + + if (!$url || !filter_var($url, FILTER_VALIDATE_URL)) { + Log::warning('ImageProxyController: Invalid URL provided', ['url' => $url]); + abort(400, 'Invalid URL'); + } + + $parsed = parse_url($url); + $host = $parsed['host'] ?? null; + + if (!$host) { + Log::warning('ImageProxyController: Invalid host', ['url' => $url]); + abort(400, 'Invalid host'); + } + + $cacheKey = 'image_proxy_' . md5($url); + + $cachedImage = Cache::get($cacheKey); + if ($cachedImage) { + Log::info('ImageProxyController: Serving cached image', ['url' => $url]); + return response($cachedImage['content'])->header('Content-Type', $cachedImage['content_type']); + } + + $timeout = config('image_proxy.default_timeout', 10); + try { + $response = Http::timeout($timeout)->get($url); + } catch (\Exception $e) { + Log::warning('ImageProxyController: External image request failed', [ + 'url' => $url, + 'error' => $e->getMessage() + ]); + abort(404, 'Image not found'); + } + + if (!$response->successful()) { + Log::warning('ImageProxyController: External image request failed', [ + 'url' => $url, + 'status' => $response->status() + ]); + abort(404, 'Image not found'); + } + + $content = $response->body(); + $contentType = $response->header('Content-Type') ?? ''; + + if (!str_starts_with($contentType, 'image/')) { + Log::warning('ImageProxyController: URL does not point to an image', [ + 'url' => $url, + 'content_type' => $contentType + ]); + abort(400, 'URL does not point to an image'); + } + + $maxCacheBytes = config('image_proxy.max_cache_bytes', self::MAX_CACHE_BYTES); + $bytes = strlen($content); + + if ($bytes <= $maxCacheBytes) { + Cache::put($cacheKey, ['content' => $content, 'content_type' => $contentType], config('image_proxy.cache_ttl', 3600)); + Log::info('ImageProxyController: Image cached and served', ['url' => $url, 'content_type' => $contentType, 'bytes' => $bytes]); + } else { + Log::warning('ImageProxyController: Skipping cache, payload too large', ['url' => $url, 'bytes' => $bytes, 'max' => $maxCacheBytes]); + } + + return response($content)->header('Content-Type', $contentType); + } +} \ No newline at end of file diff --git a/app/Policies/CustomCSPPolicy.php b/app/Policies/CustomCSPPolicy.php index 0b7cf006..2408ef28 100644 --- a/app/Policies/CustomCSPPolicy.php +++ b/app/Policies/CustomCSPPolicy.php @@ -24,7 +24,7 @@ public function configure() $this->addDirective(Directive::IMG, ['blob:']) ->addDirective(Directive::STYLE, ['unsafe-inline']); } - $this->addDirective(Directive::IMG, ['data:', 'https://tile.openstreetmap.org/']) + $this->addDirective(Directive::IMG, [Keyword::SELF, 'data:', 'https://tile.openstreetmap.org/']) ->addDirective(Directive::STYLE, [ // 'unsafe-inline', 'https://fonts.googleapis.com/', diff --git a/catatan_rilis.md b/catatan_rilis.md index 2ace5bc0..bf532140 100644 --- a/catatan_rilis.md +++ b/catatan_rilis.md @@ -1,4 +1,4 @@ -Di rilis ini, versi 2605.0.1 berisi penambahan dan perbaikan yang diminta pengguna. +Di rilis ini, versi 2606.0.0 berisi penambahan dan perbaikan yang diminta pengguna. #### Penambahan Fitur @@ -21,6 +21,7 @@ Di rilis ini, versi 2605.0.1 berisi penambahan dan perbaikan yang diminta penggu 1. [#1023](https://github.com/OpenSID/OpenKab/issues/1023) Percobaan login gagal terkadang error 500 2. [#1026](https://github.com/OpenSID/OpenKab/issues/1026) Perbaikan fungsi insert media dan gambar pada tinymce artikel 3. [#1032](https://github.com/OpenSID/OpenKab/issues/1032) Perbaikan Tombol enter refresh halaman di kategori artikel opensid +4. [#1037](https://github.com/OpenSID/OpenKab/issues/1037) Perbaikan Gambar desa aktif pada halaman website openkab masih statis #### Perubahan Teknis diff --git a/config/image_proxy.php b/config/image_proxy.php new file mode 100644 index 00000000..5f58bd56 --- /dev/null +++ b/config/image_proxy.php @@ -0,0 +1,12 @@ + 1024 * 1024 * 5, // 5MB + + 'default_timeout' => 10, + + 'cache_ttl' => 3600, + + 'enabled' => env('IMAGE_PROXY_ENABLED', true), +]; \ No newline at end of file diff --git a/resources/views/web/partials/property.blade.php b/resources/views/web/partials/property.blade.php index 56d450ef..56b36aae 100644 --- a/resources/views/web/partials/property.blade.php +++ b/resources/views/web/partials/property.blade.php @@ -16,7 +16,7 @@