Skip to content

Commit 3c8f80d

Browse files
authored
Merge pull request #140 from remcovanmook/fix/images-origin
fix(frontend): serve logos from the R2 mirror again
2 parents dbba310 + 4752131 commit 3c8f80d

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

‎frontend/js/config.js.example‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@ export const AUTH_ORIGIN = 'https://auth.<your-domain>';
44
/** Origin of the pdbfe-api worker (no trailing slash). */
55
export const API_ORIGIN = 'https://api.<your-domain>';
66

7-
/** Public R2 bucket origin for mirrored entity logos (no trailing slash). Empty to use upstream logos. */
8-
export const IMAGES_ORIGIN = '';
7+
/**
8+
* Public R2 bucket origin for mirrored entity logos (no trailing slash).
9+
* Also enables the pdbfe extension fields (__pdbfe=1) that carry
10+
* __logo_migrated. Set to '' to use upstream S3 logos only.
11+
*/
12+
export const IMAGES_ORIGIN = 'https://images.<your-domain>';
913

1014
/** S3 URL prefix to strip when building R2 logo paths. */
1115
export const S3_MEDIA_PREFIX = 'https://peeringdb-media-prod.s3.amazonaws.com/media/';

‎frontend/js/render.js‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,10 +622,16 @@ export function createDetailLayout(opts) {
622622
// Attach handlers BEFORE setting src — cached images fire
623623
// load synchronously and would be missed otherwise.
624624
logo.onload = () => { logo.style.display = ''; };
625-
logo.onerror = () => { logo.remove(); };
626625
if (IMAGES_ORIGIN && opts.logoMigrated && opts.logoUrl.startsWith(S3_MEDIA_PREFIX)) {
626+
// R2 mirror first; if it misses, fall back to the upstream URL once.
627+
const upstream = opts.logoUrl;
628+
logo.onerror = () => {
629+
logo.onerror = () => { logo.remove(); };
630+
logo.src = upstream;
631+
};
627632
logo.src = `${IMAGES_ORIGIN}/${opts.logoUrl.slice(S3_MEDIA_PREFIX.length)}`;
628633
} else {
634+
logo.onerror = () => { logo.remove(); };
629635
logo.src = opts.logoUrl;
630636
}
631637

0 commit comments

Comments
 (0)