Gmagl
Fix: Complete TypeScript strict typing for all API routes
5cff373
raw
history blame
2.7 kB
import { NextRequest, NextResponse } from "next/server";
import { db } from "@/lib/db";
interface PlatformConfig {
name: string;
type: string;
fee: number;
adultContent: boolean;
legal: string;
}
const PLATFORM_CONFIGS: Record<string, PlatformConfig> = {
onlyfans: { name: "OnlyFans", type: "subscription", fee: 20, adultContent: true, legal: "Adult content permitido, verificar edad" },
patreon: { name: "Patreon", type: "subscription", fee: 12, adultContent: false, legal: "Restricciones en adult content" },
fansly: { name: "Fansly", type: "subscription", fee: 20, adultContent: true, legal: "Adult content permitido" },
fanvue: { name: "Fanvue", type: "subscription", fee: 15, adultContent: true, legal: "Adult content permitido" },
kofi: { name: "Ko-fi", type: "tips", fee: 0, adultContent: false, legal: "Sin adult content" },
instagram: { name: "Instagram", type: "free", fee: 0, adultContent: false, legal: "Sin desnudez" },
tiktok: { name: "TikTok", type: "free", fee: 0, adultContent: false, legal: "Contenido familiar" },
youtube: { name: "YouTube", type: "free", fee: 0, adultContent: false, legal: "Politicas de comunidad estrictas" }
};
export async function GET(request: NextRequest) {
try {
const { searchParams } = new URL(request.url);
const platform = searchParams.get("platform");
const userPlatforms = await db.monetizationPlatform.findMany({ where: { isActive: true } });
if (platform && PLATFORM_CONFIGS[platform]) {
return NextResponse.json({ success: true, platform: PLATFORM_CONFIGS[platform], userPlatforms });
}
return NextResponse.json({ success: true, platforms: PLATFORM_CONFIGS, userPlatforms });
} catch {
return NextResponse.json({ success: false, error: "Error" }, { status: 500 });
}
}
export async function POST(request: NextRequest) {
try {
const body = await request.json();
const { platformName, accountId, accountName } = body;
const config = PLATFORM_CONFIGS[platformName];
if (!config) {
return NextResponse.json({ success: false, error: "Plataforma no valida" }, { status: 400 });
}
const platform = await db.monetizationPlatform.create({
data: {
name: config.name,
type: config.type,
accountId: accountId || null,
accountName: accountName || null,
feePercentage: config.fee,
legalTerms: JSON.stringify({ adultContent: config.adultContent, legal: config.legal }),
isActive: true,
isVerified: false
}
});
return NextResponse.json({ success: true, platform });
} catch {
return NextResponse.json({ success: false, error: "Error" }, { status: 500 });
}
}