From e28d104dd8e205a472db2ea9809b67ef6a006447 Mon Sep 17 00:00:00 2001 From: Hunter Miller Date: Mon, 23 Oct 2023 14:47:08 -0500 Subject: [PATCH] storage: hardcode url to mimic groups --- ui/src/env.d.ts | 4 +++- ui/src/logic/utils.ts | 15 ++++++++++++++- ui/src/state/storage/reducer.ts | 7 +++++-- ui/src/state/storage/storage.ts | 24 +++++++++++++++++++++++- 4 files changed, 45 insertions(+), 5 deletions(-) diff --git a/ui/src/env.d.ts b/ui/src/env.d.ts index 2fda24a0..891d7b10 100644 --- a/ui/src/env.d.ts +++ b/ui/src/env.d.ts @@ -1,6 +1,8 @@ -interface ImportMetaEnv extends Readonly> { +interface ImportMetaEnv + extends Readonly> { readonly VITE_LAST_WIPE: string; readonly VITE_STORAGE_VERSION: string; + readonly VITE_SHIP_URL: string; } interface ImportMeta { diff --git a/ui/src/logic/utils.ts b/ui/src/logic/utils.ts index 59f0ec9d..459eeee4 100644 --- a/ui/src/logic/utils.ts +++ b/ui/src/logic/utils.ts @@ -15,8 +15,21 @@ import { useCallback, useState } from 'react'; export const useMockData = import.meta.env.MODE === 'mock'; +export const isStagingHosted = + import.meta.env.DEV && + (import.meta.env.VITE_SHIP_URL.endsWith('.test.tlon.systems') || + window.location.hostname.endsWith('.test.tlon.systems')); export const isHosted = - import.meta.env.DEV || window.location.hostname.endsWith('.tlon.network'); + isStagingHosted || + (import.meta.env.DEV && + (import.meta.env.VITE_SHIP_URL.endsWith('.tlon.network') || + window.location.hostname.endsWith('.tlon.network'))); + +export const hostingUploadURL = isStagingHosted + ? 'https://memex.test.tlon.systems' + : isHosted + ? 'https://memex.tlon.network' + : ''; export async function fakeRequest(data: T, time = 300): Promise { return new Promise((resolve) => { diff --git a/ui/src/state/storage/reducer.ts b/ui/src/state/storage/reducer.ts index 472bfd2c..6620199a 100644 --- a/ui/src/state/storage/reducer.ts +++ b/ui/src/state/storage/reducer.ts @@ -3,6 +3,7 @@ import { StorageUpdate } from '@/gear'; import _ from 'lodash'; import { BaseStorageState } from '@/gear'; import { BaseState } from '../base'; +import { hostingUploadURL } from '@/logic/utils'; export type StorageState = BaseStorageState & BaseState; @@ -27,8 +28,10 @@ const configuration = ( buckets: new Set(data.buckets), currentBucket: data.currentBucket, region: data.region, - presignedUrl: data.presignedUrl, - service: data.service, + // if landscape is not up to date we need to default these so the + // client init logic still works + presignedUrl: data.presignedUrl || hostingUploadURL, + service: data.service || 'credentials', }; } return state; diff --git a/ui/src/state/storage/storage.ts b/ui/src/state/storage/storage.ts index 61cb2ff2..c1721df6 100644 --- a/ui/src/state/storage/storage.ts +++ b/ui/src/state/storage/storage.ts @@ -8,6 +8,7 @@ import { reduceStateN, BaseState, } from '../base'; +import { hostingUploadURL, isHosted } from '@/logic/utils'; enableMapSet(); @@ -44,9 +45,30 @@ export const useStorage = createState( } numLoads += 1; if (numLoads === 2) { - set({ loaded: true }); + const { + s3: { credentials, configuration }, + } = get(); + + if (!credentials?.endpoint && isHosted) { + set({ + loaded: true, + s3: { + credentials, + configuration: { + ...configuration, + presignedUrl: + configuration.presignedUrl || hostingUploadURL, + service: 'presigned-url', + }, + }, + }); + } else { + set({ loaded: true }); + } } } ), ] ); + +window.useStorage = useStorage;