32 lines
544 B
Go
32 lines
544 B
Go
package camera
|
|
|
|
import (
|
|
"axis_timelapse/config"
|
|
"os"
|
|
"strconv"
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
"github.com/rs/zerolog/log"
|
|
)
|
|
|
|
func CaptureImage() bool {
|
|
request := fiber.Get(config.FullURL)
|
|
|
|
code, body, err := request.Bytes()
|
|
if err != nil {
|
|
log.Error().Msgf("Error getting image.")
|
|
}
|
|
|
|
if code != 200 {
|
|
log.Error().Msg("Unexpected status code: " + strconv.Itoa(code))
|
|
}
|
|
|
|
// Write the bytes to a file
|
|
err1 := os.WriteFile("downloaded_image.jpg", body, 0644)
|
|
if err1 != nil {
|
|
log.Fatal().Err(err1).Msgf("")
|
|
}
|
|
|
|
return true
|
|
}
|