mirror of
https://github.com/mito-systems/ranger-app.git
synced 2026-02-27 00:44:08 +00:00
ffs
This commit is contained in:
parent
77ec24e763
commit
2fa41d75b2
@ -236,12 +236,16 @@ export async function POST(req: NextRequest): Promise<NextResponse> {
|
||||
// Process the animal image and get the IPFS URL
|
||||
let ipfsUrl = '';
|
||||
try {
|
||||
// Ensure we have a valid userId before passing to processAnimalImage
|
||||
const validUserId = userId || '00000000-0000-0000-0000-000000000000';
|
||||
console.log('Using userId for animal processing:', validUserId);
|
||||
|
||||
ipfsUrl = await processAnimalImage(
|
||||
buffer,
|
||||
visionResult.description,
|
||||
visionResult.rawResponse,
|
||||
fileName,
|
||||
userId
|
||||
validUserId
|
||||
);
|
||||
|
||||
// Award points to the user for uploading a valid animal image
|
||||
|
||||
@ -77,7 +77,7 @@ export async function processAnimalImage(
|
||||
visionDescription: string,
|
||||
visionResponse: any,
|
||||
filename: string = 'animal-image.jpg',
|
||||
userId?: string
|
||||
userId: string
|
||||
) {
|
||||
try {
|
||||
// Get coordinates
|
||||
@ -94,6 +94,12 @@ export async function processAnimalImage(
|
||||
)?.description || 'unknown'
|
||||
console.log('Detected species:', species)
|
||||
|
||||
// Make sure we have a valid userId
|
||||
if (!userId) {
|
||||
userId = 'anonymous';
|
||||
console.warn('No userId provided for animal record, using anonymous');
|
||||
}
|
||||
|
||||
const registryId = await publishAnimalRecord(
|
||||
species.toLowerCase(),
|
||||
coordinates.lat,
|
||||
@ -101,13 +107,19 @@ export async function processAnimalImage(
|
||||
visionDescription,
|
||||
ipfsUrl,
|
||||
process.env.NEXT_PUBLIC_PORTAL_NAME,
|
||||
userId || 'unknown'
|
||||
userId
|
||||
)
|
||||
|
||||
console.log('Published animal record to Laconic Registry:', registryId)
|
||||
return ipfsUrl
|
||||
} catch (error) {
|
||||
console.error('Failed to process animal image:', error)
|
||||
// Provide more detailed error logging
|
||||
console.error('Failed to process animal image:', {
|
||||
error: error.message || String(error),
|
||||
species: visionResponse?.labelAnnotations?.length > 0 ?
|
||||
visionResponse.labelAnnotations[0].description : 'unknown',
|
||||
userId
|
||||
})
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
@ -13,7 +13,7 @@ interface LaconicAnimalRecord {
|
||||
description: string
|
||||
imageUrl: string
|
||||
portalName: string
|
||||
userId: string
|
||||
userId: string // Single, consistent way to include userId
|
||||
}
|
||||
}
|
||||
|
||||
@ -24,9 +24,10 @@ export async function publishAnimalRecord(
|
||||
description: string,
|
||||
imageUrl: string,
|
||||
portalName: string,
|
||||
userId: string
|
||||
userId: string // Keep this required
|
||||
): Promise<string> {
|
||||
try {
|
||||
// Create the record with required fields including contributor field for userId
|
||||
const record: LaconicAnimalRecord = {
|
||||
record: {
|
||||
type: 'AnimalRecord',
|
||||
@ -38,7 +39,7 @@ export async function publishAnimalRecord(
|
||||
description,
|
||||
imageUrl,
|
||||
portalName,
|
||||
userId
|
||||
userId // Consistent place for userId
|
||||
}
|
||||
}
|
||||
|
||||
@ -54,7 +55,20 @@ export async function publishAnimalRecord(
|
||||
return response.data.output
|
||||
|
||||
} catch (error) {
|
||||
console.error('Failed to publish animal record:', error)
|
||||
// Log request details for debugging
|
||||
console.error('Failed to publish animal record:', {
|
||||
error: error.message,
|
||||
status: axios.isAxiosError(error) ? error.response?.status : 'unknown',
|
||||
data: axios.isAxiosError(error) ? error.response?.data : 'unknown',
|
||||
recordData: {
|
||||
mainObject,
|
||||
location: { latitude, longitude },
|
||||
imageUrl: imageUrl.substring(0, 30) + '...', // Truncate for log readability
|
||||
userId,
|
||||
yamlSize: yaml.stringify(record).length
|
||||
}
|
||||
})
|
||||
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user