This commit is contained in:
Peter Maquiran
2024-08-13 10:52:35 +01:00
parent 5b31a186c2
commit 251f533a68
53 changed files with 985 additions and 453 deletions
+26 -10
View File
@@ -2,33 +2,49 @@ import { Injectable } from '@angular/core';
import { Camera, CameraResultType, CameraSource } from '@capacitor/camera';
import { err, ok } from 'neverthrow';
/**
* Parameters for taking a picture.
* @typedef {Object} takePictureParams
* @property {number} [quality=90] - The quality of the picture, from 0 to 100.
* @property {CameraResultType} cameraResultType - The result type of the photo, e.g., Base64, URI.
*/
export type takePictureParams = {
quality?: number;
cameraResultType: CameraResultType;
};
type takePictureParams = {
quality?: number
cameraResultType: CameraResultType
}
/**
* Service for handling camera functionality.
* This service provides methods to interact with the device's camera.
*/
@Injectable({
providedIn: 'root'
})
export class CameraService {
/**
* Creates an instance of CameraService.
*/
constructor() { }
/**
* Takes a picture using the device's camera.
* @param {takePictureParams} params - The parameters for taking the picture.
* @param {number} [params.quality=90] - The quality of the picture, from 0 to 100.
* @param {CameraResultType} params.cameraResultType - The result type of the photo.
* @returns {Promise<ok<File> | err<any>>} A promise that resolves with an `ok` result containing the file or an `err` result containing the error.
*/
async takePicture({quality = 90, cameraResultType }: takePictureParams) {
try {
const file = await Camera.getPhoto({
quality: quality,
// allowEditing: true,
resultType: cameraResultType,
source: CameraSource.Camera
});
return ok(file)
return ok(file);
} catch (e) {
return err(e)
return err(e);
}
}
}
@@ -0,0 +1,50 @@
import { Injectable } from '@angular/core';
import { Camera, CameraResultType, CameraSource } from '@capacitor/camera';
import { err, ok } from 'neverthrow';
/**
* Parameters for picking a picture.
* @typedef {Object} PickPictureParams
* @property {number} [quality=90] - The quality of the picture, from 0 to 100. Defaults to 90.
* @property {CameraResultType} [cameraResultType=CameraResultType.DataUrl] - The result type of the photo. Defaults to `CameraResultType.DataUrl`.
*/
type PickPictureParams = {
quality?: number;
cameraResultType?: CameraResultType;
};
/**
* Service for handling file picking functionality.
* This service provides methods to pick a picture from the device's photo library.
*/
@Injectable({
providedIn: 'root'
})
export class FilePickerService {
/**
* Creates an instance of FilePickerService.
*/
constructor() { }
/**
* Picks a picture from the device's photo library.
* @param {PickPictureParams} params - The parameters for picking the picture.
* @param {number} [params.quality=90] - The quality of the picture, from 0 to 100. Defaults to 90.
* @param {CameraResultType} [params.cameraResultType=CameraResultType.DataUrl] - The result type of the photo. Defaults to `CameraResultType.DataUrl`.
* @returns {Promise<ok<File> | err<any>>} A promise that resolves with an `ok` result containing the file or an `err` result containing the error.
*/
async getPicture({quality = 90, cameraResultType = CameraResultType.DataUrl }: PickPictureParams) {
try {
const file = await Camera.getPhoto({
quality: quality,
resultType: cameraResultType,
source: CameraSource.Photos
});
return ok(file);
} catch (e) {
return err(e);
}
}
}
@@ -0,0 +1,28 @@
import { Injectable } from '@angular/core';
import { FilePicker, PickFilesResult } from '@capawesome/capacitor-file-picker';
import { err, ok, Result } from 'neverthrow';
@Injectable({
providedIn: 'root'
})
export class FilePickerMobileService {
constructor() { }
async getFile({types, multiple, readData}): Promise<Result<PickFilesResult, any>> {
try {
const result = await FilePicker.pickFiles({
types: ['application/pdf', 'application/doc', 'application/docx','application/xls', 'application/xlsx', 'application/ppt',
'application/pptx', 'application/txt'],
multiple: false,
readData: true,
});
return ok(result)
} catch (e) {
return err(e)
}
}
}
@@ -3,10 +3,7 @@ import { Camera, CameraResultType, CameraSource } from '@capacitor/camera';
import { err, ok, Result } from 'neverthrow';
import { FileType } from 'src/app/models/fileType';
type PickPictureParams = {
quality?: number,
cameraResultType?: CameraResultType
}
@Injectable({
providedIn: 'root'
@@ -30,19 +27,4 @@ export class FilePickerWebService {
})
}
async getPicture({quality = 90, cameraResultType =CameraResultType.DataUrl }: PickPictureParams) {
try {
const file = await Camera.getPhoto({
quality: quality,
// allowEditing: true,
resultType: cameraResultType,
source: CameraSource.Photos
});
return ok(file)
} catch (e) {
return err(e)
}
}
}
+11
View File
@@ -0,0 +1,11 @@
export enum StartRecordingResultError {
NoSpeaker,
NeedPermission,
alreadyRecording
}
export enum StopRecordingResultError {
haventStartYet,
NoValue,
UnknownError
}