Browse Source

Use proxy and cached images on user info page

Timothy J. Warren 1 year ago
parent
commit
1df71121eb
4 changed files with 17 additions and 9 deletions
  1. 2
    1
      .gitignore
  2. 10
    5
      app/views/me.php
  3. 0
    0
      public/images/avatars/.gitkeep
  4. 5
    3
      src/Controller/Index.php

+ 2
- 1
.gitignore View File

@@ -13,7 +13,7 @@ composer.lock
13 13
 *.sqlite
14 14
 *.db
15 15
 *.sqlite3
16
-apidocs/*
16
+apidocs/**
17 17
 tests/test_data/sessions/*
18 18
 cache.properties
19 19
 build/**
@@ -27,5 +27,6 @@ phinx.yml
27 27
 Caddyfile
28 28
 build/humbuglog.txt
29 29
 public/images/anime/**
30
+public/images/avatars/**
30 31
 public/images/manga/**
31 32
 public/images/characters/**

+ 10
- 5
app/views/me.php View File

@@ -9,7 +9,12 @@
9 9
 						<?= $attributes['name'] ?>
10 10
 					</a>
11 11
 				</h2>
12
-				<img src="<?= $attributes['avatar']['original'] ?>" alt="" />
12
+				<?php
13
+					$file = basename(parse_url($attributes['avatar']['original'], \PHP_URL_PATH));
14
+					$parts = explode('.', $file);
15
+					$ext = end($parts);
16
+				?>
17
+				<img src="<?= $urlGenerator->assetUrl('images/avatars', "{$data['id']}.{$ext}") ?>" alt="" />
13 18
 			</center>
14 19
 			<br />
15 20
 			<br />
@@ -65,13 +70,13 @@
65 70
 				<?php if ( ! empty($favorites['characters'])): ?>
66 71
 					<h4>Favorite Characters</h4>
67 72
 					<section class="media-wrap">
68
-					<?php foreach($favorites['characters'] as $char): ?>
73
+					<?php foreach($favorites['characters'] as $id => $char): ?>
69 74
 						<?php if ( ! empty($char['image']['original'])): ?>
70 75
 						<article class="small_character">
71 76
 							<?php $link = $url->generate('character', ['slug' => $char['slug']]) ?>
72 77
 							<div class="name"><?= $helper->a($link, $char['name']); ?></div>
73 78
 							<a href="<?= $link ?>">
74
-							<?= $helper->img($char['image']['original']) ?>
79
+							<?= $helper->img($urlGenerator->assetUrl('images/characters', "{$char['id']}.jpg")) ?>
75 80
 							</a>
76 81
 						</article>
77 82
 						<?php endif ?>
@@ -88,7 +93,7 @@
88 93
 								$titles = Kitsu::filterTitles($anime);
89 94
 							?>
90 95
 							<a href="<?= $link ?>">
91
-								<img src="<?= $anime['posterImage']['small'] ?>" width="220" alt="" />
96
+								<img src="<?= $urlGenerator->assetUrl('images/anime', "{$anime['id']}.jpg") ?>" width="220" alt="" />
92 97
 							</a>
93 98
 							<div class="name">
94 99
 								<a href="<?= $link ?>">
@@ -112,7 +117,7 @@
112 117
 								$titles = Kitsu::filterTitles($manga);
113 118
 							?>
114 119
 							<a href="<?= $link ?>">
115
-								<img src="<?= $manga['posterImage']['small'] ?>" width="220" alt="" />
120
+								<img src="<?= $urlGenerator->assetUrl('images/manga', "{$manga['id']}.jpg") ?>" width="220" alt="" />
116 121
 							</a>
117 122
 							<div class="name">
118 123
 								<a href="<?= $link ?>">

+ 0
- 0
public/images/avatars/.gitkeep View File


+ 5
- 3
src/Controller/Index.php View File

@@ -134,6 +134,10 @@ class Index extends BaseController {
134 134
 				$kitsuUrl .= "anime/poster_images/{$id}/small.{$ext}";
135 135
 			break;
136 136
 
137
+			case 'avatars':
138
+				$kitsuUrl .= "users/avatars/{$id}/original.{$ext}";
139
+			break;
140
+
137 141
 			case 'manga':
138 142
 				$kitsuUrl .= "manga/poster_images/{$id}/small.{$ext}";
139 143
 			break;
@@ -164,8 +168,6 @@ class Index extends BaseController {
164 168
 
165 169
 		unset($rawfavorites['data']);
166 170
 
167
-		// dump($rawfavorites);
168
-
169 171
 		foreach($rawfavorites as $item)
170 172
 		{
171 173
 			$rank = $item['attributes']['favRank'];
@@ -174,7 +176,7 @@ class Index extends BaseController {
174 176
 				$output[$key] = $output[$key] ?? [];
175 177
 				foreach ($fav as $id => $data)
176 178
 				{
177
-					$output[$key][$rank] = $data['attributes'];
179
+					$output[$key][$rank] = array_merge(['id' => $id], $data['attributes']);
178 180
 				}
179 181
 			}
180 182