77 Output ,
88 ViewChild ,
99} from '@angular/core' ;
10- import { FilesystemPlugin } from '@capacitor/filesystem' ;
11- import { AlertController } from '@ionic/angular' ;
10+ import { Directory , FilesystemPlugin } from '@capacitor/filesystem' ;
11+ import { AlertController , Platform } from '@ionic/angular' ;
1212import { TranslocoService } from '@ngneat/transloco' ;
1313import { ColorMatrix , getEditorDefaults } from '@pqina/pintura' ;
1414import {
@@ -62,6 +62,8 @@ export class PrePublishModeComponent {
6262
6363 readonly curCaptureFilePath$ = new ReplaySubject < string > ( 1 ) ;
6464
65+ readonly curCaptureFileName$ = new ReplaySubject < string > ( 1 ) ;
66+
6567 readonly curCaptureMimeType$ = new ReplaySubject < CaptureMimeType > ( 1 ) ;
6668
6769 readonly curCaptureSrc$ = new ReplaySubject < string > ( 1 ) ;
@@ -108,6 +110,11 @@ export class PrePublishModeComponent {
108110 if ( value ) this . curCaptureFilePath$ . next ( value ) ;
109111 }
110112
113+ @Input ( )
114+ set curCaptureFileName ( value : string | undefined ) {
115+ if ( value ) this . curCaptureFileName$ . next ( value ) ;
116+ }
117+
111118 @Input ( )
112119 set curCaptureMimeType ( value : CaptureMimeType | undefined ) {
113120 if ( value ) this . curCaptureMimeType$ . next ( value ) ;
@@ -129,7 +136,8 @@ export class PrePublishModeComponent {
129136 private readonly filesystemPlugin : FilesystemPlugin ,
130137 private readonly errorService : ErrorService ,
131138 private readonly alertController : AlertController ,
132- private readonly translocoService : TranslocoService
139+ private readonly translocoService : TranslocoService ,
140+ private readonly platform : Platform
133141 ) { }
134142
135143 handleEditorUpdate ( imageState : any ) : void {
@@ -150,12 +158,24 @@ export class PrePublishModeComponent {
150158
151159 async handleEditorProcess ( imageWriterResult : any ) : Promise < void > {
152160 const base64 = await blobToBase64 ( imageWriterResult . dest as File ) ;
153- combineLatest ( [ this . curCaptureFilePath$ , of ( base64 ) ] )
161+ combineLatest ( [
162+ this . curCaptureFilePath$ ,
163+ of ( base64 ) ,
164+ this . isImage$ ,
165+ this . curCaptureFileName$ ,
166+ ] )
154167 . pipe (
155168 first ( ) ,
156- switchMap ( ( [ path , data ] ) =>
157- this . filesystemPlugin . writeFile ( { path, data } )
158- ) ,
169+ switchMap ( ( [ path , data , isImage , fileName ] ) => {
170+ if ( this . platform . is ( 'android' ) && isImage ) {
171+ return this . filesystemPlugin . writeFile ( {
172+ path : fileName ,
173+ data : data ,
174+ directory : Directory . Cache ,
175+ } ) ;
176+ }
177+ return this . filesystemPlugin . writeFile ( { path, data } ) ;
178+ } ) ,
159179 tap ( ( ) => this . isProcessingImage$ . next ( false ) ) ,
160180 tap ( ( ) => this . confirm . emit ( true ) ) ,
161181 catchError ( ( error : unknown ) => {
0 commit comments