From bd9fcb53a59b6ad4de0ebb83c0329f312d647b11 Mon Sep 17 00:00:00 2001 From: Elizabeth Hunt Date: Tue, 30 Apr 2024 09:38:48 -0700 Subject: run prettier and fix bug on safari --- src/lib/utils/retry.ts | 57 ++++++++++++++++++++++---------------------- src/lib/utils/setImageUrl.ts | 17 +++++++------ 2 files changed, 36 insertions(+), 38 deletions(-) (limited to 'src/lib/utils') diff --git a/src/lib/utils/retry.ts b/src/lib/utils/retry.ts index 34bc73b..ed78528 100644 --- a/src/lib/utils/retry.ts +++ b/src/lib/utils/retry.ts @@ -9,37 +9,36 @@ export const RETRY_JITTER_MAX = 3_000; const waitFor = (ms: number) => new Promise((res) => setTimeout(res, ms)); const exponentialStrategyWithJitter: RetryStrategyF = (retries: number) => - WAIT_MS * Math.pow(RETRY_EXPONENT, RETRY_EXPONENTIAL_FACTOR * retries) + - RETRY_JITTER_MAX * Math.random(); + WAIT_MS * Math.pow(RETRY_EXPONENT, RETRY_EXPONENTIAL_FACTOR * retries) + + RETRY_JITTER_MAX * Math.random(); export const continueRetryUntilValidation = async ( - promiseFn: () => Promise | T | Promise | void, - validationFn: (x: T) => Promise | boolean = (x: T) => - Promise.resolve(!!x), - maxRetries = MAX_DEFAULT_RETRY_AMOUNT, - waitTimeStrategy: RetryStrategyF = exponentialStrategyWithJitter, - retries = 0, - lastError: undefined | unknown = undefined + promiseFn: () => Promise | T | Promise | void, + validationFn: (x: T) => Promise | boolean = (x: T) => Promise.resolve(!!x), + maxRetries = MAX_DEFAULT_RETRY_AMOUNT, + waitTimeStrategy: RetryStrategyF = exponentialStrategyWithJitter, + retries = 0, + lastError: undefined | unknown = undefined ): Promise => { - if (retries >= maxRetries) { - if (lastError) throw lastError; - throw new Error("Exceeded maximum retry amount"); - } - try { - if (retries) await waitFor(waitTimeStrategy(retries)); + if (retries >= maxRetries) { + if (lastError) throw lastError; + throw new Error('Exceeded maximum retry amount'); + } + try { + if (retries) await waitFor(waitTimeStrategy(retries)); - const res = await promiseFn(); - if (res && (await validationFn(res))) return res; + const res = await promiseFn(); + if (res && (await validationFn(res))) return res; - throw new Error("Validation predicate unsuccessful"); - } catch (e: unknown) { - return continueRetryUntilValidation( - promiseFn, - validationFn, - maxRetries, - waitTimeStrategy, - retries + 1, - e - ); - } -}; \ No newline at end of file + throw new Error('Validation predicate unsuccessful'); + } catch (e: unknown) { + return continueRetryUntilValidation( + promiseFn, + validationFn, + maxRetries, + waitTimeStrategy, + retries + 1, + e + ); + } +}; diff --git a/src/lib/utils/setImageUrl.ts b/src/lib/utils/setImageUrl.ts index 15566a8..d2db853 100644 --- a/src/lib/utils/setImageUrl.ts +++ b/src/lib/utils/setImageUrl.ts @@ -1,12 +1,11 @@ import { supabase } from '../supabase'; export const setImageUrl = (imageSpec) => { - const { publicURL, error } = supabase - .storage - .from('mistymountains') - .getPublicUrl(imageSpec.image); - if (!error) { - return { ...imageSpec, image: publicURL }; - } - return imageSpec; -} + const { publicURL, error } = supabase.storage + .from('mistymountains') + .getPublicUrl(imageSpec.image); + if (!error) { + return { ...imageSpec, image: publicURL }; + } + return imageSpec; +}; -- cgit v1.2.3-70-g09d2