diff --git a/@share/components/Img.tsx b/@share/components/Img.tsx index 4c47372..04beda0 100644 --- a/@share/components/Img.tsx +++ b/@share/components/Img.tsx @@ -52,7 +52,7 @@ const Img = forwardRef((props, ref) => { const imgProps = { style: [style, imageStyle], ref, - placeholder: blurhash, + // placeholder: blurhash, source: imageSource, cachePolicy: 'memory-disk' as const, errorSource, diff --git a/@share/components/Video.tsx b/@share/components/Video.tsx index 4f9c124..9791652 100644 --- a/@share/components/Video.tsx +++ b/@share/components/Video.tsx @@ -1,5 +1,5 @@ import { Image } from 'expo-image' -import { memo, useEffect, useState } from 'react' +import { memo, useEffect, useMemo, useState } from 'react' import { ViewStyle } from 'react-native' import Video from 'react-native-video' @@ -7,19 +7,58 @@ type Props = { url?: string poster?: string style?: ViewStyle + width?: number } & React.ComponentProps -const VideoBox = ({ url, poster, style, ...videoProps }: Props) => { - const [paused, setPaused] = useState(true) +const VideoBox = ({ url, poster, width = 120, style, ...videoProps }: Props) => { + const [urlFinal, setUrlFinal] = useState('') + + const createUrl = (url: string) => { + return `https://modal-dev.bowong.cc/api/custom/video/converter/${encodeURI(url)}?options=compression_level=3,quality=70,loop=true,resolution=${width}x${width},fps=24` + } + + const isImg = (url: any) => { + if (!url) return false + const lowerUrl = url.toLowerCase() + return lowerUrl?.match(/\.(jpg|jpeg|png|gif|webp|bmp|tiff|svg)(\?.*)?$/i) + } + + async function resolveRedirect(url: string) { + const res = await fetch(url, { + method: 'GET', + headers: { + Range: 'bytes=0-0', + }, + }) + return res.url + } + + const setRedirectUrl = async (url?: string) => { + const isImg2 = isImg(url) + if (isImg2) { + setUrlFinal(url!) + return + } + + const webpUrl = createUrl(url!) + const finalUrl = await resolveRedirect(webpUrl) + // console.log('finalUrl-----------', finalUrl) + setUrlFinal(finalUrl!) + } useEffect(() => { - console.log('url--------', url); + if (!url) return + setRedirectUrl(url!) + // const finalUrl = createUrl(url) + // console.log('finalUrl-----------', finalUrl) - setPaused(!Boolean(url)) + // setUrlFinal(finalUrl) + return }, [url]) - const createUrl = (url: string)=>`https://modal-dev.bowong.cc/api/custom/video/converter/${encodeURI(url)}?options=compression_level=3,quality=70,loop=true,resolution=120x120,fps=24` + // console.log('urlFinal--------- ', urlFinal, url) + if (!url) return null return ( // 当 url 变化时通过 key 强制重载,确保自动播放生效 //