Skip to content

Commit 277a2d9

Browse files
committed
重构设置内容
1 parent e411c68 commit 277a2d9

16 files changed

Lines changed: 152 additions & 298 deletions

app/pages/BibiGpt.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
} from "@ant-design/pro-components";
1313
import React, { useState } from "react";
1414
import { BibiGPTAPI } from "@/app/client/BibiGPT";
15-
import { api2Provider, useAppConfig } from "@/app/store";
15+
import { useAppConfig } from "@/app/store";
1616
import { RenderSubmitter } from "@/app/render";
1717

1818
const BibiGptOpenForm = (props: {
@@ -96,7 +96,7 @@ const BibiGptOpenForm = (props: {
9696

9797
const BibiGptPage = () => {
9898
const appConfig = useAppConfig();
99-
const bibiGptAPI = new BibiGPTAPI(appConfig.getFirstApiKey(api2Provider.BibiGPT));
99+
const bibiGptAPI = new BibiGPTAPI(appConfig.getApiKey());
100100
const [bibiGptOpenForm] = ProForm.useForm();
101101
const [bibiGptChatForm] = ProForm.useForm();
102102
const [bibiGptSubtitleForm] = ProForm.useForm();

app/pages/ChatCompletions.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ import { jsonMapValidationRule, jsonSchemaValidationRule, safeJsonParse } from "
1919
import { ChatCompletionAPI, ChatCompletionRequest } from "@/app/client/chatCompletions";
2020
import { PictureOutlined } from "@ant-design/icons";
2121
import { renderCode, renderRequestTimeDuration, RenderSubmitter } from "@/app/render";
22-
import { api2Provider, useAppConfig } from "@/app/store";
22+
import { useAppConfig } from "@/app/store";
2323

2424
const Upload2B64 = lazy(() => import("@/app/components/Upload2B64"));
2525

2626
// TODO: https://platform.openai.com/playground
2727
export function ChatCompletionsPage() {
2828
const appConfig = useAppConfig();
29-
const chatCompletionApi = new ChatCompletionAPI(appConfig.getFirstApiKey(api2Provider.Chat));
29+
const chatCompletionApi = new ChatCompletionAPI(appConfig.getApiKey());
3030

3131
const [chatCompletionsForm] = ProForm.useForm();
3232
const [submitting, setSubmitting] = useState<boolean>(false);

app/pages/Dalle.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { api2Provider, useAppConfig } from "@/app/store";
1+
import { useAppConfig } from "@/app/store";
22
import {
33
AvailableDalleModels,
44
DallEAPI,
@@ -465,7 +465,7 @@ const renderPicture = (data: DallEResponse) => {
465465

466466
const DallePage = () => {
467467
const appConfig = useAppConfig();
468-
const dallEApi = new DallEAPI(appConfig.getFirstApiKey(api2Provider.DallE));
468+
const dallEApi = new DallEAPI(appConfig.getApiKey());
469469
const [createForm] = ProForm.useForm();
470470
const [editForm] = ProForm.useForm();
471471
const [variationForm] = ProForm.useForm();

app/pages/Embeddings.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import React, { useState } from "react";
1414
import { COL_SCROLL_STYLE, PRO_FORM_PROPS } from "@/constant";
1515
import { arrayValidationRule, handelResponseError, safeJsonStringify } from "@/app/utils";
1616
import { renderCode, RenderSubmitter } from "@/app/render";
17-
import { api2Provider, useAppConfig } from "@/app/store";
17+
import { useAppConfig } from "@/app/store";
1818
import { Col, Divider } from "antd";
1919

2020
const EmbeddingsForm = (props: {
@@ -155,7 +155,7 @@ const EmbeddingsForm = (props: {
155155

156156
const EmbeddingsPage = () => {
157157
const appConfig = useAppConfig();
158-
const embeddingsApi = new EmbeddingsAPI(appConfig.getFirstApiKey(api2Provider.Embeddings));
158+
const embeddingsApi = new EmbeddingsAPI(appConfig.getApiKey());
159159
const [embeddingsForm] = ProForm.useForm();
160160

161161
const [data, setData] = useState<any>();

app/pages/Flux.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// /app/pages/Flux.tsx
22

3-
import { api2Provider, useAppConfig } from "@/app/store";
3+
import { useAppConfig } from "@/app/store";
44
import { FluxAPI, FluxGetRequest, FluxGetResponse, FluxImageRequest, FluxImageResponse } from "@/app/client/FluxProxy";
55
import {
66
ProDescriptions,
@@ -301,7 +301,7 @@ const FluxTaskRender = (props: {
301301

302302
export function FluxPage() {
303303
const appConfig = useAppConfig();
304-
const fluxApi = new FluxAPI(appConfig.getFirstApiKey(api2Provider.Flux));
304+
const fluxApi = new FluxAPI(appConfig.getApiKey());
305305
const [generationForm] = ProForm.useForm();
306306
const [queryForm] = ProForm.useForm();
307307

app/pages/GPTs.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { renderCode, RenderSubmitter } from "@/app/render";
66
import { handelResponseError, safeJsonStringify } from "@/app/utils";
77
import React, { useState } from "react";
88
import { FileSearchOutlined } from "@ant-design/icons";
9-
import { api2Provider, useAppConfig } from "@/app/store";
9+
import { useAppConfig } from "@/app/store";
1010
import { ProForm, ProFormInstance, ProFormText } from "@ant-design/pro-components";
1111
import { GPTsAPI, GptsSearchRequest, GptsSearchResponse } from "@/app/client/Gpts";
1212

@@ -63,7 +63,7 @@ const GPTsSearchForm = (props: {
6363

6464
const GPTsPage = () => {
6565
const appConfig = useAppConfig();
66-
const gptsApi = new GPTsAPI(appConfig.getFirstApiKey(api2Provider.GPTs));
66+
const gptsApi = new GPTsAPI(appConfig.getApiKey());
6767
const [searchForm] = ProForm.useForm();
6868

6969
const type_options = [{ label: "Search", value: "search", icon: <FileSearchOutlined /> }];

app/pages/Luma.tsx

Lines changed: 6 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
import { COL_SCROLL_STYLE, PRO_FORM_PROPS } from "@/constant";
1515
import { handelResponseError, safeJsonStringify } from "@/app/utils";
1616
import { CodeModal, renderCode, RenderSubmitter } from "@/app/render";
17-
import { api2Provider, useAppConfig } from "@/app/store";
17+
import { useAppConfig } from "@/app/store";
1818
import { Col, Divider, Empty, Image, Segmented, Spin } from "antd";
1919
import { AccountType, LumaApi, LumaExtendTaskRequest, LumaGenerationTaskRequest } from "@/app/client/Luma";
2020
import { ExpandAltOutlined, FileTextOutlined, UnorderedListOutlined } from "@ant-design/icons";
@@ -155,61 +155,15 @@ const LumaGenerateForm = (props: {
155155
label={"Image URL"}
156156
tooltip={"Start frame picture"}
157157
accept={"image/*"}
158-
max={1}
159-
action={appConfig.getUploadConfig().action}
160-
fieldProps={{
161-
listType: "picture-card",
162-
headers: {
163-
Authorization: appConfig.getUploadConfig().auth,
164-
},
165-
onChange: (info) => {
166-
const getValueByPosition = (obj: any, position: readonly any[]) => {
167-
return position.reduce((acc, key) => acc && acc[key], obj);
168-
};
169-
170-
if (info.file.status === "done") {
171-
try {
172-
const response = info.file.response;
173-
if (response) {
174-
info.file.url = getValueByPosition(response, appConfig.getUploadConfig().position);
175-
}
176-
} catch (e) {
177-
console.error(e);
178-
}
179-
}
180-
},
181-
}}
158+
{...appConfig.getProFormUploadConfig("url", 1, "picture-card")}
182159
/>
183160

184161
<ProFormUploadButton
185162
name={"image_end_url"}
186163
label={"Image End URL"}
187164
tooltip={"End frame image, key frame"}
188165
accept={"image/*"}
189-
max={1}
190-
action={appConfig.getUploadConfig().action}
191-
fieldProps={{
192-
listType: "picture-card",
193-
headers: {
194-
Authorization: appConfig.getUploadConfig().auth,
195-
},
196-
onChange: (info) => {
197-
const getValueByPosition = (obj: any, position: readonly any[]) => {
198-
return position.reduce((acc, key) => acc && acc[key], obj);
199-
};
200-
201-
if (info.file.status === "done") {
202-
try {
203-
const response = info.file.response;
204-
if (response) {
205-
info.file.url = getValueByPosition(response, appConfig.getUploadConfig().position);
206-
}
207-
} catch (e) {
208-
console.error(e);
209-
}
210-
}
211-
},
212-
}}
166+
{...appConfig.getProFormUploadConfig("url", 1, "picture-card")}
213167
/>
214168
</ProForm>
215169
);
@@ -284,60 +238,14 @@ const LumaExtendForm = (props: {
284238
<ProFormUploadButton
285239
name={"image_end_url"}
286240
label={"Image End URL"}
287-
max={1}
288-
action={appConfig.getUploadConfig().action}
289241
accept={"image/*"}
290-
fieldProps={{
291-
listType: "picture-card",
292-
headers: {
293-
Authorization: appConfig.getUploadConfig().auth,
294-
},
295-
onChange: (info) => {
296-
const getValueByPosition = (obj: any, position: readonly any[]) => {
297-
return position.reduce((acc, key) => acc && acc[key], obj);
298-
};
299-
300-
if (info.file.status === "done") {
301-
try {
302-
const response = info.file.response;
303-
if (response) {
304-
info.file.url = getValueByPosition(response, appConfig.getUploadConfig().position);
305-
}
306-
} catch (e) {
307-
console.error(e);
308-
}
309-
}
310-
},
311-
}}
242+
{...appConfig.getProFormUploadConfig("url", 1, "picture-card")}
312243
/>
313244
<ProFormUploadButton
314245
name={"video_url"}
315246
label={"Video URL"}
316247
accept={"video/*"}
317-
max={1}
318-
action={appConfig.getUploadConfig().action}
319-
fieldProps={{
320-
listType: "picture-card",
321-
headers: {
322-
Authorization: appConfig.getUploadConfig().auth,
323-
},
324-
onChange: (info) => {
325-
const getValueByPosition = (obj: any, position: readonly any[]) => {
326-
return position.reduce((acc, key) => acc && acc[key], obj);
327-
};
328-
329-
if (info.file.status === "done") {
330-
try {
331-
const response = info.file.response;
332-
if (response) {
333-
info.file.url = getValueByPosition(response, appConfig.getUploadConfig().position);
334-
}
335-
} catch (e) {
336-
console.error(e);
337-
}
338-
}
339-
},
340-
}}
248+
{...appConfig.getProFormUploadConfig("url", 1, "picture-card")}
341249
rules={[{ required: true }]}
342250
/>
343251
</ProForm>
@@ -540,7 +448,7 @@ const LumaTaskRenderer = (props: {
540448

541449
const LumaPage = () => {
542450
const appConfig = useAppConfig();
543-
const lumaApi = new LumaApi(appConfig.getFirstApiKey(api2Provider.Luma));
451+
const lumaApi = new LumaApi(appConfig.getApiKey());
544452
const [accountType, setAccountType] = useState<AccountType>("relax");
545453

546454
const operate_type_options = [

app/pages/Midjourney.tsx

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ import {
5252
} from "@/app/client/midjourneyProxy";
5353
import { CodeModal, renderCode, RenderSubmitter } from "@/app/render";
5454
import { handelResponseError, safeJsonStringify } from "@/app/utils";
55-
import { api2Provider, useAppConfig } from "@/app/store";
55+
import { useAppConfig } from "@/app/store";
5656
import ImageMaskModal from "@/app/components/ImageMask";
5757
import { ProFormItem } from "@ant-design/pro-form";
5858

@@ -531,31 +531,31 @@ const ImagineForm = (props: {
531531
tooltip={
532532
"You can use images as character references in your prompt to generate images of the same character in different situations."
533533
}
534-
max={2}
535-
action={appConfig.getUploadConfig().action}
536534
accept={"image/*"}
537-
fieldProps={{
538-
listType: "picture-card",
539-
headers: {
540-
Authorization: appConfig.getUploadConfig().auth,
541-
},
542-
onChange: (info) => {
543-
const getValueByPosition = (obj: any, position: readonly any[]) => {
544-
return position.reduce((acc, key) => acc && acc[key], obj);
545-
};
546-
547-
if (info.file.status === "done") {
548-
try {
549-
const response = info.file.response;
550-
if (response) {
551-
info.file.url = getValueByPosition(response, appConfig.getUploadConfig().position);
552-
}
553-
} catch (e) {
554-
console.error(e);
555-
}
556-
}
557-
},
558-
}}
535+
{...appConfig.getProFormUploadConfig("url", 2, "picture-card")}
536+
// action={appConfig.getUploadConfig().action}
537+
// fieldProps={{
538+
// listType: "picture-card",
539+
// headers: {
540+
// Authorization: appConfig.getUploadConfig().auth,
541+
// },
542+
// onChange: (info) => {
543+
// const getValueByPosition = (obj: any, position: readonly any[]) => {
544+
// return position.reduce((acc, key) => acc && acc[key], obj);
545+
// };
546+
//
547+
// if (info.file.status === "done") {
548+
// try {
549+
// const response = info.file.response;
550+
// if (response) {
551+
// info.file.url = getValueByPosition(response, appConfig.getUploadConfig().position);
552+
// }
553+
// } catch (e) {
554+
// console.error(e);
555+
// }
556+
// }
557+
// },
558+
// }}
559559
width="sm"
560560
/>
561561

@@ -1263,7 +1263,7 @@ const MidjourneyTasksRenderer = (props: {
12631263

12641264
export function MidjourneyPage() {
12651265
const appConfig = useAppConfig();
1266-
const drawApi = new DrawAPI(appConfig.getFirstApiKey(api2Provider.Midjourney));
1266+
const drawApi = new DrawAPI(appConfig.getApiKey());
12671267
const [mjImagineTaskForm] = ProForm.useForm();
12681268
const [mjBlendTaskForm] = ProForm.useForm();
12691269
const [mjDescribeTaskForm] = ProForm.useForm();

app/pages/Pika.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { COL_SCROLL_STYLE, PRO_FORM_PROPS } from "@/constant";
44
import { Col, Divider, Empty, Image, Segmented, Spin } from "antd";
55
import React, { useState } from "react";
66
import { ProDescriptions, ProForm, ProFormSelect, ProFormTextArea } from "@ant-design/pro-components";
7-
import { api2Provider, useAppConfig } from "@/app/store";
7+
import { useAppConfig } from "@/app/store";
88
import {
99
CreatePikaTaskRequest,
1010
CreatePikaTaskResponse,
@@ -353,7 +353,7 @@ const PikaTaskRenderer = (props: {
353353

354354
const PikaPage = () => {
355355
const appConfig = useAppConfig();
356-
const pikaApi = new PikaAPI(appConfig.getFirstApiKey(api2Provider.Pika));
356+
const pikaApi = new PikaAPI(appConfig.getApiKey());
357357
const [pikaCreateForm] = ProForm.useForm();
358358
const [pikaQueryForm] = ProForm.useForm();
359359

0 commit comments

Comments
 (0)