add config auth location
This commit is contained in:
parent
3ec67f9f47
commit
2b317f60c8
|
@ -10,6 +10,7 @@
|
||||||
max-height: 240px;
|
max-height: 240px;
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
white-space: pre-wrap;
|
white-space: pre-wrap;
|
||||||
|
min-width: 300px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -249,6 +249,30 @@ export function PluginPage() {
|
||||||
<option value="custom">{Locale.Plugin.Auth.Custom}</option>
|
<option value="custom">{Locale.Plugin.Auth.Custom}</option>
|
||||||
</select>
|
</select>
|
||||||
</ListItem>
|
</ListItem>
|
||||||
|
{["bearer", "basic", "custom"].includes(
|
||||||
|
editingPlugin.authType as string,
|
||||||
|
) && (
|
||||||
|
<ListItem title={Locale.Plugin.Auth.Location}>
|
||||||
|
<select
|
||||||
|
value={editingPlugin?.authLocation}
|
||||||
|
onChange={(e) => {
|
||||||
|
pluginStore.updatePlugin(editingPlugin.id, (plugin) => {
|
||||||
|
plugin.authLocation = e.target.value;
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<option value="header">
|
||||||
|
{Locale.Plugin.Auth.LocationHeader}
|
||||||
|
</option>
|
||||||
|
<option value="query">
|
||||||
|
{Locale.Plugin.Auth.LocationQuery}
|
||||||
|
</option>
|
||||||
|
<option value="body">
|
||||||
|
{Locale.Plugin.Auth.LocationBody}
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
</ListItem>
|
||||||
|
)}
|
||||||
{editingPlugin.authType == "custom" && (
|
{editingPlugin.authType == "custom" && (
|
||||||
<ListItem title={Locale.Plugin.Auth.CustomHeader}>
|
<ListItem title={Locale.Plugin.Auth.CustomHeader}>
|
||||||
<input
|
<input
|
||||||
|
|
|
@ -551,10 +551,14 @@ const cn = {
|
||||||
Basic: "Basic",
|
Basic: "Basic",
|
||||||
Bearer: "Bearer",
|
Bearer: "Bearer",
|
||||||
Custom: "自定义",
|
Custom: "自定义",
|
||||||
CustomHeader: "自定义头",
|
CustomHeader: "自定义参数名称",
|
||||||
Token: "Token",
|
Token: "Token",
|
||||||
Proxy: "使用代理",
|
Proxy: "使用代理",
|
||||||
ProxyDescription: "使用代理解决 CORS 错误",
|
ProxyDescription: "使用代理解决 CORS 错误",
|
||||||
|
Location: "位置",
|
||||||
|
LocationHeader: "Header",
|
||||||
|
LocationQuery: "Query",
|
||||||
|
LocationBody: "Body",
|
||||||
},
|
},
|
||||||
EditModal: {
|
EditModal: {
|
||||||
Title: (readonly: boolean) => `编辑插件 ${readonly ? "(只读)" : ""}`,
|
Title: (readonly: boolean) => `编辑插件 ${readonly ? "(只读)" : ""}`,
|
||||||
|
|
|
@ -559,10 +559,14 @@ const en: LocaleType = {
|
||||||
Basic: "Basic",
|
Basic: "Basic",
|
||||||
Bearer: "Bearer",
|
Bearer: "Bearer",
|
||||||
Custom: "Custom",
|
Custom: "Custom",
|
||||||
CustomHeader: "Custom Header",
|
CustomHeader: "Parameter Name",
|
||||||
Token: "Token",
|
Token: "Token",
|
||||||
Proxy: "Using Proxy",
|
Proxy: "Using Proxy",
|
||||||
ProxyDescription: "Using proxies to solve CORS error",
|
ProxyDescription: "Using proxies to solve CORS error",
|
||||||
|
Location: "Location",
|
||||||
|
LocationHeader: "Header",
|
||||||
|
LocationQuery: "Query",
|
||||||
|
LocationBody: "Body",
|
||||||
},
|
},
|
||||||
EditModal: {
|
EditModal: {
|
||||||
Title: (readonly: boolean) =>
|
Title: (readonly: boolean) =>
|
||||||
|
|
|
@ -13,6 +13,7 @@ export type Plugin = {
|
||||||
content: string;
|
content: string;
|
||||||
builtin: boolean;
|
builtin: boolean;
|
||||||
authType?: string;
|
authType?: string;
|
||||||
|
authLocation?: string;
|
||||||
authHeader?: string;
|
authHeader?: string;
|
||||||
authToken?: string;
|
authToken?: string;
|
||||||
usingProxy?: boolean;
|
usingProxy?: boolean;
|
||||||
|
@ -50,16 +51,17 @@ export const FunctionToolService = {
|
||||||
const definition = yaml.load(plugin.content) as any;
|
const definition = yaml.load(plugin.content) as any;
|
||||||
const serverURL = definition?.servers?.[0]?.url;
|
const serverURL = definition?.servers?.[0]?.url;
|
||||||
const baseURL = !!plugin?.usingProxy ? "/api/proxy" : serverURL;
|
const baseURL = !!plugin?.usingProxy ? "/api/proxy" : serverURL;
|
||||||
|
const headers: Record<string, string | undefined> = {
|
||||||
|
"X-Base-URL": !!plugin?.usingProxy ? serverURL : undefined,
|
||||||
|
};
|
||||||
|
if (plugin?.authLocation == "header") {
|
||||||
|
headers[headerName] = tokenValue;
|
||||||
|
}
|
||||||
const api = new OpenAPIClientAxios({
|
const api = new OpenAPIClientAxios({
|
||||||
definition: yaml.load(plugin.content) as any,
|
definition: yaml.load(plugin.content) as any,
|
||||||
axiosConfigDefaults: {
|
axiosConfigDefaults: {
|
||||||
baseURL,
|
baseURL,
|
||||||
headers: {
|
headers,
|
||||||
// 'Cache-Control': 'no-cache',
|
|
||||||
// 'Content-Type': 'application/json', // TODO
|
|
||||||
[headerName]: tokenValue,
|
|
||||||
"X-Base-URL": !!plugin?.usingProxy ? serverURL : undefined,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
|
@ -111,20 +113,26 @@ export const FunctionToolService = {
|
||||||
funcs: operations.reduce((s, o) => {
|
funcs: operations.reduce((s, o) => {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
s[o.operationId] = function (args) {
|
s[o.operationId] = function (args) {
|
||||||
const argument = [];
|
const parameters: Record<string, any> = {};
|
||||||
if (o.parameters instanceof Array) {
|
if (o.parameters instanceof Array) {
|
||||||
o.parameters.forEach((p) => {
|
o.parameters.forEach((p) => {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
argument.push(args[p?.name]);
|
parameters[p?.name] = args[p?.name];
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
delete args[p?.name];
|
delete args[p?.name];
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
argument.push(null);
|
|
||||||
}
|
}
|
||||||
argument.push(args);
|
if (plugin?.authLocation == "query") {
|
||||||
|
parameters[headerName] = tokenValue;
|
||||||
|
} else if (plugin?.authLocation == "body") {
|
||||||
|
args[headerName] = tokenValue;
|
||||||
|
}
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
return api.client[o.operationId].apply(null, argument);
|
return api.client[o.operationId](
|
||||||
|
parameters,
|
||||||
|
args,
|
||||||
|
api.axiosConfigDefaults,
|
||||||
|
);
|
||||||
};
|
};
|
||||||
return s;
|
return s;
|
||||||
}, {}),
|
}, {}),
|
||||||
|
|
Loading…
Reference in New Issue