Skip to content

Commit 053517d

Browse files
committed
feat(mobile): Add image headers for cross-origin image loading
Enhance image loading across multiple components by: - Importing `getImageHeaders` utility function - Adding custom headers to image sources to resolve cross-origin issues - Improving image rendering with transition and recycling key support Signed-off-by: Innei <tukon479@gmail.com>
1 parent 113c404 commit 053517d

File tree

6 files changed

+23
-5
lines changed

6 files changed

+23
-5
lines changed

apps/mobile/src/components/ui/image/PreviewPageProvider.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,6 @@ export const PreviewImageProvider = ({ children }: { children: React.ReactNode }
320320
],
321321
}))
322322

323-
// 更新动画样式
324323
const modalStyle = useAnimatedStyle(() => ({
325324
opacity: opacity.value,
326325
}))

apps/mobile/src/lib/image.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export const getImageHeaders = (url: string) => {
2+
if (url.startsWith("https://cdnfile.sspai.com")) {
3+
return {
4+
Referer: "https://sspai.com",
5+
}
6+
}
7+
8+
return {}
9+
}

apps/mobile/src/modules/discover/search-tabs/SearchFeed.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import Animated, { FadeInUp } from "react-native-reanimated"
1212
import { FeedIcon } from "@/src/components/ui/icon/feed-icon"
1313
import { ItemPressable } from "@/src/components/ui/pressable/ItemPressable"
1414
import { apiClient } from "@/src/lib/api-fetch"
15+
import { getImageHeaders } from "@/src/lib/image"
1516
import { useSubscriptionByFeedId } from "@/src/store/subscription/hooks"
1617

1718
import { useSearchPageContext } from "../ctx"
@@ -160,7 +161,7 @@ const PreviewItem = ({ entry }: { entry: NonNullable<SearchResultItem["entries"]
160161
{!!firstMedia && (
161162
<View className="bg-gray-6 ml-auto size-[52px] shrink-0 overflow-hidden rounded-lg">
162163
<Image
163-
source={firstMedia.url}
164+
source={{ uri: firstMedia.url, headers: getImageHeaders(firstMedia.url) }}
164165
className="size-full rounded-lg"
165166
contentFit="cover"
166167
transition={500}

apps/mobile/src/modules/entry-list/templates/EntryGridItem.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { ReAnimatedPressable } from "@/src/components/common/AnimatedComponents"
88
import { PreviewImage } from "@/src/components/ui/image/PreviewImage"
99
import { ItemPressable } from "@/src/components/ui/pressable/ItemPressable"
1010
import { CloseCuteReIcon } from "@/src/icons/close_cute_re"
11+
import { getImageHeaders } from "@/src/lib/image"
1112
import { useEntry } from "@/src/store/entry/hooks"
1213

1314
import { useSelectedView } from "../../screen/atoms"
@@ -57,7 +58,7 @@ export function EntryGridItem({ id }: { id: string }) {
5758
}}
5859
>
5960
<Image
60-
source={{ uri: imageUrl }}
61+
source={{ uri: imageUrl, headers: getImageHeaders(imageUrl) }}
6162
className="w-full"
6263
style={{
6364
aspectRatio,

apps/mobile/src/modules/entry-list/templates/EntryNormalItem.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { setWebViewEntry } from "@/src/components/native/webview/EntryContentWeb
88
import { FeedIcon } from "@/src/components/ui/icon/feed-icon"
99
import { ItemPressable } from "@/src/components/ui/pressable/ItemPressable"
1010
import { gentleSpringPreset } from "@/src/constants/spring"
11+
import { getImageHeaders } from "@/src/lib/image"
1112
import { useEntry } from "@/src/store/entry/hooks"
1213
import { useFeed } from "@/src/store/feed/hooks"
1314

@@ -73,10 +74,15 @@ export function EntryNormalItem({ entryId }: { entryId: string }) {
7374
</View>
7475
{image && (
7576
<Image
76-
source={{ uri: image }}
77+
source={{
78+
uri: image,
79+
headers: getImageHeaders(image),
80+
}}
7781
placeholder={{ blurhash }}
7882
className="bg-system-fill ml-2 size-20 rounded-md"
7983
contentFit="cover"
84+
recyclingKey={image}
85+
transition={500}
8086
/>
8187
)}
8288
</ItemPressable>

apps/mobile/src/modules/entry-list/templates/EntrySocialItem.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { FeedIcon } from "@/src/components/ui/icon/feed-icon"
1313
import { ItemPressableStyle } from "@/src/components/ui/pressable/enum"
1414
import { ItemPressable } from "@/src/components/ui/pressable/ItemPressable"
1515
import { gentleSpringPreset } from "@/src/constants/spring"
16+
import { getImageHeaders } from "@/src/lib/image"
1617
import { quickLookImage } from "@/src/lib/native"
1718
import { useEntry } from "@/src/store/entry/hooks"
1819
import { useFeed } from "@/src/store/feed/hooks"
@@ -133,11 +134,12 @@ export function EntrySocialItem({ entryId }: { entryId: string }) {
133134
}}
134135
>
135136
<Image
136-
source={{ uri: image.url }}
137+
source={{ uri: image.url, headers: getImageHeaders(image.url) }}
137138
transition={500}
138139
placeholder={{ blurhash: image.blurhash }}
139140
className="bg-system-fill ml-2 size-20 rounded-md"
140141
contentFit="cover"
142+
recyclingKey={image.url}
141143
/>
142144
</Pressable>
143145
)

0 commit comments

Comments
 (0)