Skip to content

Commit 74312c6

Browse files
Merge pull request #4542 from tloncorp/lb/new-web-hosted-uploads
Web: Fix hosted uploads
2 parents 110bc8f + bd202cc commit 74312c6

File tree

5 files changed

+25
-3
lines changed

5 files changed

+25
-3
lines changed

packages/app/lib/envVars.native.ts

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const envVars = (Constants.expoConfig?.extra ?? {}) as Record<
66
string | undefined
77
>;
88

9+
export const DEV_SHIP_URL = '';
910
export const NOTIFY_PROVIDER = envVars.notifyProvider ?? 'rivfur-livmet';
1011
export const NOTIFY_SERVICE = envVars.notifyService ?? 'groups-native';
1112
export const POST_HOG_API_KEY = envVars.postHogApiKey ?? '';
@@ -46,6 +47,7 @@ export const INVITE_SERVICE_IS_DEV =
4647
envVars.inviteServiceIsDev === 'true' ? true : undefined;
4748

4849
export const ENV_VARS = {
50+
DEV_SHIP_URL,
4951
NOTIFY_PROVIDER,
5052
NOTIFY_SERVICE,
5153
POST_HOG_API_KEY,

packages/app/lib/envVars.ts

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// @ts-ignore – only valid on web
33
const env = import.meta.env;
44
const envVars = {
5+
devShipUrl: env.VITE_SHIP_URL,
56
notifyProvider: env.VITE_NOTIFY_PROVIDER,
67
notifyService: env.VITE_NOTIFY_SERVICE,
78
postHogApiKey: env.VITE_POST_HOG_API_KEY,
@@ -30,6 +31,7 @@ const envVars = {
3031
inviteServiceIsDev: env.VITE_INVITE_SERVICE_IS_DEV,
3132
} as Record<string, string | undefined>;
3233

34+
export const DEV_SHIP_URL = envVars.devShipUrl ?? '';
3335
export const NOTIFY_PROVIDER = envVars.notifyProvider ?? 'rivfur-livmet';
3436
export const NOTIFY_SERVICE = envVars.notifyService ?? 'groups-native';
3537
export const POST_HOG_API_KEY = envVars.postHogApiKey ?? '';
@@ -67,6 +69,7 @@ export const INVITE_SERVICE_IS_DEV =
6769
envVars.inviteServiceIsDev === 'true' ? true : undefined;
6870

6971
export const ENV_VARS = {
72+
DEV_SHIP_URL,
7073
NOTIFY_PROVIDER,
7174
NOTIFY_SERVICE,
7275
POST_HOG_API_KEY,

packages/shared/src/api/urbit.ts

+15-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import { Noun } from '@urbit/nockjs';
22
import _ from 'lodash';
33

44
import { createDevLogger, escapeLog, runIfDev } from '../debug';
5-
import { AnalyticsEvent } from '../domain';
5+
import { AnalyticsEvent, getConstants } from '../domain';
6+
import * as Hosting from '../domain/hosting';
67
import {
78
AuthError,
89
ChannelStatus,
@@ -106,7 +107,19 @@ export const getCurrentUserIsHosted = () => {
106107
throw new Error('Client not initialized');
107108
}
108109

109-
return client.url.endsWith('tlon.network');
110+
// prefer referencing client URL if available
111+
if (client.url) {
112+
return Hosting.nodeUrlIsHosted(client.url);
113+
}
114+
115+
/*
116+
On web, client URL is implicit based on location
117+
Note: during development, the true URL is supplied via the environment. Localhost is
118+
set up to redirect there
119+
*/
120+
const env = getConstants();
121+
const implicitUrl = __DEV__ ? env.DEV_SHIP_URL : window.location.hostname;
122+
return Hosting.nodeUrlIsHosted(implicitUrl);
110123
};
111124

112125
export function internalConfigureClient({
@@ -119,7 +132,6 @@ export function internalConfigureClient({
119132
onQuitOrReset,
120133
onChannelStatusChange,
121134
}: ClientParams) {
122-
logger.log('configuring client', shipName, shipUrl);
123135
config.client = config.client || new Urbit(shipUrl, '', '', fetchFn);
124136
config.client.verbose = verbose;
125137
config.client.nodeId = preSig(shipName);

packages/shared/src/domain/constants.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const TLON_NAMESPACE = 'tlonEnv';
22

33
interface Constants {
4+
DEV_SHIP_URL: string;
45
NOTIFY_PROVIDER: string;
56
NOTIFY_SERVICE: string;
67
POST_HOG_API_KEY: string;

packages/shared/src/domain/hosting.ts

+4
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,7 @@ export enum HostedNodeStatus {
5050
UnderMaintenance = 'UnderMaintenance',
5151
Unknown = 'Unknown',
5252
}
53+
54+
export function nodeUrlIsHosted(url: string) {
55+
return url.endsWith('tlon.network') || url.endsWith('.test.tlon.systems');
56+
}

0 commit comments

Comments
 (0)