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