Skip to content

Commit 4d90a96

Browse files
authored
Merge pull request #1814 from numbersprotocol/fix-custom-camera-delete-file-after-discard-confirm
fix(custom-camera.page): remove capture after discard/approve
2 parents 8c3ac62 + 2f74ca1 commit 4d90a96

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

src/app/features/home/custom-camera/custom-camera.page.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,9 @@ export class CustomCameraPage implements OnInit, OnDestroy {
156156
this.removeCurrentCapture();
157157
}
158158

159-
confirmCurrentCapture() {
159+
async confirmCurrentCapture() {
160160
if (this.curCaptureFilePath && this.curCaptureType) {
161-
this.customCameraService.uploadToCapture(
161+
await this.customCameraService.uploadToCapture(
162162
this.curCaptureFilePath,
163163
this.curCaptureType
164164
);
@@ -179,7 +179,7 @@ export class CustomCameraPage implements OnInit, OnDestroy {
179179
}
180180

181181
private removeCurrentCapture() {
182-
// TODO: remove file this.curCaptureFilePath to free space
182+
this.customCameraService.removeFile(this.curCaptureFilePath);
183183
this.curCaptureFilePath = undefined;
184184
this.curCaptureMimeType = undefined;
185185
this.curCaptureSrc = undefined;

src/app/features/home/custom-camera/custom-camera.service.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { HttpClient } from '@angular/common/http';
2-
import { Injectable } from '@angular/core';
2+
import { Inject, Injectable } from '@angular/core';
33
import { DomSanitizer } from '@angular/platform-browser';
44
import { Capacitor } from '@capacitor/core';
5+
import { FilesystemPlugin } from '@capacitor/filesystem';
56
import { TranslocoService } from '@ngneat/transloco';
67
import { PreviewCamera } from '@numbersprotocol/preview-camera';
78
import { BehaviorSubject } from 'rxjs';
9+
import { FILESYSTEM_PLUGIN } from '../../../shared/capacitor-plugins/capacitor-plugins.module';
810
import { CaptureService } from '../../../shared/capture/capture.service';
911
import { ErrorService } from '../../../shared/error/error.service';
1012
import { blobToBase64 } from '../../../utils/encoding/encoding';
@@ -27,7 +29,9 @@ export class CustomCameraService {
2729
private readonly httpClient: HttpClient,
2830
private readonly captureService: CaptureService,
2931
private readonly errorService: ErrorService,
30-
private readonly translocoService: TranslocoService
32+
private readonly translocoService: TranslocoService,
33+
@Inject(FILESYSTEM_PLUGIN)
34+
private readonly filesystemPlugin: FilesystemPlugin
3135
) {}
3236

3337
private mediaItemFromFilePath(
@@ -89,6 +93,11 @@ export class CustomCameraService {
8993
return PreviewCamera.stopRecord().catch(() => ({}));
9094
}
9195

96+
async removeFile(filePath: string | undefined) {
97+
if (!filePath) return;
98+
await this.filesystemPlugin.deleteFile({ path: filePath });
99+
}
100+
92101
private changeGlobalCSSBackgroundToTransparent() {
93102
document.querySelector('body')?.classList.add(this.globalCSSClass);
94103
document.querySelector('ion-app')?.classList.add(this.globalCSSClass);

0 commit comments

Comments
 (0)