fix
This commit is contained in:
parent
a8666c94e3
commit
5f2cd718a8
@ -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<string> {
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user