feat(tool-workspace): add default image cropper, dynamic remaining quota badge, clean studio header, and larger title
This commit is contained in:
@@ -147,6 +147,7 @@ export async function POST(req: NextRequest, { params }: { params: { toolId: str
|
||||
|
||||
// Record rate-limit usage
|
||||
recordUsage(visitorId, ip);
|
||||
const remainingAfterUsage = Math.max(0, rateCheck.remainingToday - 1);
|
||||
|
||||
// Call backend or mock engine
|
||||
const { buffer: resultBuffer, contentType } = await executeBackendTryIt(
|
||||
@@ -164,7 +165,7 @@ export async function POST(req: NextRequest, { params }: { params: { toolId: str
|
||||
'Content-Type': contentType,
|
||||
'Content-Length': resultBuffer.length.toString(),
|
||||
'Cache-Control': 'no-store, no-cache, must-revalidate',
|
||||
'X-Remaining-Tries': rateCheck.remainingToday.toString(),
|
||||
'X-Remaining-Tries': remainingAfterUsage.toString(),
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { checkRateLimits } from '@/lib/api/rateLimiter';
|
||||
|
||||
export const dynamic = 'force-dynamic';
|
||||
export const revalidate = 0;
|
||||
|
||||
export async function GET(req: NextRequest) {
|
||||
const ip = req.headers.get('x-forwarded-for')?.split(',')[0].trim() || '127.0.0.1';
|
||||
let visitorId = req.cookies.get('photoai_vid')?.value;
|
||||
let isNewVisitor = false;
|
||||
if (!visitorId) {
|
||||
visitorId = 'v_' + Math.random().toString(36).substring(2, 15);
|
||||
isNewVisitor = true;
|
||||
}
|
||||
|
||||
const rateCheck = checkRateLimits(visitorId, ip);
|
||||
const response = NextResponse.json({
|
||||
allowed: rateCheck.allowed,
|
||||
remainingToday: rateCheck.remainingToday,
|
||||
limit: 5,
|
||||
timestamp: Date.now(),
|
||||
}, {
|
||||
headers: {
|
||||
'Cache-Control': 'no-store, no-cache, must-revalidate',
|
||||
},
|
||||
});
|
||||
|
||||
if (isNewVisitor) {
|
||||
response.cookies.set('photoai_vid', visitorId, {
|
||||
path: '/',
|
||||
maxAge: 60 * 60 * 24 * 30,
|
||||
httpOnly: true,
|
||||
sameSite: 'lax',
|
||||
});
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
Reference in New Issue
Block a user