Skip to content

Commit

Permalink
Merge pull request #17 from WaterWolfDev/dev.waterwolf.club
Browse files Browse the repository at this point in the history
Minor S3-related performance bump.
  • Loading branch information
BusterNeece authored Apr 3, 2024
2 parents 75d6ec1 + d94d787 commit 06c6f60
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 17 deletions.
26 changes: 12 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,15 @@ make bash-root

Static assets used by the web site are stored inside this repository and can be referenced directly via `/static` links.

User-uploaded content should instead be stored in the media storage subsystem, which resolves in
production to `media.waterwolf.town`.

`media.waterwolf.town` structure.
- site/ -> `# Website assets`
- css/
- js/
- img/
- video/
- uploads/ -> `# User generated assets`
- public/ -> `# Long-term file sharing`
- unity/
- video/
- img/
User-uploaded content is stored in `/web/media/site` in local development and in a Cloudflare R2 repository in
production, which resolves to `uploads.waterwolf.club`.

`uploads.waterwolf.club` structure:

```
img/
djs/ # DJ Avatars
posters/ # Posters
profile/ # Main Avatars
worlds/ # World screenshots
```
20 changes: 17 additions & 3 deletions backend/src/Controller/Dashboard/PostersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Doctrine\DBAL\ArrayParameterType;
use Doctrine\DBAL\Connection;
use Intervention\Image\ImageManager;
use League\Flysystem\StorageAttributes;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UploadedFileInterface;

Expand Down Expand Up @@ -69,18 +70,31 @@ public function listAction(

$nowDt = new \DateTimeImmutable('now', new \DateTimeZone('UTC'));

// Iterate files in the poster uploads directory once to avoid a bunch of repeat calls.
$fs = Media::getFilesystem();

$posterFiles = [];

/** @var StorageAttributes $posterFile */
foreach ($fs->listContents('img/posters/') as $posterFile) {
if (!$posterFile->isFile()) {
continue;
}

$posterFiles[$posterFile->path()] = $posterFile->path();
}

foreach ($qb->fetchAllAssociative() as $poster) {
// Get poster URL
$tryMediaUrls = [
'/img/posters/' . urlencode($poster['file']) . '_thumb.jpg',
'/img/posters/' . urlencode($poster['file']) . '_150x200.jpeg',
'img/posters/' . urlencode($poster['file']) . '_thumb.jpg',
'img/posters/' . urlencode($poster['file']) . '_150x200.jpeg',
];

$mediaUrl = '/static/img/no_poster_thumb.jpg';

foreach ($tryMediaUrls as $tryMediaUrl) {
if ($fs->has($tryMediaUrl)) {
if (isset($posterFiles[$tryMediaUrl])) {
$mediaUrl = mediaUrl($tryMediaUrl);
break;
}
Expand Down

0 comments on commit 06c6f60

Please sign in to comment.