pummmp.fun/app/api/miner/buy/route.ts
2026-07-04 12:49:09 -07:00

81 lines
No EOL
2.8 KiB
TypeScript

import { NextRequest, NextResponse } from 'next/server'
import { getServerSession } from 'next-auth'
import { authOptions } from '@/lib/auth'
import { connectToDatabase } from '@/lib/mongodb'
import { ObjectId } from 'mongodb'
export async function POST(request: NextRequest) {
return NextResponse.json({ error: 'Miners are temporarily disabled by administrators' }, { status: 503 })
// try {
// const session = await getServerSession(authOptions)
// if (!session?.user?.id) {
// return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
// }
// const { coinId } = await request.json()
// if (!coinId) {
// return NextResponse.json({ error: 'Coin ID required' }, { status: 400 })
// }
// const { db } = await connectToDatabase()
// // Check if user already has a miner for this coin (allow multiple)
// // const existingMiner = await db.collection('miners').findOne({
// // userId: session.user.id,
// // coinId: coinId,
// // isActive: true
// // })
// // if (existingMiner) {
// // await client.close()
// // return NextResponse.json({ error: 'You already have a miner for this coin' }, { status: 400 })
// // }
// // Check user's balance
// const user = await db.collection('users').findOne({ _id: new ObjectId(session.user.id) })
// if (!user) {
// return NextResponse.json({ error: 'User not found' }, { status: 404 })
// }
// // Check trade ban (prevent buying miners)
// if (user.tradeBannedUntil) {
// const banExpiry = new Date(user.tradeBannedUntil);
// if (banExpiry > new Date()) {
// return NextResponse.json({ error: 'You are banned from trading/mining actions' }, { status: 403 })
// } else {
// try { await db.collection('users').updateOne({ _id: user._id }, { $unset: { tradeBannedUntil: 1 } }) } catch (e) {}
// }
// }
// if (user.balance < 3) {
// return NextResponse.json({ error: 'Insufficient balance. Need 3 SOL to buy a miner' }, { status: 400 })
// }
// // Deduct 3 SOL from balance
// await db.collection('users').updateOne(
// { _id: new ObjectId(session.user.id) },
// { $inc: { balance: -3 } }
// )
// // Create miner
// const miner = {
// userId: session.user.id,
// coinId: coinId,
// purchasedAt: new Date(),
// lastCollectedAt: new Date(),
// isActive: true
// }
// await db.collection('miners').insertOne(miner)
// return NextResponse.json({
// success: true,
// message: 'Miner purchased successfully! Started mining at 1000 tokens/second.'
// })
// } catch (error) {
// console.error('Error buying miner:', error)
// return NextResponse.json({ error: 'Internal server error' }, { status: 500 })
// }
}