import axios from 'axios'; declare let process: any; export enum BulkTypes { mongodb = 'mongodb', es = 'es', pg = 'pg', } const api = process.env.API_HOST; const bulkApi = `${api}/bulk`; export async function sendItemsToEsApi(index, key, items) { const secret = process.env.API_SECRET; if (!secret) { throw new Error('sendEsItemsToApi 没有 secret'); } try { const resp = await axios.post(bulkApi, { index, key, items, secret, bulk_type: BulkTypes.es, }); return resp; } catch (error: any) { return null } } export async function sendItemsToMongoApi(dbName, colName, key, items) { const secret = process.env.API_SECRET; if (!secret) { throw new Error('sendItemsToMongoApi 没有 secret'); } console.info('%c--------- sendItemsToMongoApi --------- ', 'background:yellow; color:blue; font-weight:600;'); try { const resp = await axios.post(bulkApi, { dbName, colName, key, items, secret, bulk_type: BulkTypes.mongodb, }); return resp; } catch (error: any) { console.error('sendItemsToMongoApi error', error); return null; } }