mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-21 13:55:51 +00:00
realtime
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user