import axios from 'axios' import { getAccessToken } from '../get-access-token' import { Buffer } from 'buffer' interface Response { excel_file: string suffix: string name: string } const table2Excel = async (tableImage: Buffer, config: {apiKey: string , secretKey: string}): Promise => { const {apiKey, secretKey} = config try { const {access_token: accessToken} = await getAccessToken({AK:apiKey, SK:secretKey}) const res = await axios.post( `https://aip.baidubce.com/rest/2.0/ocr/v1/table?access_token=${accessToken}`, { image: tableImage, cell_contents:false, return_excel:true }, { headers: { "Accept": "application/json", "Content-Type": "application/x-www-form-urlencoded" } } ) const {excel_file, suffix, name} = res?.data const result = Buffer.from(excel_file, 'base64') return result } catch (err) { return undefined } } export { table2Excel }