From 8ea1367a029bc3d6feefb2634e10b5f8c98b6605 Mon Sep 17 00:00:00 2001
From: Dominik Hebeler <dominik@suma-ev.de>
Date: Thu, 18 Jul 2024 16:43:34 +0200
Subject: [PATCH] load images through proxy

---
 metager/app/Models/Tile.php             | 11 +++++++++++
 metager/resources/js/startpage/tiles.js |  1 +
 2 files changed, 12 insertions(+)

diff --git a/metager/app/Models/Tile.php b/metager/app/Models/Tile.php
index 73e1de114..b64ff38b5 100644
--- a/metager/app/Models/Tile.php
+++ b/metager/app/Models/Tile.php
@@ -2,6 +2,10 @@
 
 namespace App\Models;
 
+use App\Http\Controllers\Pictureproxy;
+use Exception;
+use Request;
+
 /**
  * Model to hold data which represents a tile as visible on the startpage
  */
@@ -25,6 +29,13 @@ class Tile implements \JsonSerializable
     public function __construct(string $title, string $image, string $image_alt, string $url, string $classes = "", string $image_classes = "")
     {
         $this->title = $title;
+        try {
+            $host = parse_url($image, PHP_URL_HOST);
+            if ($host !== null && Request::host() !== $host) {
+                $image = Pictureproxy::generateUrl($image);
+            }
+        } catch (Exception $e) {
+        }
         $this->image = $image;
         $this->image_alt = $image_alt;
         $this->url = $url;
diff --git a/metager/resources/js/startpage/tiles.js b/metager/resources/js/startpage/tiles.js
index 71475b33f..cb6e9fd17 100644
--- a/metager/resources/js/startpage/tiles.js
+++ b/metager/resources/js/startpage/tiles.js
@@ -8,6 +8,7 @@
     async function fetchAdvertisements() {
         let desired_tile_count = calculateDesiredTileCount();
         let regular_tile_count = getRegularTileCount();
+        console.log(desired_tile_count, advertisements.length)
         if (advertisements.length >= desired_tile_count - regular_tile_count) return;
         let update_url = document.querySelector("meta[name=tiles-update-url]").content;
         update_url += "&count=" + (desired_tile_count - tile_count);
-- 
GitLab