UNPKG

gplayapi-ts

Version:
1 lines 7.7 kB
{"version":3,"sources":["../../../src/api/endpoints/apps.ts"],"sourcesContent":["/**\n * Apps endpoint handlers for fetching app details and metadata\n */\n\nimport { GPNilPayloadError } from \"../../errors\";\nimport { ImageType } from \"../../models/common\";\nimport { URL_DETAILS } from \"../constants\";\nimport type { App } from \"../../models/app\";\nimport type { Item, Payload } from \"../../gen_proto/googleplay_pb\";\n\nexport class AppsEndpoint {\n constructor(\n private doAuthedReq: (url: string, options?: RequestInit) => Promise<Payload | null>\n ) {}\n\n async getAppDetails(packageName: string): Promise<App> {\n const payload = await this.doAuthedReq(`${URL_DETAILS}?doc=${packageName}`, {\n method: \"GET\",\n });\n\n if (!payload || !payload.detailsResponse) {\n throw new GPNilPayloadError();\n }\n\n return this.buildAppFromItem(payload.detailsResponse.item!);\n }\n\n async bulkDetails(packageNames: string[]): Promise<App[]> {\n const apps: App[] = [];\n \n // Note: This could be optimized with parallel requests or batch API if available\n for (const packageName of packageNames) {\n try {\n const app = await this.getAppDetails(packageName);\n apps.push(app);\n } catch (error) {\n // Continue with other apps even if one fails\n console.warn(`Failed to fetch details for ${packageName}:`, error);\n }\n }\n \n return apps;\n }\n\n private buildAppFromItem(item: Item): App {\n const details = item.details?.appDetails;\n const app: App = {\n packageName: item.id!,\n categoryId: item.categoryId || 0,\n displayName: item.title || \"\",\n description: item.descriptionHtml || \"\",\n shortDescription: item.promotionalDescription || \"\",\n shareUrl: item.shareUrl || \"\",\n versionName: details?.versionString || \"\",\n versionCode: details?.versionCode || 0,\n categoryName: details?.categoryName || \"\",\n size: details?.infoDownloadSize || 0,\n downloadString: details?.downloadLabelAbbreviated || \"\",\n changes: details?.recentChangesHtml || \"\",\n containsAds: !!details?.installNotes,\n earlyAccess: !!details?.earlyAccessInfo,\n developerName: details?.developerName || item.creator || \"\",\n targetSdk: details?.targetSdkVersion || 0,\n updatedOn: details?.infoUpdatedOn || \"\",\n offerDetails: {},\n offerType: 0,\n price: \"\",\n screenshots: [],\n isFree: true,\n isSystem: false,\n };\n\n if (item.offer && item.offer.length > 0) {\n const offer = item.offer[0];\n if (offer) {\n app.offerType = offer.offerType || 0;\n app.isFree = (offer.micros || 0) === 0;\n app.price = offer.formattedAmount || \"\";\n }\n }\n\n if (details?.instantLink) {\n app.instantAppLink = details.instantLink;\n }\n\n this.parseAppInfo(app, item);\n this.parseStreamUrls(app, item);\n this.parseImages(app, item);\n\n return app;\n }\n\n private parseAppInfo(app: App, item: Item): void {\n if (item.appInfo) {\n app.appInfo = { appInfoMap: {} };\n for (const section of item.appInfo.section || []) {\n if (section.label && section.container?.description) {\n app.appInfo.appInfoMap[section.label] = section.container.description;\n }\n }\n }\n }\n\n private parseStreamUrls(app: App, item: Item): void {\n if (item.annotations) {\n app.liveStreamUrl = item.annotations.liveStreamUrl;\n app.promotionStreamUrl = item.annotations.promotionStreamUrl;\n }\n }\n\n private parseImages(app: App, item: Item): void {\n for (const image of item.image || []) {\n switch (image.imageType) {\n case ImageType.CATEGORY_ICON:\n app.categoryImage = image;\n break;\n case ImageType.APP_ICON:\n app.iconImage = image;\n break;\n case ImageType.YOUTUBE_VIDEO_THUMBNAIL:\n app.video = image;\n break;\n case ImageType.PLAY_STORE_PAGE_BACKGROUND:\n app.coverImage = image;\n break;\n case ImageType.APP_SCREENSHOT:\n app.screenshots.push(image);\n break;\n }\n }\n\n if (app.screenshots.length === 0 && item.annotations?.sectionImage) {\n for (const imageContainer of item.annotations.sectionImage.imageContainer || []) {\n if (imageContainer.image) {\n app.screenshots.push(imageContainer.image);\n }\n }\n }\n }\n}"],"mappings":"AAIA,SAAS,yBAAyB;AAClC,SAAS,iBAAiB;AAC1B,SAAS,mBAAmB;AAIrB,MAAM,aAAa;AAAA,EACtB,YACY,aACV;AADU;AAAA,EACT;AAAA,EAEH,MAAM,cAAc,aAAmC;AACnD,UAAM,UAAU,MAAM,KAAK,YAAY,GAAG,WAAW,QAAQ,WAAW,IAAI;AAAA,MACxE,QAAQ;AAAA,I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