From 504d3faefca7342c880e8be77faa6d7db9759e4d Mon Sep 17 00:00:00 2001 From: Untone Date: Tue, 23 Jan 2024 18:21:37 +0300 Subject: [PATCH] zoom-url-fix-3 --- src/utils/getImageUrl.ts | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/src/utils/getImageUrl.ts b/src/utils/getImageUrl.ts index e2d17ada..23367c47 100644 --- a/src/utils/getImageUrl.ts +++ b/src/utils/getImageUrl.ts @@ -1,10 +1,10 @@ import { thumborUrl, cdnUrl } from './config' -const getSizeUrlPart = (options: { width?: number; height?: number } = {}) => { +const getSizeUrlPart = (options: { width?: number; height?: number; noSizeUrlPart?: boolean } = {}) => { const widthString = options.width ? options.width.toString() : '' const heightString = options.height ? options.height.toString() : '' - if (!widthString && !heightString) { + if ((!widthString && !heightString) || options.noSizeUrlPart) { return '' } @@ -15,21 +15,12 @@ export const getImageUrl = ( src: string, options: { width?: number; height?: number; noSizeUrlPart?: boolean } = {}, ) => { + const filename = src.split('/')[-1] const isAudio = src.toLowerCase().split('.')[-1] in ['wav', 'mp3', 'ogg', 'aif', 'flac'] - const base = (isAudio ? cdnUrl : thumborUrl).replaceAll('unsafe/', '') + const base = isAudio ? cdnUrl : `${thumborUrl}/unsafe/` const sizeUrlPart = isAudio ? '' : getSizeUrlPart(options) - // Используйте новую переменную вместо переназначения параметра - let modifiedSrc = src - .replaceAll(thumborUrl + '/', '') - .replaceAll(cdnUrl + '/', '') - .replaceAll('unsafe/', '') - - if (options.noSizeUrlPart) { - modifiedSrc = modifiedSrc.replace(/\d+x.*?\//, '') - } - - return `${base}/unsafe/${sizeUrlPart}${modifiedSrc}` + return `${base}${sizeUrlPart}production/${isAudio ? 'audio' : 'image'}/${filename}` } export const getOpenGraphImageUrl = (