/**
 * Extracts the S3 key from the provided URL.
 *
 * @param url - The URL from which to extract the S3 key.
 * @param bucketName - The name of the S3 bucket to remove from the URL.
 * @returns The S3 key derived from the URL.
 */
export const extractKeyFromUrl = (url: string, bucketName: string): string => {
  const baseUrlPattern = /^https?:\/\/[^\/]+/;
  const bucketPattern = `/${bucketName}`;
  return decodeURIComponent(
    url.replace(baseUrlPattern, '').replace(bucketPattern, ''),
  );
};
