mirror of
https://github.com/lone-cloud/gerbil
synced 2026-06-04 12:13:28 -07:00
31 lines
732 B
TypeScript
31 lines
732 B
TypeScript
const isValidUrl = (string: string): boolean => {
|
|
try {
|
|
const url = new URL(string);
|
|
return url.protocol === 'http:' || url.protocol === 'https:';
|
|
} catch {
|
|
return false;
|
|
}
|
|
};
|
|
|
|
const isValidFilePath = (path: string): boolean => {
|
|
if (!path.trim()) return false;
|
|
|
|
const validExtensions = ['.gguf'];
|
|
const hasValidExtension = validExtensions.some((ext) =>
|
|
path.toLowerCase().endsWith(ext)
|
|
);
|
|
|
|
return hasValidExtension || path.includes('/') || path.includes('\\');
|
|
};
|
|
|
|
export const getInputValidationState = (
|
|
path: string
|
|
): 'valid' | 'invalid' | 'neutral' => {
|
|
if (!path.trim()) return 'neutral';
|
|
|
|
if (isValidUrl(path) || isValidFilePath(path)) {
|
|
return 'valid';
|
|
}
|
|
|
|
return 'invalid';
|
|
};
|