From 5f2cd718a8b1ed8367112af9b1d9261851f4d7e9 Mon Sep 17 00:00:00 2001 From: zramsay Date: Fri, 24 Jan 2025 10:37:14 -0500 Subject: [PATCH] fix --- src/services/laconicService.ts | 45 +++++++++++----------------------- 1 file changed, 14 insertions(+), 31 deletions(-) diff --git a/src/services/laconicService.ts b/src/services/laconicService.ts index 157084a..3f200e9 100644 --- a/src/services/laconicService.ts +++ b/src/services/laconicService.ts @@ -1,16 +1,11 @@ -// src/services/laconicService.ts - import { promises as fs } from 'fs' -import { exec } from 'child_process' -import { promisify } from 'util' import yaml from 'yaml' - -const execAsync = promisify(exec) +import axios from 'axios' interface LaconicAnimalRecord { record: { type: 'AnimalRecord' - mainObject: string // changed from species + mainObject: string location: { latitude: number longitude: number @@ -22,7 +17,7 @@ interface LaconicAnimalRecord { } export async function publishAnimalRecord( - mainObject: string, // changed parameter name + mainObject: string, latitude: number, longitude: number, description: string, @@ -30,43 +25,31 @@ export async function publishAnimalRecord( portalName: string ): Promise { try { - // Verify config file exists - await fs.access('config.yml') - - // Create animal record const record: LaconicAnimalRecord = { record: { type: 'AnimalRecord', - mainObject, // use mainObject instead of species + mainObject, location: { latitude, longitude }, description, imageUrl, - portalName + portalName } } - // Write temporary record file - const recordPath = 'animal-record.yml' - await fs.writeFile(recordPath, yaml.stringify(record)) - - try { - // Execute laconic command - const { stdout, stderr } = await execAsync( - `laconic -c config.yml registry record publish --filename animal-record.yml --user-key "${process.env.LACONIC_USER_KEY}" --bond-id "${process.env.LACONIC_BOND_ID}"` - ) - - if (stderr) { - console.error('Laconic command stderr:', stderr) + const response = await axios.post('http://143.198.37.25:3000/publishRecord', { + yamlContent: yaml.stringify(record) + }, { + headers: { + 'Authorization': `Bearer 1234`, //${process.env.LACONIC_AUTH_TOKEN}`, + 'Content-Type': 'application/json' } + }) + + return response.data.output - return stdout.trim() - } finally { - // Clean up temporary file - await fs.unlink(recordPath).catch(console.error) - } } catch (error) { console.error('Failed to publish animal record:', error) throw error