feat(deploy): run shared toolkit socket
Lint and Build Checks / Lint, Test, and Build (push) Failing after 364h2m28s
Lint and Build Checks / Lint, Test, and Build (push) Failing after 364h2m28s
This commit is contained in:
@@ -13,6 +13,17 @@ type NodeProcess = {
|
||||
env?: Partial<Record<string, string>>;
|
||||
};
|
||||
|
||||
type BrowserLocation = {
|
||||
hostname: string;
|
||||
protocol: string;
|
||||
};
|
||||
|
||||
type BrowserGlobal = typeof globalThis & {
|
||||
location?: BrowserLocation;
|
||||
};
|
||||
|
||||
declare const __TOOLKIT_SOCKET_URL__: string | undefined;
|
||||
|
||||
export type ToolkitContentResource = EditableToolkitResource;
|
||||
export type ToolkitAssetKind = 'audio' | 'image';
|
||||
|
||||
@@ -79,9 +90,36 @@ function getMaybeProcess() {
|
||||
return typeof process === 'undefined' ? undefined : (process as NodeProcess);
|
||||
}
|
||||
|
||||
function getConfiguredToolkitSocketUrl() {
|
||||
if (
|
||||
typeof __TOOLKIT_SOCKET_URL__ === 'string' &&
|
||||
__TOOLKIT_SOCKET_URL__.length > 0
|
||||
) {
|
||||
return __TOOLKIT_SOCKET_URL__;
|
||||
}
|
||||
|
||||
return getMaybeProcess()?.env?.TOOLKIT_SOCKET_URL;
|
||||
}
|
||||
|
||||
function getBrowserToolkitSocketUrl() {
|
||||
const location = (globalThis as BrowserGlobal).location;
|
||||
|
||||
if (location == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (location.hostname === '127.0.0.1' || location.hostname === 'localhost') {
|
||||
return defaultToolkitSocketUrl;
|
||||
}
|
||||
|
||||
return `${location.protocol}//${location.hostname}:5174`;
|
||||
}
|
||||
|
||||
export function getToolkitSocketUrl() {
|
||||
return (
|
||||
getMaybeProcess()?.env?.TOOLKIT_SOCKET_URL ?? defaultToolkitSocketUrl
|
||||
getConfiguredToolkitSocketUrl() ??
|
||||
getBrowserToolkitSocketUrl() ??
|
||||
defaultToolkitSocketUrl
|
||||
);
|
||||
}
|
||||
|
||||
@@ -103,7 +141,9 @@ export function getToolkitSocket() {
|
||||
return toolkitSocket;
|
||||
}
|
||||
|
||||
function isToolkitContentPayload(value: unknown): value is ToolkitContentPayload {
|
||||
function isToolkitContentPayload(
|
||||
value: unknown,
|
||||
): value is ToolkitContentPayload {
|
||||
if (value == null || typeof value !== 'object') {
|
||||
return false;
|
||||
}
|
||||
@@ -117,9 +157,7 @@ function isToolkitContentPayload(value: unknown): value is ToolkitContentPayload
|
||||
);
|
||||
}
|
||||
|
||||
function parseToolkitContentResponse(
|
||||
response: unknown,
|
||||
): ToolkitContentPayload {
|
||||
function parseToolkitContentResponse(response: unknown): ToolkitContentPayload {
|
||||
if (response == null || typeof response !== 'object') {
|
||||
throw new Error('Toolkit content response was empty.');
|
||||
}
|
||||
@@ -172,7 +210,10 @@ function parseToolkitAssetUploadResponse(
|
||||
throw new Error(uploadResponse.error ?? 'Toolkit asset upload failed.');
|
||||
}
|
||||
|
||||
if (uploadResponse.ok === true && isToolkitAssetUploadPayload(uploadResponse)) {
|
||||
if (
|
||||
uploadResponse.ok === true &&
|
||||
isToolkitAssetUploadPayload(uploadResponse)
|
||||
) {
|
||||
return uploadResponse;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user