feat(media): implement integrated media manager with sidebar and picker

- Implement DriveService and ShopifyMediaService for backend operations
- Create MediaSidebar.html with premium UI and auto-polling
- Integrate Google Picker API for robust file selection
- Orchestrate sync logic via MediaService (Drive -> Staged Upload -> Shopify)
- Add secure config handling for API keys and tokens
- Update ppsscript.json with required OAuth scopes
- Update MEMORY.md and README.md with architecture details
This commit is contained in:
Ben Miller
2025-12-25 15:10:17 -07:00
parent 2417359595
commit 95094b1674
21 changed files with 973 additions and 16 deletions

View File

@ -0,0 +1,55 @@
import { MediaService } from "./MediaService"
import { MockDriveService } from "./MockDriveService"
import { MockShopifyMediaService } from "./MockShopifyMediaService"
import { INetworkService } from "../interfaces/INetworkService"
import { Config } from "../config"
class MockNetworkService implements INetworkService {
lastUrl: string = ""
lastPayload: any = {}
fetch(url: string, params: GoogleAppsScript.URL_Fetch.URLFetchRequestOptions): GoogleAppsScript.URL_Fetch.HTTPResponse {
this.lastUrl = url
this.lastPayload = params.payload
return {
getResponseCode: () => 200
} as GoogleAppsScript.URL_Fetch.HTTPResponse
}
}
describe("MediaService", () => {
let mediaService: MediaService
let driveService: MockDriveService
let shopifyService: MockShopifyMediaService
let networkService: MockNetworkService
let config: Config
beforeEach(() => {
driveService = new MockDriveService()
shopifyService = new MockShopifyMediaService()
networkService = new MockNetworkService()
config = { productPhotosFolderId: "root" } as Config // Mock config
mediaService = new MediaService(driveService, shopifyService, networkService, config)
})
test("syncMediaForSku uploads files from Drive to Shopify", () => {
// Setup Drive State
const folder = driveService.getOrCreateFolder("SKU123", "root")
const blob1 = { getName: () => "01.jpg", getMimeType: () => "image/jpeg", getBytes: () => [] } as unknown as GoogleAppsScript.Base.Blob
driveService.saveFile(blob1, folder.getId())
// Run Sync
mediaService.syncMediaForSku("SKU123", "shopify_prod_id")
// Verify Network Call (Upload)
expect(networkService.lastUrl).toBe("https://mock-upload.shopify.com")
// Verify payload contained file
expect(networkService.lastPayload).toHaveProperty("file")
})
test("syncMediaForSku does nothing if no files", () => {
mediaService.syncMediaForSku("SKU_EMPTY", "pid")
expect(networkService.lastUrl).toBe("")
})
})