From f5803fdafbcdc035e90847f25f3e4e4f86dd638f Mon Sep 17 00:00:00 2001 From: vincent Date: Mon, 30 Aug 2021 15:38:12 +0800 Subject: [PATCH] Share cai-injected photo instead of sharable copy --- .../asset/dia-backend-asset-repository.service.ts | 1 + src/app/shared/share/share.service.ts | 14 ++++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/app/shared/dia-backend/asset/dia-backend-asset-repository.service.ts b/src/app/shared/dia-backend/asset/dia-backend-asset-repository.service.ts index c324fab21..69f1c97bd 100644 --- a/src/app/shared/dia-backend/asset/dia-backend-asset-repository.service.ts +++ b/src/app/shared/dia-backend/asset/dia-backend-asset-repository.service.ts @@ -302,6 +302,7 @@ export interface DiaBackendAsset extends Tuple { readonly creator_name: string; readonly supporting_file: string | null; readonly source_type: 'original' | 'post_capture' | 'store'; + readonly cai_file: string; } export type AssetDownloadField = diff --git a/src/app/shared/share/share.service.ts b/src/app/shared/share/share.service.ts index 04eacdce5..44887c8c2 100644 --- a/src/app/shared/share/share.service.ts +++ b/src/app/shared/share/share.service.ts @@ -1,3 +1,4 @@ +import { HttpClient } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { Plugins } from '@capacitor/core'; import { concatMap, first, map } from 'rxjs/operators'; @@ -18,11 +19,12 @@ export class ShareService { constructor( private readonly diaBackendAssetRepository: DiaBackendAssetRepository, - private readonly mediaStore: MediaStore + private readonly mediaStore: MediaStore, + private readonly httpClient: HttpClient ) {} async share(asset: DiaBackendAsset) { - const dataUri = await this.getSharableCopy(asset); + const dataUri = await this.getCaiFile(asset); const fileUrl = await this.createFileUrl(dataUri); return Share.share({ text: this.defaultShareText, @@ -36,11 +38,15 @@ export class ShareService { return this.mediaStore.getUri(index); } - private async getSharableCopy(asset: DiaBackendAsset) { + private async getCaiFile(asset: DiaBackendAsset) { return this.diaBackendAssetRepository - .downloadFile$({ id: asset.id, field: 'sharable_copy' }) + .fetchById$(asset.id) .pipe( first(), + map(diaBackendAsset => diaBackendAsset.cai_file), + concatMap(cai_file => + this.httpClient.get(cai_file, { responseType: 'blob' }) + ), concatMap(blobToBase64), map(imageBase64 => `data:image/jpeg;base64,${imageBase64}`) )