34 lines
615 B
Go
34 lines
615 B
Go
package camera
|
|
|
|
import (
|
|
"axis_timelapse/config"
|
|
"os"
|
|
"strconv"
|
|
"time"
|
|
|
|
"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))
|
|
}
|
|
|
|
timestamp := time.Now()
|
|
filename := timestamp.Format("/axis-2006-01-02_15-04-05.jpg")
|
|
err1 := os.WriteFile(config.StoragePath+filename, body, 0644)
|
|
if err1 != nil {
|
|
log.Fatal().Err(err1).Msgf("")
|
|
}
|
|
|
|
return true
|
|
}
|