Feature: Robust Google Photos Integration & Media Hardening

- Implemented Google Photos Picker with Session API.
- Fixed 403 Forbidden errors by adding OAuth headers to download requests.
- Implemented MediaHandler resilience:
  - 3-Step Import (Save to Root -> Verify Folder -> Move).
  - Advanced Drive API Fallback (v3/v2) for file creation.
  - Blob Sanitization (Utilities.newBlob) to fix server errors.
- Enabled Advanced Drive Service in ppsscript.json.
- Updated Documentation (MEMORY.md, ARCHITECTURE.md) with findings.
This commit is contained in:
2025-12-26 01:51:04 -07:00
parent 95094b1674
commit 50ddfc9e15
7 changed files with 403 additions and 22 deletions

View File

@ -118,3 +118,26 @@ We use **Husky** and **lint-staged** to enforce quality standards at the commit
Classes (like `Product`) should accept an `ISpreadsheetService` in their constructor. This allows providing the Mock service during tests to verify logic without touching real Google Sheets.
### 7. Media Manager (`src/mediaHandlers.ts`, `src/MediaSidebar.html`)
We implemented a "Sidebar-First" architecture for product media to handle the complexity of Google Picker and Shopify Sync.
#### Frontend (`MediaSidebar.html`)
- **Glassmorphism UI**: Uses modern CSS for a premium feel.
- **Polling**: Since the sidebar can't listen to Sheet events directly efficiently, it polls `getMediaState(sku)` to detect when the user selects a different product row.
- **Google Picker API**:
- Uses the **New Google Photos Picker** (Session-based) for selecting photos.
- Uses the **Google Drive Picker** (Legacy) for selecting existing Drive files.
- Handles OAuth token passing securely from the server side (`google.script.run`).
#### Backend (`mediaHandlers.ts`)
- **Import Strategy**:
- **Safe Zone**: Files are first downloaded/copied to the Drive Root to ensure we have the asset.
- **Move**: Then they are moved to the organized SKU folder (`/Product Photos/[SKU]/`).
- **Resilience**: The file creation logic tries multiple methods (Standard `DriveApp`, Sanitized Blob, Advanced `Drive` API) to handle the notoriously fickle nature of UrlFetchApp blobs.
- **Shopify Sync**:
- `MediaService` manages the state.
- Calculates checksums to avoid re-uploading duplicate images.
- Uses Shopify's "Staged Uploads" -> "Create Media" mutation flow.