fix: enhance image loading logic to handle static paths when sockets are unavailable

This commit is contained in:
sebseb7
2025-07-20 01:28:36 +02:00
parent ca98c304e5
commit bdd50770be

View File

@@ -52,8 +52,13 @@ class Images extends Component {
pics.push(bildId); pics.push(bildId);
this.loadPic(this.props.fullscreenOpen ? 'large' : 'medium',bildId,newMainPic); this.loadPic(this.props.fullscreenOpen ? 'large' : 'medium',bildId,newMainPic);
}else{ }else{
pics.push(bildId); // For prerender or when sockets unavailable, use static path
this.loadPic(this.props.fullscreenOpen ? 'large' : 'medium',bildId,newMainPic); if (!this.props.socket && !this.props.socketB) {
pics.push(`/assets/images/prod${bildId}.jpg`);
} else {
pics.push(bildId);
this.loadPic(this.props.fullscreenOpen ? 'large' : 'medium',bildId,newMainPic);
}
} }
}else{ }else{
if(window.tinyPicCache[bildId]){ if(window.tinyPicCache[bildId]){
@@ -62,8 +67,13 @@ class Images extends Component {
pics.push(window.mediumPicCache[bildId]); pics.push(window.mediumPicCache[bildId]);
this.loadPic('tiny',bildId,newMainPic); this.loadPic('tiny',bildId,newMainPic);
}else{ }else{
pics.push(null); // For prerender or when sockets unavailable, use static path
this.loadPic('tiny',bildId,pics.length-1); if (!this.props.socket && !this.props.socketB) {
pics.push(`/assets/images/prod${bildId}.jpg`);
} else {
pics.push(null);
this.loadPic('tiny',bildId,pics.length-1);
}
} }
} }
} }
@@ -75,6 +85,9 @@ class Images extends Component {
} }
loadPic = (size,bildId,index) => { loadPic = (size,bildId,index) => {
// Skip loading if sockets are not available (e.g., during prerender)
if (!this.props.socketB) return;
this.props.socketB.emit('getPic', { bildId, size }, (res) => { this.props.socketB.emit('getPic', { bildId, size }, (res) => {
if(res.success){ if(res.success){
const url = URL.createObjectURL(new Blob([res.imageBuffer], { type: 'image/jpeg' })); const url = URL.createObjectURL(new Blob([res.imageBuffer], { type: 'image/jpeg' }));