feat: add file storage settings and uploads
This commit is contained in:
+130
-1
@@ -5,6 +5,10 @@ import type {
|
||||
CatalogProvider,
|
||||
CatalogProviderUpsertRequest,
|
||||
CreatedGatewayApiKey,
|
||||
FileStorageChannel,
|
||||
FileStorageSettings,
|
||||
FileStorageSettingsUpdateRequest,
|
||||
FileStorageChannelUpsertRequest,
|
||||
GatewayAccessRuleBatchRequest,
|
||||
GatewayAccessRule,
|
||||
GatewayAccessRuleUpsertRequest,
|
||||
@@ -601,10 +605,17 @@ export async function createImageGenerationTask(
|
||||
model: string;
|
||||
prompt: string;
|
||||
aspect_ratio?: string;
|
||||
content?: Array<Record<string, unknown>>;
|
||||
count?: number;
|
||||
height?: number;
|
||||
image?: string | string[];
|
||||
image_url?: string | string[];
|
||||
image_urls?: string[];
|
||||
images?: string[];
|
||||
n?: number;
|
||||
quality?: string;
|
||||
referenceImage?: string | string[];
|
||||
reference_image?: string | string[];
|
||||
resolution?: string;
|
||||
runMode?: string;
|
||||
simulation?: boolean;
|
||||
@@ -622,7 +633,26 @@ export async function createImageGenerationTask(
|
||||
|
||||
export async function createImageEditTask(
|
||||
token: string,
|
||||
input: { model: string; prompt: string; image?: string; mask?: string; runMode?: string; simulation?: boolean },
|
||||
input: {
|
||||
model: string;
|
||||
prompt: string;
|
||||
aspect_ratio?: string;
|
||||
content?: Array<Record<string, unknown>>;
|
||||
count?: number;
|
||||
height?: number;
|
||||
image?: string | string[];
|
||||
image_url?: string | string[];
|
||||
image_urls?: string[];
|
||||
images?: string[];
|
||||
mask?: string;
|
||||
n?: number;
|
||||
quality?: string;
|
||||
resolution?: string;
|
||||
runMode?: string;
|
||||
simulation?: boolean;
|
||||
size?: string;
|
||||
width?: number;
|
||||
},
|
||||
): Promise<{ task: GatewayTask; next: Record<string, string> }> {
|
||||
return request<{ task: GatewayTask; next: Record<string, string> }>('/api/v1/images/edits', {
|
||||
body: input,
|
||||
@@ -636,6 +666,9 @@ export async function createVideoGenerationTask(
|
||||
token: string,
|
||||
input: {
|
||||
audio?: boolean;
|
||||
audioUrl?: string | string[];
|
||||
audio_url?: string | string[];
|
||||
content?: Array<Record<string, unknown>>;
|
||||
model: string;
|
||||
prompt: string;
|
||||
aspect_ratio?: string;
|
||||
@@ -643,12 +676,24 @@ export async function createVideoGenerationTask(
|
||||
duration?: number;
|
||||
duration_seconds?: number;
|
||||
height?: number;
|
||||
image?: string | string[];
|
||||
imageUrl?: string | string[];
|
||||
image_url?: string | string[];
|
||||
imageUrls?: string[];
|
||||
image_urls?: string[];
|
||||
n?: number;
|
||||
output_audio?: boolean;
|
||||
referenceAudio?: string | string[];
|
||||
referenceVideo?: string | string[];
|
||||
reference_audio?: string | string[];
|
||||
reference_image?: string | string[];
|
||||
reference_video?: string | string[];
|
||||
resolution?: string;
|
||||
runMode?: string;
|
||||
simulation?: boolean;
|
||||
size?: string;
|
||||
videoUrl?: string | string[];
|
||||
video_url?: string | string[];
|
||||
width?: number;
|
||||
},
|
||||
): Promise<{ task: GatewayTask; next: Record<string, string> }> {
|
||||
@@ -660,6 +705,41 @@ export async function createVideoGenerationTask(
|
||||
});
|
||||
}
|
||||
|
||||
export interface GatewayFileUploadResponse extends Record<string, unknown> {
|
||||
fileUrl?: string;
|
||||
file_url?: string;
|
||||
url?: string;
|
||||
}
|
||||
|
||||
export async function uploadFileToStorage(
|
||||
token: string,
|
||||
file: File,
|
||||
source = 'ai-gateway-playground',
|
||||
): Promise<GatewayFileUploadResponse> {
|
||||
const form = new FormData();
|
||||
form.append('file', file);
|
||||
form.append('source', source);
|
||||
|
||||
const response = await fetch(`${API_BASE}/v1/files/upload`, {
|
||||
body: form,
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
method: 'POST',
|
||||
});
|
||||
const body = await response.text();
|
||||
if (!response.ok) {
|
||||
throw new GatewayApiError(parseErrorDetails(body, response.status, `Request failed: ${response.status}`));
|
||||
}
|
||||
if (!body) return {};
|
||||
try {
|
||||
const parsed = JSON.parse(body) as unknown;
|
||||
return recordFromUnknown(parsed) ? (parsed as GatewayFileUploadResponse) : {};
|
||||
} catch {
|
||||
return { url: body };
|
||||
}
|
||||
}
|
||||
|
||||
export async function estimatePricing(
|
||||
token: string,
|
||||
input: Record<string, unknown>,
|
||||
@@ -758,6 +838,55 @@ export async function getNetworkProxyConfig(token: string): Promise<GatewayNetwo
|
||||
return request<GatewayNetworkProxyConfig>('/api/admin/config/network-proxy', { token });
|
||||
}
|
||||
|
||||
export async function listFileStorageChannels(token: string): Promise<ListResponse<FileStorageChannel>> {
|
||||
return request<ListResponse<FileStorageChannel>>('/api/admin/system/file-storage/channels', { token });
|
||||
}
|
||||
|
||||
export async function getFileStorageSettings(token: string): Promise<FileStorageSettings> {
|
||||
return request<FileStorageSettings>('/api/admin/system/file-storage/settings', { token });
|
||||
}
|
||||
|
||||
export async function updateFileStorageSettings(
|
||||
token: string,
|
||||
input: FileStorageSettingsUpdateRequest,
|
||||
): Promise<FileStorageSettings> {
|
||||
return request<FileStorageSettings>('/api/admin/system/file-storage/settings', {
|
||||
body: input,
|
||||
method: 'PATCH',
|
||||
token,
|
||||
});
|
||||
}
|
||||
|
||||
export async function createFileStorageChannel(
|
||||
token: string,
|
||||
input: FileStorageChannelUpsertRequest,
|
||||
): Promise<FileStorageChannel> {
|
||||
return request<FileStorageChannel>('/api/admin/system/file-storage/channels', {
|
||||
body: input,
|
||||
method: 'POST',
|
||||
token,
|
||||
});
|
||||
}
|
||||
|
||||
export async function updateFileStorageChannel(
|
||||
token: string,
|
||||
channelId: string,
|
||||
input: FileStorageChannelUpsertRequest,
|
||||
): Promise<FileStorageChannel> {
|
||||
return request<FileStorageChannel>(`/api/admin/system/file-storage/channels/${channelId}`, {
|
||||
body: input,
|
||||
method: 'PATCH',
|
||||
token,
|
||||
});
|
||||
}
|
||||
|
||||
export async function deleteFileStorageChannel(token: string, channelId: string): Promise<void> {
|
||||
await request<void>(`/api/admin/system/file-storage/channels/${channelId}`, {
|
||||
method: 'DELETE',
|
||||
token,
|
||||
});
|
||||
}
|
||||
|
||||
async function request<T>(
|
||||
path: string,
|
||||
options: { token?: string; auth?: boolean; method?: string; body?: unknown; headers?: Record<string, string> } = {},
|
||||
|
||||
Reference in New Issue
Block a user