feat(validation): relax Instagram URL validation to support all content types
- Create validateInstagramUrl utility using URL constructor - Replace regex-based validation with hostname and protocol checks - Support posts, reels, IGTV, and URLs with query parameters - Add comprehensive unit tests (22 tests, all passing) - Add integration tests for new URL formats - Update API documentation with supported URL formats Closes: #RelaxInstagramUrlValidation
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
|
||||
import { json, error } from '@sveltejs/kit';
|
||||
import { queueManager } from '$lib/server/queue/QueueManager';
|
||||
import { validateInstagramUrl } from '$lib/server/validation/instagram-url';
|
||||
import type { RequestHandler } from './$types';
|
||||
|
||||
/**
|
||||
@@ -41,12 +42,10 @@ export const POST: RequestHandler = async ({ request }) => {
|
||||
return error(400, { message: 'URL is required and must be a string' });
|
||||
}
|
||||
|
||||
// Validate Instagram URL format
|
||||
const instagramUrlPattern = /^https:\/\/(www\.)?instagram\.com\/p\/[a-zA-Z0-9_-]+\/?$/;
|
||||
if (!instagramUrlPattern.test(url)) {
|
||||
return error(400, {
|
||||
message: 'Invalid Instagram URL format. Expected: https://instagram.com/p/{post-id}'
|
||||
});
|
||||
// Validate Instagram URL format using utility
|
||||
const validation = validateInstagramUrl(url);
|
||||
if (!validation.valid) {
|
||||
return error(400, { message: validation.error || 'Invalid Instagram URL' });
|
||||
}
|
||||
|
||||
// Enqueue the URL
|
||||
|
||||
Reference in New Issue
Block a user