|
1 | | -import { Stability, StoreKey } from "@/app/constant"; |
2 | | -import { getHeaders } from "@/app/client/api"; |
| 1 | +import { |
| 2 | + Stability, |
| 3 | + StoreKey, |
| 4 | + ACCESS_CODE_PREFIX, |
| 5 | + ApiPath, |
| 6 | +} from "@/app/constant"; |
| 7 | +import { getBearerToken } from "@/app/client/api"; |
3 | 8 | import { createPersistStore } from "@/app/utils/store"; |
4 | 9 | import { nanoid } from "nanoid"; |
5 | 10 | import { uploadImage, base64Image2Blob } from "@/app/utils/chat"; |
6 | 11 | import { models, getModelParamBasicData } from "@/app/components/sd/sd-panel"; |
| 12 | +import { useAccessStore } from "./access"; |
7 | 13 |
|
8 | 14 | const defaultModel = { |
9 | 15 | name: models[0].name, |
@@ -57,18 +63,30 @@ export const useSdStore = createPersistStore< |
57 | 63 | okCall?.(); |
58 | 64 | }, |
59 | 65 | stabilityRequestCall(data: any) { |
| 66 | + const accessStore = useAccessStore.getState(); |
| 67 | + let prefix = ApiPath.Stability; |
| 68 | + let bearerToken = ""; |
| 69 | + if (accessStore.useCustomConfig) { |
| 70 | + prefix = accessStore.stabilityUrl || ApiPath.Stability; |
| 71 | + bearerToken = getBearerToken(accessStore.stabilityApiKey); |
| 72 | + } |
| 73 | + if (!bearerToken && accessStore.enabledAccessControl()) { |
| 74 | + bearerToken = getBearerToken( |
| 75 | + ACCESS_CODE_PREFIX + accessStore.accessCode, |
| 76 | + ); |
| 77 | + } |
| 78 | + const headers = { |
| 79 | + Accept: "application/json", |
| 80 | + Authorization: bearerToken, |
| 81 | + }; |
| 82 | + const path = `${prefix}/${Stability.GeneratePath}/${data.model}`; |
60 | 83 | const formData = new FormData(); |
61 | 84 | for (let paramsKey in data.params) { |
62 | 85 | formData.append(paramsKey, data.params[paramsKey]); |
63 | 86 | } |
64 | | - const headers = getHeaders(); |
65 | | - delete headers["Content-Type"]; |
66 | | - fetch(`/api/stability/${Stability.GeneratePath}/${data.model}`, { |
| 87 | + fetch(path, { |
67 | 88 | method: "POST", |
68 | | - headers: { |
69 | | - ...headers, |
70 | | - Accept: "application/json", |
71 | | - }, |
| 89 | + headers, |
72 | 90 | body: formData, |
73 | 91 | }) |
74 | 92 | .then((response) => response.json()) |
|
0 commit comments