mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-19 14:33:38 +00:00
* refactor: Remove Unused Agent Helpers and Superseded Wrappers * refactor: Remove Dead Auth, Middleware, Protection and Prompt Helpers * refactor: Remove Dead MCP, File, Skill and Endpoint Code * refactor: Remove Dead Stream, Telemetry, Utility and Type Exports * chore: Drop Unused packages/api Dependencies From bun.lock * refactor: Keep Published Compatibility and Deprecated packages/api Exports
23 lines
714 B
TypeScript
23 lines
714 B
TypeScript
import path from 'path';
|
|
import { URL } from 'url';
|
|
|
|
const imageExtensionRegex = /\.(jpg|jpeg|png|gif|bmp|tiff|svg|webp)$/i;
|
|
|
|
/**
|
|
* Extracts the image basename from a given URL.
|
|
*
|
|
* @param urlString - The URL string from which the image basename is to be extracted.
|
|
* @returns The basename of the image file from the URL.
|
|
* Returns an empty string if the URL does not contain a valid image basename.
|
|
*/
|
|
export function getImageBasename(urlString: string): string {
|
|
try {
|
|
const url = new URL(urlString);
|
|
const basename = path.basename(url.pathname);
|
|
|
|
return imageExtensionRegex.test(basename) ? basename : '';
|
|
} catch {
|
|
// If URL parsing fails, return an empty string
|
|
return '';
|
|
}
|
|
}
|