Initial admin edits
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
import { BadRequestException } from '@nestjs/common';
|
||||
|
||||
/** مسیر داخلی (`/…`) یا URL با http/https */
|
||||
export function normalizeBannerLink(value?: string | null): string | null {
|
||||
if (value == null || value === '') return null;
|
||||
const link = value.trim();
|
||||
if (!link) return null;
|
||||
if (link.startsWith('/')) {
|
||||
if (!/^\/[^\s]*$/.test(link)) {
|
||||
throw new BadRequestException('لینک بنر نامعتبر است');
|
||||
}
|
||||
return link;
|
||||
}
|
||||
try {
|
||||
const url = new URL(link);
|
||||
if (url.protocol !== 'http:' && url.protocol !== 'https:') {
|
||||
throw new Error('invalid protocol');
|
||||
}
|
||||
return link;
|
||||
} catch {
|
||||
throw new BadRequestException('لینک بنر نامعتبر است');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user