<aside> ⚠️ user fetched tweetpic img url → (img.src = tweetpicUrl )→ dom <img> rerendered → screenshoted image still in the process on the back-end → user got error file not found
</aside>
We should wait for the retrieved image URL from the backend on the front end by delaying the re-rendering of the img (changing img.src) element for a couple of seconds. If we don't, it will result in 504 ( File Not found ) when the browser tries to fetch the image, because we are faster than the screenshot service in producing the screenshot image.
or
the other way is we could combine that solution with something like this, this was suggested by claude.ai.
func serveImage(c *fiber.Ctx) error {
imageName := c.Query("name")
if imageName == "" {
return fiber.NewError(fiber.StatusBadRequest, "Image name not specified")
}
imagePath := filepath.Join("./images", filepath.Clean(imageName))
// Check if the file exists
if _, err := os.Stat(imagePath); os.IsNotExist(err) {
// If the file doesn't exist, return a "processing" or placeholder image
return c.SendFile("./images/processing.png")
}
return c.SendFile(imagePath)
}
we would return a ‘placeholder’ image if the image not found or when it still in the process. this could make a good ux even after we forcefulluy coded to the client website to wait for couple seconds, there could be the case if the image still in the process and not found after that timespan.