@@ -9,6 +9,11 @@ import {
99 Plugins ,
1010} from '@capacitor/core' ;
1111import { isPlatform } from '@ionic/core' ;
12+ import {
13+ detectFileTypeFromUrl ,
14+ extractFileNameFromGoProUrl ,
15+ urlIsImage ,
16+ } from '../../../../../utils/url' ;
1217import { FILESYSTEM_PLUGIN } from '../../../../shared/capacitor-plugins/capacitor-plugins.module' ;
1318import { CaptureService } from '../../../../shared/capture/capture.service' ;
1419import { blobToBase64 } from '../../../../utils/encoding/encoding' ;
@@ -37,32 +42,6 @@ export class GoProMediaService {
3742 private readonly httpClient : HttpClient
3843 ) { }
3944
40- // eslint-disable-next-line class-methods-use-this
41- getFileType ( url ?: string ) : 'unknown' | 'video' | 'image' {
42- if ( url === undefined ) {
43- return 'unknown' ;
44- }
45- if ( url . toLowerCase ( ) . includes ( '.mp4' ) ) {
46- return 'video' ;
47- }
48- if (
49- url . toLowerCase ( ) . includes ( '.jpg' ) ||
50- url . toLowerCase ( ) . includes ( '.jpeg' )
51- ) {
52- return 'image' ;
53- }
54- return 'unknown' ;
55- }
56-
57- // eslint-disable-next-line class-methods-use-this
58- extractFileNameFromGoProUrl ( url : string ) : string {
59- // example of GoPro urls
60- // _________url: http://10.5.5.9:8080/videos/DCIM/100GOPRO/GH010168.MP4
61- // thumbnailUrl: http://10.5.5.9:8080/gopro/media/thumbnail?path=100GOPRO/GH010168.MP4
62- return url . split ( '/' ) . pop ( ) ?? '' ;
63- }
64-
65- // eslint-disable-next-line class-methods-use-this
6645 getThumbnailUrlFrom ( url : string ) : string {
6746 const fileName = url . split ( '/' ) . pop ( ) ;
6847 const thumbnailUrl = `${ this . goproBaseUrl } /gopro/media/thumbnail?path=100GOPRO/${ fileName } ` ;
@@ -77,7 +56,7 @@ export class GoProMediaService {
7756 } > {
7857 if ( ! mediaFile ) return { isDownloaded : false , isCaptured : false } ;
7958
80- const fileName = this . extractFileNameFromGoProUrl ( mediaFile . url ) ;
59+ const fileName = extractFileNameFromGoProUrl ( mediaFile . url ) ;
8160
8261 let isDownloaded = false ;
8362 let isCaptured = false ;
@@ -103,9 +82,7 @@ export class GoProMediaService {
10382
10483 const base64 = await blobToBase64 ( blob ) ;
10584
106- const mimeType = this . urlIsImage ( mediaFile . url )
107- ? 'image/jpeg'
108- : 'video/mp4' ;
85+ const mimeType = urlIsImage ( mediaFile . url ) ? 'image/jpeg' : 'video/mp4' ;
10986 isDownloaded = true ;
11087
11188 await this . captureService . capture ( { base64, mimeType } ) ;
@@ -125,29 +102,6 @@ export class GoProMediaService {
125102 return { isDownloaded, isCaptured } ;
126103 }
127104
128- // eslint-disable-next-line class-methods-use-this
129- urlIsImage ( url : string ) : boolean {
130- return (
131- url . toLocaleLowerCase ( ) . includes ( '.jpeg' ) ||
132- url . toLocaleLowerCase ( ) . includes ( '.jpg' )
133- ) ;
134- }
135-
136- // eslint-disable-next-line class-methods-use-this
137- urlIsVideo ( url : string ) : boolean {
138- return url . toLowerCase ( ) . includes ( '.mp4' ) ;
139- }
140-
141- detectFileTypeFromUrl ( url : string ) : 'image' | 'video' | 'unknown' {
142- if ( this . urlIsImage ( url ) ) {
143- return 'image' ;
144- }
145- if ( this . urlIsVideo ( url ) ) {
146- return 'video' ;
147- }
148- return 'unknown' ;
149- }
150-
151105 async getFilesFromGoPro ( ) : Promise < GoProFile [ ] > {
152106 const url = this . goproBaseUrl + '/gopro/media/list' ;
153107 const params = { } ;
@@ -173,8 +127,8 @@ export class GoProMediaService {
173127 url,
174128 storageKey : undefined ,
175129 thumbnailUrl : this . getThumbnailUrlFrom ( url ) ,
176- name : this . extractFileNameFromGoProUrl ( url ) ,
177- type : this . detectFileTypeFromUrl ( url ) ,
130+ name : extractFileNameFromGoProUrl ( url ) ,
131+ type : detectFileTypeFromUrl ( url ) ,
178132 } ;
179133 }
180134}
0 commit comments