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:
71
src/services/ShopifyMediaService.ts
Normal file
71
src/services/ShopifyMediaService.ts
Normal file
@ -0,0 +1,71 @@
|
||||
import { IShopifyMediaService } from "../interfaces/IShopifyMediaService"
|
||||
import { IShop } from "../interfaces/IShop"
|
||||
import { formatGqlForJSON } from "../shopifyApi"
|
||||
|
||||
export class ShopifyMediaService implements IShopifyMediaService {
|
||||
private shop: IShop
|
||||
|
||||
constructor(shop: IShop) {
|
||||
this.shop = shop
|
||||
}
|
||||
|
||||
stagedUploadsCreate(input: any[]): any {
|
||||
const query = /* GraphQL */ `
|
||||
mutation stagedUploadsCreate($input: [StagedUploadInput!]!) {
|
||||
stagedUploadsCreate(input: $input) {
|
||||
stagedTargets {
|
||||
url
|
||||
resourceUrl
|
||||
parameters {
|
||||
name
|
||||
value
|
||||
}
|
||||
}
|
||||
userErrors {
|
||||
field
|
||||
message
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
const variables = { input }
|
||||
const payload = {
|
||||
query: formatGqlForJSON(query),
|
||||
variables: variables
|
||||
}
|
||||
const response = this.shop.shopifyGraphQLAPI(payload)
|
||||
return response.content.data.stagedUploadsCreate
|
||||
}
|
||||
|
||||
productCreateMedia(productId: string, media: any[]): any {
|
||||
const query = /* GraphQL */ `
|
||||
mutation productCreateMedia($media: [CreateMediaInput!]!, $productId: ID!) {
|
||||
productCreateMedia(media: $media, productId: $productId) {
|
||||
media {
|
||||
alt
|
||||
mediaContentType
|
||||
status
|
||||
}
|
||||
mediaUserErrors {
|
||||
field
|
||||
message
|
||||
}
|
||||
product {
|
||||
id
|
||||
title
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
const variables = {
|
||||
productId,
|
||||
media
|
||||
}
|
||||
const payload = {
|
||||
query: formatGqlForJSON(query),
|
||||
variables: variables
|
||||
}
|
||||
const response = this.shop.shopifyGraphQLAPI(payload)
|
||||
return response.content.data.productCreateMedia
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user