Documentation
¶
Index ¶
- Variables
- func S3Key[T any](bucket string, filename string) ([]T, error)
- func SetS3Key[T any](bucket string, filename string, photos []T) error
- type Credentials
- type Duration
- type GoogleOAuthError
- type GooglePhotosError
- type GooglePhotosPickedItem
- type GooglePhotosPickedItems
- type GooglePhotosPickedMedia
- type GooglePhotosPickedMetadata
- type GooglePhotosPickerSession
- type GooglePhotosPollingConfig
- type MediaType
- type S3Options
- type Token
Constants ¶
This section is empty.
Variables ¶
var ( TypeUnspecified = MediaType("TYPE_UNSPECIFIED") TypePhoto = MediaType("PHOTO") TypeVideo = MediaType("VIDEO") )
var (
ErrPollingCallbackFalse = errors.New("callback returned false, so polling was halted")
)
Functions ¶
Types ¶
type Credentials ¶
type Credentials struct { ClientID string // ClientID is your app's client ID from Google ClientSecret string // ClientSecret is your app's client secret from Google RefreshToken string // Refresh token is the _user's_ refresh token from first authentication that can be used to get a new access token AccessToken *Token // Optionally supply a valid access token, which will be used if provided }
Credentials represents a Google Photos OAuth2 credential that can be used to get a valid access token.
func (*Credentials) NewPickerSession ¶
func (c *Credentials) NewPickerSession() (*GooglePhotosPickerSession, error)
func (Credentials) NewUserAuthorization ¶
func (c Credentials) NewUserAuthorization()
func (*Credentials) Token ¶
func (c *Credentials) Token() (*Token, error)
Token fetches an access token for the provided credentials. Also sets the AccessToken field of the provided credentials.
func (*Credentials) UploadToS3 ¶
func (c *Credentials) UploadToS3(photos []GooglePhotosPickedItem, opts S3Options) error
UploadToS3 writes the photos to an S3 bucket.
S3 environment variables _must_ be set, including:
- AWS_ACCESS_KEY_ID
- AWS_SECRET_ACCESS_KEY
- AWS_REGION
type Duration ¶
func (*Duration) UnmarshalJSON ¶
type GoogleOAuthError ¶
type GoogleOAuthError struct { ErrorCode string `json:"error"` Message string `json:"error_description"` }
GoogleOAuthError represents an error during an OAuth exchange with Google
func (GoogleOAuthError) Error ¶
func (e GoogleOAuthError) Error() string
type GooglePhotosError ¶
type GooglePhotosError struct { Code int `json:"code"` Status string `json:"status"` Message string `json:"message"` Details any `json:"details"` }
GooglePhotosError is the content of the error message returned in JSON responses from the API.
func (GooglePhotosError) Error ¶
func (e GooglePhotosError) Error() string
type GooglePhotosPickedItem ¶
type GooglePhotosPickedItem struct { ID string CreateTime string Type MediaType Media GooglePhotosPickedMedia `json:"mediaFile"` }
type GooglePhotosPickedItems ¶
type GooglePhotosPickedItems struct { Items []GooglePhotosPickedItem `json:"mediaItems"` NextPageToken string `json:"nextPageToken"` Error *GooglePhotosError `json:"error"` }
type GooglePhotosPickedMedia ¶
type GooglePhotosPickedMedia struct { BaseURL string MimeType string Filename string Metadata GooglePhotosPickedMetadata `json:"mediaFileMetadata"` }
type GooglePhotosPickerSession ¶
type GooglePhotosPickerSession struct { ID string // ID of the session created by Google for this user PickerURI string // URI to send the user to pick photos PollingURI string `json:"-"` // URI to poll to find out when the user is done PollingConfig GooglePhotosPollingConfig // Recommended polling configuration for the Polling URI from google ExpireTime time.Time // Time that the session expires MediaItemsSet bool // True if the user has finished picking photos Credentials *Credentials `json:"-"` // Credentials used to create this session Error *GooglePhotosError `json:"error"` // Only present if there's been an error returned by the API }
GooglePhotosPickerSession represents a session where a user can pick photos from the Google Photos Picker UI.
func (*GooglePhotosPickerSession) Poll ¶
func (s *GooglePhotosPickerSession) Poll(ctx context.Context, callbacks ...func(s *GooglePhotosPickerSession) bool) ([]GooglePhotosPickedItem, error)
Poll polls the Google Photos session API until MediaItemsSet is true or an error occurs.
Provide a callback func if to show progress to the user or interrupt the polling. Returning `false` from a callback will stop the polling with an `ErrPollingCallbackFalse` error.
type GooglePhotosPollingConfig ¶
type GooglePhotosPollingConfig struct { PollInterval Duration // How often the polling uri should be polled TimeoutIn string // when the picker session times out }
GooglePhotosPollingConfig is google's recommended polling config
type S3Options ¶
type S3Options struct { Bucket string // Required. s3 bucket to upload content. PhotosJSONKey string // s3 key for a json dump of all the photos info, default to `photos.json` PhotosPrefix string // s3 key prefix for where to put the photos without the trailing slash, defaults to `photos` Width int // width of the image to request from Google Photos. If not provided, gets full width Height int // height of the image to request from Google Photos. If not provided, gets full height AddExtension bool // add the extension of the file onto the s3 key. Defaults to false, uploading by Google Photos ID }
S3Options provide configuration over where photos should be stored in S3
func NewS3Options ¶ added in v1.0.1
NewS3Options creates a new S3Options object with defaults
func (S3Options) PhotoJSON ¶
func (o S3Options) PhotoJSON() ([]GooglePhotosPickedItem, error)
PhotoJSON returns the photos metadata json file stored in S3
func (S3Options) SetPhotoJSON ¶ added in v1.0.1
func (opts S3Options) SetPhotoJSON(photos []GooglePhotosPickedItem) error