Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/map/ElementDetailScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
useElementDetailQuery,
} from '../graphql/__generated__/types';
import type {RootStackParamList} from '../navigation/types';
import {photoImageSource} from '../photos/photoImageSource';
import type {Theme} from '../theme/colors';
import {useTheme} from '../theme/useTheme';

Expand Down Expand Up @@ -122,7 +123,7 @@ function ModalContents({
{element.photos.map(photo => (
<Image
key={photo.id}
source={{uri: photo.regular}}
source={photoImageSource(photo.regular)}
style={styles.photo}
/>
))}
Expand Down
3 changes: 2 additions & 1 deletion src/map/ElementEditScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
useUpdateElementMutation,
} from '../graphql/__generated__/types';
import type {RootStackParamList} from '../navigation/types';
import {photoImageSource} from '../photos/photoImageSource';
import {usePhotoUploader} from '../photos/photoUpload';
import type {Theme} from '../theme/colors';
import {useTheme} from '../theme/useTheme';
Expand Down Expand Up @@ -254,7 +255,7 @@ function EditForm({element, onDone}: {element: Element; onDone: () => void}) {
{photos.map(photo => (
<View key={photo.id} style={styles.photoThumbWrap}>
<Image
source={{uri: photo.thumbnail}}
source={photoImageSource(photo.thumbnail)}
style={styles.photoThumb}
/>
<Pressable
Expand Down
14 changes: 14 additions & 0 deletions src/photos/photoImageSource.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type {ImageURISource} from 'react-native';

// Wikimedia's User-Agent policy (https://meta.wikimedia.org/wiki/User-Agent_policy)
// rejects generic library User-Agents (e.g. the `okhttp/x.y` that React Native's
// native image loader sends on Android) with a 403, so `wikimedia`-type photos
// never render. Browsers send a full `Mozilla/...` UA, which is why the same
// photos load fine on web. Sending a descriptive UA satisfies the policy. It's
// harmless for our other photo hosts (S3/Cloudinary), so we apply it to all.
const USER_AGENT = 'Culpeos/0.0.1 (https://culpeos.com)';

// Builds an Image `source` for a photo URL with a User-Agent header attached.
export function photoImageSource(uri: string): ImageURISource {
return {uri, headers: {'User-Agent': USER_AGENT}};
}
Loading