UNPKG

viettel-ekyc-sdk

Version:
117 lines 5.13 kB
/* eslint-disable react-native/no-inline-styles */ import ImageEditor from '@react-native-community/image-editor'; import React from 'react'; import { Dimensions } from 'react-native'; import RNFS from 'react-native-fs'; import ImageResizer from 'react-native-image-resizer'; import { Header } from '../components/Header'; import { SUCCESS } from '../constants/api'; import { OCR_FRONT_TYPE } from '../constants/camera'; import { OS } from '../constants/OS'; import { checkIdSanityPost, checkIdTemperingPost } from './api'; import { getBase64FromUri, makeId } from './utils'; export const getHeader = (typeString) => { if (typeString === OCR_FRONT_TYPE) { return (React.createElement(Header, { title: 'Ch\u1EE5p \u1EA3nh m\u1EB7t tr\u01B0\u1EDBc gi\u1EA5y t\u1EDD t\u00F9y th\u00E2n', subTitle: 'CMT/ CCCD/ CMT Qu\u00E2n \u0111\u1ED9i/ HC/ B\u1EB1ng l\u00E1i xe', titleStyle: { color: 'white', fontSize: 18 }, subTitleStyle: { color: 'white' } })); } else { return (React.createElement(Header, { title: 'Ch\u1EE5p \u1EA3nh m\u1EB7t sau gi\u1EA5y t\u1EDD t\u00F9y th\u00E2n', titleStyle: { color: 'white', fontSize: 18 }, subTitle: 'CMT/ CCCD/ CMT Qu\u00E2n \u0111\u1ED9i', subTitleStyle: { color: 'white' } })); } }; export const getStepResultHeader = (typeCard) => { return (React.createElement(Header, { title: 'Ph\u00E1t hi\u1EC7n lo\u1EA1i gi\u1EA5y t\u1EDD', subTitle: convertStringCardType(typeCard), titleStyle: { color: 'black', fontSize: 18 }, subTitleStyle: { color: 'black' } })); }; export const isCardFront = (typeCard) => { if (typeCard === undefined) { return true; } if ((typeCard.lastIndexOf('CMND') > -1 || typeCard.lastIndexOf('CCCD') > -1 || typeCard.lastIndexOf('CMCC') > -1 || typeCard.lastIndexOf('CMQD') > -1) && typeCard.lastIndexOf('back') > -1) { return false; } return true; }; const convertStringCardType = (typeCard) => { if (typeCard === undefined) { return 'Giấy tờ không nhận dạng được'; } if (typeCard.lastIndexOf('CMND') > -1 || typeCard.lastIndexOf('CCCD') > -1 || typeCard.lastIndexOf('CMCC') > -1) { return 'CMND/CCCD'; } else if (typeCard.lastIndexOf('Passport') > -1 || typeCard.lastIndexOf('PASSPORT') > -1) { return 'Hộ chiếu'; } else if (typeCard.lastIndexOf('BLX') > -1) { return 'Bằng lái xe'; } else if (typeCard.lastIndexOf('CMQD') > -1) { return 'Chứng minh Quân đội'; } else { return 'Giấy tờ không nhận dạng được'; } }; export const cropImageFrame = async (uri, topLeft, initialImageWidth, width, height) => { let rate = initialImageWidth / Dimensions.get('screen').width; const cropData = { offset: { x: topLeft.x * rate, y: topLeft.y * rate, }, size: { width: width * rate, height: height * rate, }, }; let link = await ImageEditor.cropImage(OS.IS_ANDROID ? `file://${uri}` : uri, { ...cropData, resizeMode: 'contain', }); const fromPath = link.substring(7); let toPath = `file://${RNFS.DocumentDirectoryPath}/${makeId(8)}.jpg`; await RNFS.moveFile(fromPath, toPath); return toPath; }; export const resizedImage = async (uri) => { let response = await ImageResizer.createResizedImage(uri, 720, 720, 'JPEG', 95); return `file://${response.path}`; }; export const checkQualityAndSpoof = async (path, enableCheckSanity, enableCheckTempering) => { var _a, _b, _c, _d, _e, _f, _g, _h; const imageUriBase64 = await getBase64FromUri(path); if (enableCheckSanity && enableCheckTempering) { const [temperingResponse, sanityResponse] = await Promise.all([ checkIdTemperingPost(imageUriBase64), checkIdSanityPost(imageUriBase64), ]); if (((_a = sanityResponse.data) === null || _a === void 0 ? void 0 : _a.code) !== SUCCESS) { return ((_b = sanityResponse.data) === null || _b === void 0 ? void 0 : _b.message) || ''; } else if (((_c = temperingResponse.data) === null || _c === void 0 ? void 0 : _c.code) !== SUCCESS) { return ((_d = temperingResponse.data) === null || _d === void 0 ? void 0 : _d.message) || ''; } else { return ''; } } else if (enableCheckSanity) { const sanityResponse = await checkIdSanityPost(imageUriBase64); return ((_e = sanityResponse.data) === null || _e === void 0 ? void 0 : _e.code) !== SUCCESS ? (_f = sanityResponse.data) === null || _f === void 0 ? void 0 : _f.message : ''; } else if (enableCheckTempering) { const temperingResponse = await checkIdTemperingPost(imageUriBase64); return ((_g = temperingResponse.data) === null || _g === void 0 ? void 0 : _g.code) !== SUCCESS ? (_h = temperingResponse.data) === null || _h === void 0 ? void 0 : _h.message : ''; } return ''; }; //# sourceMappingURL=widget.js.map