func DownloadPhotoByID()

in cobra/aid/unsplash.go [108:151]


func DownloadPhotoByID(r model.UnsplashGetPhotoResponse, size string) error {
	dirPath, err := helper.CreateDirectoryNamedPath("downloads/unsplash/" + r.ID)
	if err != nil {
		return err
	}

	if size == "raw" || size == "all" {
		err = helper.DownloadFile(r.Urls.Raw, dirPath, r.ID+"-raw.jpeg")
		if err != nil {
			return fmt.Errorf("unable to download photo\n%v", err)
		}
	}

	if size == "full" || size == "all" {
		err = helper.DownloadFile(r.Urls.Full, dirPath, r.ID+"-full.jpeg")
		if err != nil {
			return fmt.Errorf("unable to download photo\n%v", err)
		}
	}

	if size == "regular" || size == "all" {
		err = helper.DownloadFile(r.Urls.Regular, dirPath, r.ID+"-regular.jpeg")
		if err != nil {
			return fmt.Errorf("unable to download photo\n%v", err)
		}
	}

	if size == "small" || size == "all" {
		err = helper.DownloadFile(r.Urls.Small, dirPath, r.ID+"-small.jpeg")
		if err != nil {
			return fmt.Errorf("unable to download photo\n%v", err)
		}
	}

	if size == "thumb" || size == "all" {
		err = helper.DownloadFile(r.Urls.Thumb, dirPath, r.ID+"-thumb.jpeg")
		if err != nil {
			return fmt.Errorf("unable to download photo\n%v", err)
		}
	}

	return err

}