package photos import ( "encoding/json" "fmt" ) type Bridge interface { RequestAccess() error ListAlbums() ([]Album, error) ListAssets(albumID string) ([]Asset, int, error) ReverseGeocode(latitude, longitude float64) (Placemark, error) ListTree() ([]CollectionNode, error) ExportPreview(assetID, outputDir string, targetSize, quality, index int) (ExportResult, error) ExportOriginal(assetID, outputDir string, index int) (ExportResult, error) ExportPreviewWithSlot(assetID, outputDir string, targetSize, quality, index, slotIndex int) (ExportResult, error) ExportOriginalWithSlot(assetID, outputDir string, index, slotIndex int) (ExportResult, error) Cancel() IsCancelled() bool } func ParseAlbumsJSON(jsonStr string) ([]Album, error) { var resp AlbumsResponse if err := json.Unmarshal([]byte(jsonStr), &resp); err != nil { return nil, err } return resp.Albums, nil } func ParseAssetsJSON(jsonStr string) ([]Asset, int, error) { var errResp ErrorResponse if err := json.Unmarshal([]byte(jsonStr), &errResp); err == nil && errResp.Error != "" { return nil, 0, fmt.Errorf("%s", errResp.Error) } var resp AssetsResponse if err := json.Unmarshal([]byte(jsonStr), &resp); err != nil { return nil, 0, err } return resp.Assets, resp.Total, nil } func ParsePlacemarkJSON(jsonStr string) (Placemark, error) { var resp PlacemarkResponse if err := json.Unmarshal([]byte(jsonStr), &resp); err != nil { return Placemark{}, err } if resp.Error != "" { return Placemark{}, fmt.Errorf("%s", resp.Error) } return resp.Placemark, nil } func ParseTreeJSON(jsonStr string) ([]CollectionNode, error) { var errResp ErrorResponse if err := json.Unmarshal([]byte(jsonStr), &errResp); err == nil && errResp.Error != "" { return nil, fmt.Errorf("%s", errResp.Error) } var resp TreeResponse if err := json.Unmarshal([]byte(jsonStr), &resp); err != nil { return nil, err } return resp.Collections, nil } func ParseExportResultJSON(jsonStr string) (ExportResult, error) { var resp ExportResultResponse if err := json.Unmarshal([]byte(jsonStr), &resp); err != nil { return ExportResult{}, err } if resp.Error != "" { return ExportResult{}, fmt.Errorf("%s", resp.Error) } return resp.ExportResult, nil }