mirror of
https://github.com/yusufipk/OpenFrame.git
synced 2026-09-11 17:46:06 +00:00
feat(progress): add validation for duration to ensure it is a non-negative finite number
This commit is contained in:
@@ -55,6 +55,10 @@ export async function PATCH(request: NextRequest, { params }: RouteParams) {
|
|||||||
const body = await request.json();
|
const body = await request.json();
|
||||||
const { duration, versionLabel, isActive } = body;
|
const { duration, versionLabel, isActive } = body;
|
||||||
|
|
||||||
|
if (duration !== undefined && (typeof duration !== 'number' || !isFinite(duration) || duration < 0)) {
|
||||||
|
return apiErrors.badRequest('Invalid duration value');
|
||||||
|
}
|
||||||
|
|
||||||
const updateData: Record<string, unknown> = {};
|
const updateData: Record<string, unknown> = {};
|
||||||
if (duration !== undefined) updateData.duration = duration;
|
if (duration !== undefined) updateData.duration = duration;
|
||||||
if (versionLabel !== undefined) updateData.versionLabel = versionLabel?.trim() || null;
|
if (versionLabel !== undefined) updateData.versionLabel = versionLabel?.trim() || null;
|
||||||
|
|||||||
@@ -85,10 +85,14 @@ export async function POST(request: NextRequest, { params }: RouteParams) {
|
|||||||
const body = await request.json();
|
const body = await request.json();
|
||||||
const { progress, duration, versionId } = body;
|
const { progress, duration, versionId } = body;
|
||||||
|
|
||||||
if (typeof progress !== 'number' || progress < 0) {
|
if (typeof progress !== 'number' || !isFinite(progress) || progress < 0) {
|
||||||
return apiErrors.badRequest('Invalid progress value');
|
return apiErrors.badRequest('Invalid progress value');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (duration !== undefined && (typeof duration !== 'number' || !isFinite(duration) || duration < 0)) {
|
||||||
|
return apiErrors.badRequest('Invalid duration value');
|
||||||
|
}
|
||||||
|
|
||||||
if (versionId !== undefined && typeof versionId !== 'string') {
|
if (versionId !== undefined && typeof versionId !== 'string') {
|
||||||
return apiErrors.badRequest('Invalid versionId');
|
return apiErrors.badRequest('Invalid versionId');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user