function photoManager() { return { photos: [], isPlaying: false, // Default with immich frame hiddenPhotosCount: 5, maxPhotosToShow: 25, getVisiblePhotos() { return this.photos.length > this.hiddenPhotosCount ? this.photos.slice(this.hiddenPhotosCount, this.photos.length) : this.photos; }, init() { const eventSource = new EventSource("/api/photos"); eventSource.onmessage = (event) => { if (event.data.includes("Heartbeat")) return; // Parse the incoming photo data const newPhoto = JSON.parse(event.data); this.photos.push(newPhoto); this.photos.sort((a, b) => new Date(b.rawDate) - new Date(a.rawDate)); // Limit the number of photos to maxPhotosToShow + hiddenPhotosCount const max = this.maxPhotosToShow + this.hiddenPhotosCount; if (this.photos.length > max) { // Remove oldest photos this.photos.splice(max, this.photos.length - max); } }; }, togglePlayback() { fetch("/api/pause", { method: "POST", }) .catch((err) => { console.error("Failed to toggle playback", err); }) .then(() => { this.isPlaying = !this.isPlaying; }); }, deletePhoto(photoId) { if (confirm("Are you sure you want to delete this photo?")) { // TODO: } }, openInImmich(photoUrl) { window.open(photoUrl, "_blank"); }, handleImageError(event) { event.target.src = "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjAwIiBoZWlnaHQ9IjIwMCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cmVjdCB3aWR0aD0iMTAwJSIgaGVpZ2h0PSIxMDAlIiBmaWxsPSIjZjBmMGYwIi8+PHRleHQgeD0iNTAlIiB5PSI1MCUiIGZvbnQtc2l6ZT0iMTQiIGZpbGw9IiM5OTkiIHRleHQtYW5jaG9yPSJtaWRkbGUiIGR5PSIuM2VtIj5JbWFnZSBub3QgZm91bmQ8L3RleHQ+PC9zdmc+"; }, }; }