Skip to content

Commit

Permalink
Share cai-injected photo instead of sharable copy
Browse files Browse the repository at this point in the history
  • Loading branch information
vincent10400094 committed Aug 30, 2021
1 parent fc4e3a8 commit f5803fd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
14 changes: 10 additions & 4 deletions src/app/shared/share/share.service.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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,
Expand All @@ -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}`)
)
Expand Down

0 comments on commit f5803fd

Please sign in to comment.