get-image-url-fix
This commit is contained in:
parent
e796fa30a4
commit
fc601c747e
|
@ -1,6 +1,7 @@
|
|||
export const isDev = import.meta.env.MODE === 'development'
|
||||
|
||||
const defaultThumborUrl = 'https://images.discours.io'
|
||||
export const cdnUrl = 'https://cdn.discours.io'
|
||||
export const thumborUrl = import.meta.env.PUBLIC_THUMBOR_URL || defaultThumborUrl
|
||||
|
||||
export const SENTRY_DSN = import.meta.env.PUBLIC_SENTRY_DSN || ''
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
import { thumborUrl } from './config'
|
||||
|
||||
const thumborPrefix = `${thumborUrl}/unsafe/`
|
||||
import { thumborUrl, cdnUrl } from './config'
|
||||
|
||||
const getSizeUrlPart = (options: { width?: number; height?: number } = {}) => {
|
||||
const widthString = options.width ? options.width.toString() : ''
|
||||
|
@ -17,21 +15,16 @@ export const getImageUrl = (
|
|||
src: string,
|
||||
options: { width?: number; height?: number; noSizeUrlPart?: boolean } = {},
|
||||
) => {
|
||||
const sizeUrlPart = getSizeUrlPart(options)
|
||||
|
||||
let modifiedSrc = src // Используйте новую переменную вместо переназначения параметра
|
||||
const isAudio = src.toLowerCase().split('.')[-1] in ['wav', 'mp3', 'ogg', 'aif', 'flac']
|
||||
const base = isAudio ? cdnUrl : thumborUrl
|
||||
const sizeUrlPart = isAudio ? '' : getSizeUrlPart(options)
|
||||
let modifiedSrc = src.replaceAll(thumborUrl + '/', '').replaceAll(cdnUrl + '/', '') // Используйте новую переменную вместо переназначения параметра
|
||||
|
||||
if (options.noSizeUrlPart) {
|
||||
modifiedSrc = modifiedSrc.replace(/\d+x.*?\//, '')
|
||||
}
|
||||
|
||||
if (src.startsWith(thumborPrefix)) {
|
||||
const thumborKey = modifiedSrc.replace(thumborPrefix, '')
|
||||
|
||||
return `${thumborUrl}/unsafe/${sizeUrlPart}${thumborKey}`
|
||||
}
|
||||
|
||||
return `${thumborUrl}/unsafe/${sizeUrlPart}${modifiedSrc}`
|
||||
return `${base}/unsafe/${sizeUrlPart}${modifiedSrc}`
|
||||
}
|
||||
|
||||
export const getOpenGraphImageUrl = (
|
||||
|
@ -50,8 +43,8 @@ export const getOpenGraphImageUrl = (
|
|||
options.author,
|
||||
)}','${encodeURIComponent(options.title)}')/`
|
||||
|
||||
if (src.startsWith(thumborPrefix)) {
|
||||
const thumborKey = src.replace(thumborPrefix, '')
|
||||
if (src.startsWith(thumborUrl)) {
|
||||
const thumborKey = src.replace(thumborUrl + '/unsafe', '')
|
||||
return `${thumborUrl}/unsafe/${sizeUrlPart}${filtersPart}${thumborKey}`
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user