Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(features/home/details): improve C2PA flow #3247

Merged
merged 1 commit into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ios/App/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ PODS:
- CapacitorCordova (5.7.5)
- CapacitorDevice (5.0.4):
- Capacitor
- CapacitorFilesystem (5.0.4):
- CapacitorFilesystem (5.1.1):
- Capacitor
- CapacitorGeolocation (5.0.4):
- Capacitor
Expand Down Expand Up @@ -224,7 +224,7 @@ SPEC CHECKSUMS:
CapacitorCommunityWifi: 47188c74f2c6bcaefb619380863be8c67b1917c8
CapacitorCordova: c946a6052b547e1e185fc46862003f7b9130ead1
CapacitorDevice: eb4b5e3b42ac35d2527f20aad296b59e0785dc8d
CapacitorFilesystem: e1bdfab09b95b181c844c16abcfda45ec8e8ed6b
CapacitorFilesystem: 38e85e56818420bed3f0aa1b77128f503a960821
CapacitorGeolocation: 33015be1ef496585a60da9efa1c5642ff8624db3
CapacitorLocalNotifications: c2d8b14794064fd4814b1d6c4ddbac8029afa295
CapacitorNativeSettings: b6f40955945bc659f966a43fa54fc6be192d8f9b
Expand Down
14 changes: 0 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@
"immutable": "^4.0.0-rc.14",
"lodash-es": "^4.17.21",
"material-design-icons-iconfont": "^6.1.0",
"mime-types": "2.1.35",
"ng-circle-progress": "^1.6.0",
"ngx-joyride": "^2.5.0",
"ngx-long-press2": "^2.0.0",
Expand Down Expand Up @@ -111,7 +110,6 @@
"@types/jasmine": "^3.8.2",
"@types/jasminewd2": "^2.0.10",
"@types/lodash-es": "^4.17.4",
"@types/mime-types": "2.1.4",
"@types/node": "^16.7.10",
"@typescript-eslint/eslint-plugin": "^5.29.0",
"@typescript-eslint/parser": "^5.36.2",
Expand Down
81 changes: 35 additions & 46 deletions src/app/features/home/details/details.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,24 @@ import { DomSanitizer } from '@angular/platform-browser';
import { ActivatedRoute, Router } from '@angular/router';
import { Browser } from '@capacitor/browser';
import { Clipboard } from '@capacitor/clipboard';
import { Directory, Filesystem } from '@capacitor/filesystem';
import { ActionSheetController, AlertController } from '@ionic/angular';
import { ActionSheetButton } from '@ionic/core';
import { TranslocoService } from '@ngneat/transloco';
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
import { extension } from 'mime-types';
import {
EMPTY,
Observable,
ReplaySubject,
Subject,
combineLatest,
defer,
of,
} from 'rxjs';
import {
catchError,
concatMap,
concatMapTo,
distinctUntilChanged,
finalize,
first,
map,
pluck,
Expand Down Expand Up @@ -525,9 +523,36 @@ export class DetailsPage {
}

private async handleDownloadC2paAction(diaBackendAsset: DiaBackendAsset) {
const filePath = await this.diaBackendAssetRepository
.downloadC2pa$(diaBackendAsset.id)
let fileUrl: string | undefined = undefined;
const downloadC2paDismissed$ = new Subject<void>();
const alert = await this.alertController.create({
header: this.translocoService.translate('details.shares.downloadC2pa'),
message: `<ion-spinner></ion-spinner><br>${this.translocoService.translate(
'message.pleaseWait'
)}`,
backdropDismiss: false,
buttons: [
{ text: this.translocoService.translate('cancel'), role: 'cancel' },
],
});

alert.onDidDismiss().then(async () => {
downloadC2paDismissed$.next();
if (fileUrl) {
const link = document.createElement('a');
link.href = `${BUBBLE_IFRAME_URL}/download?url=${fileUrl}`;
link.hidden = true;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
});

defer(() => alert.present())
.pipe(
switchMap(() =>
this.diaBackendAssetRepository.downloadC2pa$(diaBackendAsset.id)
),
catchError((err: unknown) => {
if (err instanceof HttpErrorResponse) {
const errorMessage = err.error?.error?.message;
Expand All @@ -537,50 +562,14 @@ export class DetailsPage {
}
return this.errorService.toastError$(err);
}),
switchMap(c2paResult =>
defer(() => {
let filePath = c2paResult.cid;
const ext = extension(diaBackendAsset.asset_file_mime_type);
if (ext) {
filePath += `.${ext}`;
}
return Filesystem.downloadFile({
url: c2paResult.url,
path: filePath,
directory: Directory.Cache,
});
})
),
catchError((err: unknown) => this.errorService.toastError$(err)),
switchMap(downloadResult => {
if (!downloadResult.path) {
return this.errorService.toastError$(
this.translocoService.translate('error.unknownError')
);
}
return of(downloadResult.path);
map(c2paResult => {
fileUrl = c2paResult.url;
}),
finalize(() => alert.dismiss()),
untilDestroyed(this),
takeUntil(this.shareMenuDismissed$)
takeUntil(downloadC2paDismissed$)
)
.toPromise();

if (!filePath || !(await ShareService.canShare())) {
// Failed or web no navigator share
return;
}

let fileUrl = filePath;
if (!fileUrl.startsWith('file://')) {
fileUrl = `file://${fileUrl}`;
}
await ShareService.shareFile(fileUrl)
.catch(async reason => {
if (reason?.message !== 'Share canceled') {
await this.errorService.toastError$(reason).toPromise();
}
})
.finally(() => Filesystem.deleteFile({ path: filePath }));
.subscribe();
}

private handleEditAction() {
Expand Down
Loading