New abstraction
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { isDevBuild } from "@/next/env";
|
||||
import { apiOrigin } from "@/next/origins";
|
||||
import { apiOrigin, apiURL } from "@/next/origins";
|
||||
import { clientPackageName } from "@/next/types/app";
|
||||
import { TwoFactorAuthorizationResponse } from "@/next/types/credentials";
|
||||
import { ensure } from "@/utils/ensure";
|
||||
@@ -58,7 +58,7 @@ const GetPasskeysResponse = z.object({
|
||||
* has no passkeys.
|
||||
*/
|
||||
export const getPasskeys = async (token: string) => {
|
||||
const url = `${apiOrigin()}/passkeys`;
|
||||
const url = await apiURL("passkeys");
|
||||
const res = await fetch(url, {
|
||||
headers: accountsAuthenticatedRequestHeaders(token),
|
||||
});
|
||||
|
||||
@@ -11,6 +11,19 @@ import { get, set } from "idb-keyval";
|
||||
export const apiOrigin = async () =>
|
||||
(await customAPIOrigin()) ?? "https://api.ente.io";
|
||||
|
||||
/**
|
||||
* A convenience function to construct an endpoint in a one-liner.
|
||||
*
|
||||
* This avoids us having to create a temporary variable or otherwise complicate
|
||||
* the call sites since async functions cannot be used inside template literals.
|
||||
*
|
||||
* @returns The equivalent of `${await apiOrigin()}/pathEtc`
|
||||
*/
|
||||
export const apiURL = async (pathEtc: string) => {
|
||||
const origin = await apiOrigin();
|
||||
return `${origin}/${pathEtc}`;
|
||||
};
|
||||
|
||||
/**
|
||||
* Return the overridden API origin, if one is defined by either (in priority
|
||||
* order):
|
||||
|
||||
Reference in New Issue
Block a user