新增get转发接口
新增Laitool 设置中的绘图设置
This commit is contained in:
@@ -158,7 +158,7 @@ public class ForwardWordService(ApplicationDbContext context)
|
||||
|
||||
#endregion
|
||||
|
||||
#region 简单的AI转发,OpenAI格式
|
||||
#region Post 转发接口
|
||||
/// <summary>
|
||||
/// 简单的转发接口
|
||||
/// </summary>
|
||||
@@ -171,20 +171,88 @@ public class ForwardWordService(ApplicationDbContext context)
|
||||
{
|
||||
// 开始拼接请求体
|
||||
using HttpClient client = new();
|
||||
client.DefaultRequestHeaders.Add("Authorization", "Bearer " + request.APIKey);
|
||||
if (request.url.StartsWith("https://api.laitool.net"))
|
||||
{
|
||||
//client.DefaultRequestHeaders.Add("Authorization", "Bearer " + request.APIKey);
|
||||
client.DefaultRequestHeaders.Add("mj-api-secret", request.APIKey);
|
||||
}
|
||||
else
|
||||
{
|
||||
client.DefaultRequestHeaders.Add("Authorization", "Bearer " + request.APIKey);
|
||||
}
|
||||
|
||||
// 判断请求的url是不是满足条件
|
||||
if (string.IsNullOrEmpty(request.url))
|
||||
{
|
||||
throw new Exception("请求的url为空");
|
||||
}
|
||||
if (!request.url.StartsWith("https://ark.cn-beijing.volces.com") && !request.url.StartsWith("https://api.moonshot.cn") && !request.url.StartsWith("https://laitool.net") && !request.url.StartsWith("https://api.laitool.cc") && !request.url.StartsWith("https://laitool.cc"))
|
||||
if (!request.url.StartsWith("https://ark.cn-beijing.volces.com")
|
||||
&& !request.url.StartsWith("https://api.moonshot.cn")
|
||||
&& !request.url.StartsWith("https://laitool.net")
|
||||
&& !request.url.StartsWith("https://api.laitool.net")
|
||||
&& !request.url.StartsWith("https://api.laitool.cc")
|
||||
&& !request.url.StartsWith("https://laitool.cc"))
|
||||
{
|
||||
throw new Exception("请求的url不合法");
|
||||
throw new Exception("请求的url不支持转发");
|
||||
}
|
||||
client.Timeout = Timeout.InfiniteTimeSpan;
|
||||
var response = await client.PostAsync(request.url, new StringContent(request.dataString, Encoding.UTF8, "application/json"));
|
||||
|
||||
// 判断返回的状态码
|
||||
if (response.StatusCode != HttpStatusCode.OK)
|
||||
{
|
||||
if (response.StatusCode == HttpStatusCode.Unauthorized)
|
||||
{
|
||||
return APIResponseModel<object>.CreateErrorResponseModel(ResponseCode.ForwardWordFail, "responseCode: 401", "请求失败");
|
||||
}
|
||||
// 读取响应体
|
||||
string responseContent = await response.Content.ReadAsStringAsync();
|
||||
return APIResponseModel<object>.CreateErrorResponseModel(ResponseCode.ForwardWordFail, responseContent, "请求失败");
|
||||
}
|
||||
var content = await response.Content.ReadAsStringAsync();
|
||||
return APIResponseModel<object>.CreateSuccessResponseModel(content);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return APIResponseModel<object>.CreateErrorResponseModel(ResponseCode.SystemError, e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Get直接转发接口
|
||||
internal async Task<ActionResult<APIResponseModel<object>>> GetTransfer(GetTransferModel getTransferModel)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 开始拼接请求体
|
||||
using HttpClient client = new();
|
||||
|
||||
if (getTransferModel.url.StartsWith("https://api.laitool.net"))
|
||||
{
|
||||
client.DefaultRequestHeaders.Add("mj-api-secret", getTransferModel.APIKey);
|
||||
}
|
||||
else
|
||||
{
|
||||
client.DefaultRequestHeaders.Add("Authorization", "Bearer " + getTransferModel.APIKey);
|
||||
}
|
||||
|
||||
// 判断请求的url是不是满足条件
|
||||
if (string.IsNullOrEmpty(getTransferModel.url))
|
||||
{
|
||||
throw new Exception("请求的url为空");
|
||||
}
|
||||
if (!getTransferModel.url.StartsWith("https://ark.cn-beijing.volces.com")
|
||||
&& !getTransferModel.url.StartsWith("https://api.moonshot.cn")
|
||||
&& !getTransferModel.url.StartsWith("https://laitool.net")
|
||||
&& !getTransferModel.url.StartsWith("https://api.laitool.net")
|
||||
&& !getTransferModel.url.StartsWith("https://api.laitool.cc")
|
||||
&& !getTransferModel.url.StartsWith("https://laitool.cc"))
|
||||
{
|
||||
throw new Exception("请求的url不支持转发");
|
||||
}
|
||||
client.Timeout = Timeout.InfiniteTimeSpan;
|
||||
var response = await client.GetAsync(getTransferModel.url);
|
||||
// 判断返回的状态码
|
||||
if (response.StatusCode != HttpStatusCode.OK)
|
||||
{
|
||||
@@ -201,6 +269,5 @@ public class ForwardWordService(ApplicationDbContext context)
|
||||
return APIResponseModel<object>.CreateErrorResponseModel(ResponseCode.SystemError, e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user