From 11f5907d4ed2a8f2d2ec48ca18a0daa9f44bdc44 Mon Sep 17 00:00:00 2001 From: km2025 Date: Fri, 26 Dec 2025 15:18:07 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=20Img=20=E5=92=8C=20?= =?UTF-8?q?Video=20=E7=BB=84=E4=BB=B6=EF=BC=8C=E4=BC=98=E5=8C=96=E8=A7=86?= =?UTF-8?q?=E9=A2=91=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91=EF=BC=8C=E8=B0=83?= =?UTF-8?q?=E6=95=B4=E6=94=AF=E4=BB=98=E5=AE=9D=E6=94=AF=E4=BB=98=E6=96=B9?= =?UTF-8?q?=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- @share/components/Img.tsx | 2 +- @share/components/Video.tsx | 53 +++++++++++++++++--- app/(tabs)/sync.tsx | 99 +++++++++++++++++-------------------- app/pointList.native.tsx | 4 +- 4 files changed, 93 insertions(+), 65 deletions(-) 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 强制重载,确保自动播放生效 //