From da769523c82f6218c9681f59976dd1a043c4de1b Mon Sep 17 00:00:00 2001 From: Tiny_Murky Date: Thu, 15 Aug 2024 17:51:14 +0800 Subject: [PATCH 1/7] connect to gemini aich --- package.json | 2 +- src/constants/aich.ts | 4 ++++ src/lib/utils/aich.ts | 17 +++++++++++++++++ .../company/[companyId]/ocr/[resultId]/index.ts | 6 ++++-- .../api/v1/company/[companyId]/ocr/index.ts | 4 ++-- 5 files changed, 28 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 8d83c2ddc..b2693f385 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "iSunFA", - "version": "0.8.0+7", + "version": "0.8.0+8", "private": false, "scripts": { "dev": "next dev", diff --git a/src/constants/aich.ts b/src/constants/aich.ts index b75e37cf8..78362b69a 100644 --- a/src/constants/aich.ts +++ b/src/constants/aich.ts @@ -1,4 +1,8 @@ export enum AICH_APIS_TYPES { UPLOAD_OCR = 'upload_ocr', GET_OCR_RESULT_ID = 'get_ocr_result_id', + GET_OCR_RESULT = 'get_ocr_result', + UPLOAD_GEMINI = 'upload_gemini', + GET_GEMINI_RESULT_ID = 'get_gemini_result_id', + GET_GEMINI_RESULT = 'get_gemini_result', } diff --git a/src/lib/utils/aich.ts b/src/lib/utils/aich.ts index a38a3bf03..624c48457 100644 --- a/src/lib/utils/aich.ts +++ b/src/lib/utils/aich.ts @@ -18,6 +18,23 @@ export function getAichUrl(endPoint: AICH_APIS_TYPES, aichResultId?: string): st throw new Error('AICH Result ID is required'); } return `${AICH_URI}/api/v1/ocr/${aichResultId}/process_status`; + case AICH_APIS_TYPES.GET_OCR_RESULT: + if (!aichResultId) { + throw new Error('AICH Result ID is required'); + } + return `${AICH_URI}/api/v1/ocr/${aichResultId}/result`; + case AICH_APIS_TYPES.UPLOAD_GEMINI: + return `${AICH_URI}/api/v1/gemini/upload`; + case AICH_APIS_TYPES.GET_GEMINI_RESULT_ID: + if (!aichResultId) { + throw new Error('AICH Result ID is required'); + } + return `${AICH_URI}/api/v1/gemini/${aichResultId}/process_status`; + case AICH_APIS_TYPES.GET_GEMINI_RESULT: + if (!aichResultId) { + throw new Error('AICH Result ID is required'); + } + return `${AICH_URI}/api/v1/gemini/${aichResultId}/result`; default: throw new Error('Invalid AICH API Type'); } diff --git a/src/pages/api/v1/company/[companyId]/ocr/[resultId]/index.ts b/src/pages/api/v1/company/[companyId]/ocr/[resultId]/index.ts index 4ee0be301..e3cdc8941 100644 --- a/src/pages/api/v1/company/[companyId]/ocr/[resultId]/index.ts +++ b/src/pages/api/v1/company/[companyId]/ocr/[resultId]/index.ts @@ -1,6 +1,5 @@ // Info Murky (20240416): this is mock api need to migrate to microservice import type { NextApiRequest, NextApiResponse } from 'next'; -import { AICH_URI } from '@/constants/config'; import { IResponseData } from '@/interfaces/response_data'; import { IInvoice } from '@/interfaces/invoice'; import { @@ -17,6 +16,8 @@ import { ProgressStatus } from '@/constants/account'; import { getSession } from '@/lib/utils/session'; import { checkAuthorization } from '@/lib/utils/auth_check'; import { AuthFunctionsKeys } from '@/interfaces/auth'; +import { getAichUrl } from '@/lib/utils/aich'; +import { AICH_APIS_TYPES } from '@/constants/aich'; // Info (20240522 - Murky): This OCR now can only be used on Invoice @@ -31,7 +32,8 @@ export async function fetchOCRResult(resultId: string) { let response: Response; try { - response = await fetch(`${AICH_URI}/api/v1/ocr/${resultId}/result`); + const fetchURL = getAichUrl(AICH_APIS_TYPES.GET_GEMINI_RESULT, resultId); + response = await fetch(fetchURL); } catch (error) { throw new Error(STATUS_MESSAGE.INTERNAL_SERVICE_ERROR_AICH_FAILED); } diff --git a/src/pages/api/v1/company/[companyId]/ocr/index.ts b/src/pages/api/v1/company/[companyId]/ocr/index.ts index 613e2ac0c..6b947292b 100644 --- a/src/pages/api/v1/company/[companyId]/ocr/index.ts +++ b/src/pages/api/v1/company/[companyId]/ocr/index.ts @@ -57,7 +57,7 @@ export async function uploadImageToAICH(imageBlob: Blob, imageName: string) { const formData = createImageFormData(imageBlob, imageName); let response: Response; - const uploadUrl = getAichUrl(AICH_APIS_TYPES.UPLOAD_OCR); + const uploadUrl = getAichUrl(AICH_APIS_TYPES.UPLOAD_GEMINI); try { response = await fetch(uploadUrl, { method: 'POST', @@ -203,7 +203,7 @@ export async function fetchStatus(aichResultId: string) { if (aichResultId.length > 0) { try { - const fetchUrl = getAichUrl(AICH_APIS_TYPES.GET_OCR_RESULT_ID, aichResultId); + const fetchUrl = getAichUrl(AICH_APIS_TYPES.GET_GEMINI_RESULT_ID, aichResultId); const result = await fetch(fetchUrl); if (!result.ok) { From 136c51ef8a61d6cb4bc55c23b7285407e38a5fd0 Mon Sep 17 00:00:00 2001 From: Tiny_Murky Date: Fri, 16 Aug 2024 10:28:14 +0800 Subject: [PATCH 2/7] change test case --- .../api/v1/company/[companyId]/ocr/[resultId]/index.test.ts | 2 +- src/pages/api/v1/company/[companyId]/ocr/index.test.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pages/api/v1/company/[companyId]/ocr/[resultId]/index.test.ts b/src/pages/api/v1/company/[companyId]/ocr/[resultId]/index.test.ts index f8f2c69c1..53ee70f49 100644 --- a/src/pages/api/v1/company/[companyId]/ocr/[resultId]/index.test.ts +++ b/src/pages/api/v1/company/[companyId]/ocr/[resultId]/index.test.ts @@ -58,7 +58,7 @@ describe('fetchOCRResult', () => { const result = await module.fetchOCRResult(resultId); expect(global.fetch).toHaveBeenCalledWith( - expect.stringContaining(`/api/v1/ocr/${resultId}/result`) + expect.stringContaining(`/api/v1/gemini/${resultId}/result`) ); expect(result).toEqual({ payload: 'testPayload' }); diff --git a/src/pages/api/v1/company/[companyId]/ocr/index.test.ts b/src/pages/api/v1/company/[companyId]/ocr/index.test.ts index da8b44bfe..5262dea54 100644 --- a/src/pages/api/v1/company/[companyId]/ocr/index.test.ts +++ b/src/pages/api/v1/company/[companyId]/ocr/index.test.ts @@ -123,7 +123,7 @@ describe('POST OCR', () => { expect(promiseJson).toBeInstanceOf(Promise); expect(global.fetch).toHaveBeenCalledWith( - expect.stringContaining('/ocr/upload'), + expect.stringContaining('/gemini/upload'), expect.objectContaining({ method: 'POST', body: expect.any(FormData) }) ); }); @@ -227,7 +227,7 @@ describe('POST OCR', () => { expect(resultJson).toEqual(resultJsonArrayExpect); expect(global.fetch).toHaveBeenCalledWith( - expect.stringContaining('/ocr/upload'), + expect.stringContaining('/gemini/upload'), expect.objectContaining({ method: 'POST', body: expect.any(FormData) }) ); }); From 3c7b174137e11ce210d3a7660570531b02740f48 Mon Sep 17 00:00:00 2001 From: Luphia Chang Date: Fri, 16 Aug 2024 14:54:29 +0800 Subject: [PATCH 3/7] Update login_confirm_modal.beta.tsx --- src/components/login_confirm_modal/login_confirm_modal.beta.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/login_confirm_modal/login_confirm_modal.beta.tsx b/src/components/login_confirm_modal/login_confirm_modal.beta.tsx index f51020974..e2a5c033c 100644 --- a/src/components/login_confirm_modal/login_confirm_modal.beta.tsx +++ b/src/components/login_confirm_modal/login_confirm_modal.beta.tsx @@ -32,7 +32,7 @@ const LoginConfirmModal: React.FC = ({
-
+
{modalData.content === 'info_collection_statement' && } {modalData.content === 'term_n_privacy' && }
From 76d3acfd0c51251cb1a05bfd13d47abfc3fa49eb Mon Sep 17 00:00:00 2001 From: Luphia Chang Date: Fri, 16 Aug 2024 14:55:13 +0800 Subject: [PATCH 4/7] Update login_page_body.beta.tsx --- src/components/login_page_body/login_page_body.beta.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/login_page_body/login_page_body.beta.tsx b/src/components/login_page_body/login_page_body.beta.tsx index 529acd6a1..963155f2f 100644 --- a/src/components/login_page_body/login_page_body.beta.tsx +++ b/src/components/login_page_body/login_page_body.beta.tsx @@ -186,7 +186,7 @@ const LoginPageBody = () => { return (
-
+
{isLoading ? ( ) : ( From 0601bc36804bcd458493f71fcb2aba668aaae260 Mon Sep 17 00:00:00 2001 From: Luphia Chang Date: Fri, 16 Aug 2024 14:56:21 +0800 Subject: [PATCH 5/7] Update global_context.tsx --- src/contexts/global_context.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/contexts/global_context.tsx b/src/contexts/global_context.tsx index 3775f9a5f..0ffd04fe4 100644 --- a/src/contexts/global_context.tsx +++ b/src/contexts/global_context.tsx @@ -420,7 +420,7 @@ export const GlobalProvider = ({ children }: IGlobalProvider) => { const position = toastPosition ?? ToastPosition.TOP_CENTER; // Info:(20240513 - Julian) default position 'top-center' // Info:(20240513 - Julian) 如果 closeable 為 false,則 autoClose、closeOnClick、draggable 都會被設為 false - const autoClose = closeable ? (isAutoClose ?? 5000) : false; // Info:(20240513 - Julian) default autoClose 5000ms + const autoClose = closeable ? isAutoClose ?? 5000 : false; // Info:(20240513 - Julian) default autoClose 5000ms const closeOnClick = closeable; // Info:(20240513 - Julian) default closeOnClick true const draggable = closeable; // Info:(20240513 - Julian) default draggable true From 3f4f105dd66a32da44a2aab82bf8487595b2c5e2 Mon Sep 17 00:00:00 2001 From: Luphia Chang Date: Fri, 16 Aug 2024 14:56:55 +0800 Subject: [PATCH 6/7] Update use_api.ts --- src/lib/hooks/use_api.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/hooks/use_api.ts b/src/lib/hooks/use_api.ts index dd021df23..9a0ce8174 100644 --- a/src/lib/hooks/use_api.ts +++ b/src/lib/hooks/use_api.ts @@ -68,7 +68,7 @@ const useAPI = ( apiConfig: IAPIConfig, options: IAPIInput, triggerImmediately: boolean = false, - cancel?: boolean + cancel?: boolean, ): IAPIResponse => { const [success, setSuccess] = useState(undefined); const [code, setCode] = useState(undefined); From e55a9a7c90fdd8f4f74799204e1e69fa00aaf77d Mon Sep 17 00:00:00 2001 From: Luphia Chang Date: Fri, 16 Aug 2024 14:57:09 +0800 Subject: [PATCH 7/7] Update use_api_worker.ts --- src/lib/hooks/use_api_worker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/hooks/use_api_worker.ts b/src/lib/hooks/use_api_worker.ts index 19724894a..c1f7c77b7 100644 --- a/src/lib/hooks/use_api_worker.ts +++ b/src/lib/hooks/use_api_worker.ts @@ -8,7 +8,7 @@ const useAPIWorker = ( apiConfig: IAPIConfig, options: IAPIInput, triggerImmediately: boolean = false, - cancel?: boolean + cancel?: boolean, ): IAPIResponse => { const [success, setSuccess] = useState(undefined); const [code, setCode] = useState(undefined);