mirror of
https://github.com/mito-systems/ranger-app.git
synced 2026-03-24 08:24:09 +00:00
ok
This commit is contained in:
parent
390b2a205d
commit
dcd7161a64
@ -251,14 +251,26 @@ export async function POST(req: NextRequest): Promise<NextResponse> {
|
||||
|
||||
if (pointsUserId && userEmail) {
|
||||
console.log('Awarding points to user:', { pointsUserId, userEmail });
|
||||
await awardPointsForImage(
|
||||
pointsUserId,
|
||||
userEmail,
|
||||
buffer,
|
||||
ipfsUrl,
|
||||
visionResult.description,
|
||||
visionResult.mainObject
|
||||
).catch(err => console.error('Failed to award points for image:', err));
|
||||
try {
|
||||
const pointsResult = await awardPointsForImage(
|
||||
pointsUserId,
|
||||
userEmail,
|
||||
buffer,
|
||||
ipfsUrl,
|
||||
visionResult.description,
|
||||
visionResult.mainObject
|
||||
);
|
||||
console.log('Points award result:', pointsResult);
|
||||
} catch (err) {
|
||||
console.error('Failed to award points for image:', err);
|
||||
console.error('Points error details:', {
|
||||
error: err.message || 'Unknown error',
|
||||
userId: pointsUserId,
|
||||
userEmail,
|
||||
imageHash: ipfsUrl ? ipfsUrl.split('/').pop() : 'unknown'
|
||||
});
|
||||
// Continue without points if there's an error
|
||||
}
|
||||
} else {
|
||||
console.log('Unable to award points, missing user data', {
|
||||
pointsUserId,
|
||||
|
||||
@ -104,6 +104,18 @@ export async function awardPointsForImage(
|
||||
animalType: string
|
||||
) {
|
||||
try {
|
||||
// Add safe mode to bypass database operations if needed
|
||||
// This allows the app to work during database schema transitions
|
||||
const safeMode = process.env.POINTS_SAFE_MODE === 'true';
|
||||
if (safeMode) {
|
||||
console.log('Points system running in SAFE MODE - bypassing database operations');
|
||||
return {
|
||||
success: true,
|
||||
points: POINTS.IMAGE_UPLOAD,
|
||||
message: 'Points system in safe mode, database operations bypassed'
|
||||
};
|
||||
}
|
||||
|
||||
if (!userId) {
|
||||
console.warn('Missing user data, cannot award points', { userId, email });
|
||||
return {
|
||||
@ -267,6 +279,13 @@ export async function findUserByEmail(email: string) {
|
||||
*/
|
||||
export async function getUserPoints(userId: string) {
|
||||
try {
|
||||
// Add safe mode to bypass database operations if needed
|
||||
const safeMode = process.env.POINTS_SAFE_MODE === 'true';
|
||||
if (safeMode) {
|
||||
console.log('Points system running in SAFE MODE - returning default points');
|
||||
return 1; // Return 1 as a default so UI shows something
|
||||
}
|
||||
|
||||
if (!userId) {
|
||||
console.warn('Cannot get points for undefined userId');
|
||||
return 0;
|
||||
@ -335,6 +354,24 @@ export async function getUserPoints(userId: string) {
|
||||
*/
|
||||
export async function getUserTransactions(userId: string) {
|
||||
try {
|
||||
// Add safe mode to bypass database operations if needed
|
||||
const safeMode = process.env.POINTS_SAFE_MODE === 'true';
|
||||
if (safeMode) {
|
||||
console.log('Points system running in SAFE MODE - returning sample transaction');
|
||||
// Return a sample transaction for UI display
|
||||
return [{
|
||||
id: 1,
|
||||
user_id: userId,
|
||||
points: 1,
|
||||
transaction_type: 'image_upload',
|
||||
image_hash: null,
|
||||
image_url: null,
|
||||
description: 'Sample transaction during database migration',
|
||||
animal_type: 'Sample',
|
||||
created_at: new Date().toISOString()
|
||||
}];
|
||||
}
|
||||
|
||||
if (!userId) {
|
||||
console.warn('Cannot get transactions for undefined userId');
|
||||
return [];
|
||||
|
||||
Loading…
Reference in New Issue
Block a user