Skip to content

Commit a617c73

Browse files
committed
🐛 (expo): Use OPDS URLs without any trimming
1 parent ece5ec2 commit a617c73

File tree

4 files changed

+27
-11
lines changed

4 files changed

+27
-11
lines changed

apps/expo/components/opds/OPDSAuthDialog.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ import { opdsURL } from '@stump/sdk/controllers'
66
import { isAxiosError } from 'axios'
77
import { useCallback, useEffect, useRef, useState } from 'react'
88
import { Controller, useForm, useFormState } from 'react-hook-form'
9-
import { Image, View } from 'react-native'
9+
import { View } from 'react-native'
1010
import { useSafeAreaInsets } from 'react-native-safe-area-context'
11+
import TurboImage from 'react-native-turbo-image'
1112
import urlJoin from 'url-join'
1213
import { z } from 'zod'
1314

@@ -154,7 +155,7 @@ export default function OPDSAuthDialog({ isOpen, authDoc, onClose }: OPDSAuthDia
154155
<View className="flex-1 items-start gap-4 p-6">
155156
{logoURL && (
156157
<View className="w-full items-center justify-center">
157-
<Image
158+
<TurboImage
158159
className="self-center"
159160
source={{ uri: logoURL }}
160161
style={{ width: 100, height: 100 }}

packages/sdk/src/api.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,24 @@ export class Api {
9595
const instance = axios.create({
9696
baseURL: this.serviceURL,
9797
withCredentials: this.configuration.authMethod === 'session',
98+
// Note: Keeping this here for posterity. I went down a DEEP rabbit hole on this one.
99+
// If you read through https://github.com/ajslater/codex/issues/524 basically Stump
100+
// was stripping trailing slashes from OPDS urls which caused issues with Codex, it would
101+
// redirect to a url and axios wasn't preserving the Authorization header on the redirect for iOS.
102+
// It _does_ on Android, though. From what I can tell about how axios works in the context of iOS in
103+
// a react-native app, it uses native networking (i.e., CFNetwork/NSURLSession) which doesn't seem to
104+
// adhere to _this_ beforeRedirect config. From what I understand, I'd need to hook into maybe
105+
// https://developer.apple.com/documentation/foundation/urlsessiontaskdelegate/urlsession(_:task:willperformhttpredirection:newrequest:completionhandler:)
106+
// which would mean a native module to handle it. That is a pretty sizable effort so for now I am just
107+
// going to accept it as a limitation for iOS. A little unfortunate, but as long as there aren't servers
108+
// which put feeds behind layers of redirects it should be fine.
109+
// beforeRedirect: (config) => {
110+
// config.headers = config.headers.concat(this.getHeaders())
111+
// if (this._basicAuth) {
112+
// config.auth = this._basicAuth
113+
// }
114+
// return config
115+
// },
98116
})
99117

100118
instance.interceptors.request.use(async (config) => {

packages/sdk/src/controllers/opds-api.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ export class OPDSV2API extends APIBase {
6666
async feed(url: string, params?: OPDSPageQuery): Promise<OPDSFeed> {
6767
const absoluteUrl = resolveUrl(url, this.api.rootURL)
6868
const resolvedURL = urlWithParams(
69-
`${absoluteUrl.endsWith('/') ? absoluteUrl.slice(0, -1) : absoluteUrl}`,
69+
// See https://github.com/ajslater/codex/issues/524 for commented out line
70+
// `${absoluteUrl.endsWith('/') ? absoluteUrl.slice(0, -1) : absoluteUrl}`,
71+
absoluteUrl,
7072
toUrlParams(params),
7173
)
7274
const { data } = await this.axios.get<OPDSFeed>(resolvedURL, {

packages/sdk/src/utils/url.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,9 @@ export const formatApiURL = (url: string, version: ApiVersion) => {
2828
export const formatOPDSURL = (url: string) => {
2929
let correctedUrl = url
3030

31-
// Remove trailing slash
32-
if (correctedUrl.endsWith('/')) {
33-
correctedUrl = correctedUrl.slice(0, -1)
34-
}
35-
36-
// if (correctedUrl.endsWith('/api')) {
37-
// correctedUrl = correctedUrl.slice(0, -4)
38-
// }
31+
// We don't remove trailing slash for OPDS urls since we don't have
32+
// the knowledge of if they are needed like we do for internal API urls
33+
// See https://github.com/ajslater/codex/issues/524
3934

4035
// Remove all double slashes AFTER the initial http://, https://, etc
4136
correctedUrl = correctedUrl.replace(/([^:]\/)\/+/g, '$1')

0 commit comments

Comments
 (0)