mirror of
https://github.com/APIParkLab/APIPark.git
synced 2026-06-14 20:41:15 +08:00
Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e449f86c01 | |||
| a1bdc048a7 | |||
| 0a1b08157d | |||
| d36c66371f | |||
| b7bb409e96 | |||
| 517007c941 | |||
| 4c685a9ec6 | |||
| 1aca2099de | |||
| a93e5b4ff8 | |||
| 85d25bebe2 | |||
| 9fa43ccc00 | |||
| c2a11050dd | |||
| 080bfc3a44 | |||
| 836c7699b8 |
@@ -27,7 +27,7 @@ type imlAPIController struct {
|
||||
}
|
||||
|
||||
func (i *imlAPIController) Create(ctx *gin.Context, serviceId string, input *ai_api_dto.CreateAPI) (*ai_api_dto.API, error) {
|
||||
info, err := i.serviceModule.Get(ctx, serviceId)
|
||||
_, err := i.serviceModule.Get(ctx, serviceId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -52,7 +52,7 @@ func (i *imlAPIController) Create(ctx *gin.Context, serviceId string, input *ai_
|
||||
plugins["ai_formatter"] = api.PluginSetting{
|
||||
Config: plugin_model.ConfigType{
|
||||
"model": input.AiModel.Id,
|
||||
"provider": fmt.Sprintf("%s@ai-provider", info.Provider.Id),
|
||||
"provider": fmt.Sprintf("%s@ai-provider", input.AiModel.Provider),
|
||||
"config": input.AiModel.Config,
|
||||
},
|
||||
}
|
||||
@@ -73,7 +73,7 @@ func (i *imlAPIController) Create(ctx *gin.Context, serviceId string, input *ai_
|
||||
Retry: input.Retry,
|
||||
Plugins: plugins,
|
||||
},
|
||||
Upstream: info.Provider.Id,
|
||||
Upstream: input.AiModel.Provider,
|
||||
Disable: false,
|
||||
})
|
||||
|
||||
@@ -86,7 +86,7 @@ func (i *imlAPIController) Create(ctx *gin.Context, serviceId string, input *ai_
|
||||
}
|
||||
|
||||
func (i *imlAPIController) Edit(ctx *gin.Context, serviceId string, apiId string, input *ai_api_dto.EditAPI) (*ai_api_dto.API, error) {
|
||||
info, err := i.serviceModule.Get(ctx, serviceId)
|
||||
_, err := i.serviceModule.Get(ctx, serviceId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -106,11 +106,11 @@ func (i *imlAPIController) Edit(ctx *gin.Context, serviceId string, apiId string
|
||||
proxy.Plugins["ai_formatter"] = api.PluginSetting{
|
||||
Config: plugin_model.ConfigType{
|
||||
"model": input.AiModel.Id,
|
||||
"provider": fmt.Sprintf("%s@ai-provider", info.Provider.Id),
|
||||
"provider": fmt.Sprintf("%s@ai-provider", input.AiModel.Provider),
|
||||
"config": input.AiModel.Config,
|
||||
},
|
||||
}
|
||||
upstream = &info.Provider.Id
|
||||
upstream = &input.AiModel.Provider
|
||||
}
|
||||
|
||||
if input.AiPrompt != nil {
|
||||
|
||||
@@ -326,7 +326,33 @@ func (i *imlServiceController) Create(ctx *gin.Context, teamID string, input *se
|
||||
if input.Kind == "ai" {
|
||||
return i.createAIService(ctx, teamID, input)
|
||||
}
|
||||
return i.module.Create(ctx, teamID, input)
|
||||
var err error
|
||||
var info *service_dto.Service
|
||||
err = i.transaction.Transaction(ctx, func(txCtx context.Context) error {
|
||||
info, err = i.module.Create(txCtx, teamID, input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
path := fmt.Sprintf("/%s/", strings.Trim(input.Prefix, "/"))
|
||||
_, err = i.routerModule.Create(txCtx, info.Id, &router_dto.Create{
|
||||
Id: uuid.New().String(),
|
||||
Name: "",
|
||||
Path: path + "*",
|
||||
Methods: []string{http.MethodGet, http.MethodPost, http.MethodPut, http.MethodDelete, http.MethodPatch, http.MethodOptions},
|
||||
Description: "auto create by create service",
|
||||
Protocols: []string{"http", "https"},
|
||||
MatchRules: nil,
|
||||
Upstream: "",
|
||||
Proxy: &router_dto.InputProxy{
|
||||
Path: path,
|
||||
Timeout: 30000,
|
||||
Retry: 0,
|
||||
},
|
||||
Disable: false,
|
||||
})
|
||||
return err
|
||||
})
|
||||
return info, err
|
||||
}
|
||||
|
||||
func (i *imlServiceController) Edit(ctx *gin.Context, id string, input *service_dto.EditService) (*service_dto.Service, error) {
|
||||
|
||||
@@ -265,7 +265,8 @@ func (i *imlInitController) OnInit() {
|
||||
return fmt.Errorf("create default team error: %v", err)
|
||||
}
|
||||
// 创建Rest服务
|
||||
_, err = i.serviceModule.Create(ctx, info.Id, &service_dto.CreateService{
|
||||
restPath := "/rest-demo"
|
||||
serviceInfo, err := i.serviceModule.Create(ctx, info.Id, &service_dto.CreateService{
|
||||
Name: "REST Demo Service",
|
||||
Prefix: "/rest-demo",
|
||||
Description: "Auto created By APIPark",
|
||||
@@ -277,6 +278,26 @@ func (i *imlInitController) OnInit() {
|
||||
if err != nil {
|
||||
return fmt.Errorf("create default service error: %v", err)
|
||||
}
|
||||
path := fmt.Sprintf("/%s/", strings.Trim(restPath, "/"))
|
||||
_, err = i.routerModule.Create(ctx, serviceInfo.Id, &router_dto.Create{
|
||||
Id: uuid.NewString(),
|
||||
Name: "",
|
||||
Path: path + "*",
|
||||
Methods: []string{http.MethodGet, http.MethodPost, http.MethodPut, http.MethodDelete, http.MethodPatch, http.MethodOptions},
|
||||
Description: "auto create by create service",
|
||||
Protocols: []string{"http", "https"},
|
||||
MatchRules: nil,
|
||||
Upstream: "",
|
||||
Proxy: &router_dto.InputProxy{
|
||||
Path: path,
|
||||
Timeout: 30000,
|
||||
Retry: 0,
|
||||
},
|
||||
Disable: false,
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("create default router error: %v", err)
|
||||
}
|
||||
// 创建AI服务
|
||||
err = i.createAIService(ctx, info.Id, &service_dto.CreateService{
|
||||
Name: "AI Demo Service",
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"env": {
|
||||
"browser": true,
|
||||
"es2021": true,
|
||||
"node": true
|
||||
},
|
||||
"extends": [
|
||||
"eslint:recommended",
|
||||
"plugin:react/recommended",
|
||||
"plugin:@typescript-eslint/recommended",
|
||||
"prettier"
|
||||
],
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"parserOptions": {
|
||||
"ecmaFeatures": {
|
||||
"jsx": true
|
||||
},
|
||||
"ecmaVersion": "latest",
|
||||
"sourceType": "module"
|
||||
},
|
||||
"plugins": ["react", "@typescript-eslint", "prettier"],
|
||||
"rules": {
|
||||
"react/react-in-jsx-scope": "off",
|
||||
"prettier/prettier": "error",
|
||||
"@typescript-eslint/no-explicit-any": "warn",
|
||||
"no-unused-vars": "off",
|
||||
"@typescript-eslint/no-unused-vars": ["warn"]
|
||||
},
|
||||
"settings": {
|
||||
"react": {
|
||||
"version": "detect"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"semi": true,
|
||||
"singleQuote": true,
|
||||
"trailingComma": "es5",
|
||||
"tabWidth": 2,
|
||||
"printWidth": 100,
|
||||
"bracketSpacing": true,
|
||||
"arrowParens": "avoid",
|
||||
"jsxSingleQuote": false
|
||||
}
|
||||
@@ -4,69 +4,88 @@ import { memo, useEffect, useMemo } from 'react';
|
||||
import { useGlobalContext } from '@common/contexts/GlobalStateContext';
|
||||
import { Icon } from '@iconify/react/dist/iconify.js';
|
||||
|
||||
const LanguageSetting = ({mode = 'light'}:{mode?:'dark'|'light'}) => {
|
||||
const { dispatch,state} = useGlobalContext()
|
||||
const items = [
|
||||
{
|
||||
key: 'en-US',
|
||||
label:<Button key="en" type="text" className="border-none p-0 flex items-center bg-transparent ">
|
||||
English
|
||||
</Button>,
|
||||
title:'English'
|
||||
},
|
||||
{
|
||||
key: 'ja-JP',
|
||||
label: <Button key="jp" type="text" className="border-none p-0 flex items-center bg-transparent ">
|
||||
const LanguageSetting = ({ mode = 'light' }: { mode?: 'dark' | 'light' }) => {
|
||||
const { dispatch, state } = useGlobalContext();
|
||||
const items = [
|
||||
{
|
||||
key: 'en-US',
|
||||
label: (
|
||||
<Button key="en" type="text" className="flex items-center p-0 bg-transparent border-none">
|
||||
English
|
||||
</Button>
|
||||
),
|
||||
title: 'English',
|
||||
},
|
||||
{
|
||||
key: 'ja-JP',
|
||||
label: (
|
||||
<Button key="jp" type="text" className="flex items-center p-0 bg-transparent border-none">
|
||||
日本語
|
||||
</Button>,
|
||||
title: '日本語',
|
||||
},
|
||||
{
|
||||
key: 'zh-TW',
|
||||
label: <Button key="tw" type="text" className="border-none p-0 flex items-center bg-transparent ">
|
||||
繁體中文
|
||||
</Button>,
|
||||
title: '繁體中文',
|
||||
},
|
||||
{
|
||||
key: 'zh-CN',
|
||||
label: <Button key="cn" type="text" className="border-none p-0 flex items-center bg-transparent ">
|
||||
简体中文
|
||||
</Button>,
|
||||
title: '简体中文',
|
||||
},
|
||||
</Button>
|
||||
),
|
||||
title: '日本語',
|
||||
},
|
||||
{
|
||||
key: 'zh-TW',
|
||||
label: (
|
||||
<Button key="tw" type="text" className="flex items-center p-0 bg-transparent border-none">
|
||||
繁體中文
|
||||
</Button>
|
||||
),
|
||||
title: '繁體中文',
|
||||
},
|
||||
{
|
||||
key: 'zh-CN',
|
||||
label: (
|
||||
<Button key="cn" type="text" className="flex items-center p-0 bg-transparent border-none">
|
||||
简体中文
|
||||
</Button>
|
||||
),
|
||||
title: '简体中文',
|
||||
},
|
||||
];
|
||||
|
||||
const langLabel = useMemo(()=>items.find((item) => item?.key === state.language)?.title,[state.language])
|
||||
const langLabel = useMemo(
|
||||
() => items.find(item => item?.key === state.language)?.title,
|
||||
[state.language]
|
||||
);
|
||||
|
||||
useEffect(()=>{
|
||||
const savedLang = sessionStorage.getItem('i18nextLng')
|
||||
const browserLang = navigator.language || navigator.userLanguage
|
||||
if(savedLang){
|
||||
dispatch({ type: 'UPDATE_LANGUAGE', language: savedLang });
|
||||
}else{
|
||||
dispatch({ type: 'UPDATE_LANGUAGE', language: browserLang });
|
||||
}
|
||||
},[
|
||||
])
|
||||
useEffect(() => {
|
||||
const savedLang = sessionStorage.getItem('i18nextLng');
|
||||
const browserLang = navigator.language || navigator.userLanguage;
|
||||
if (savedLang) return;
|
||||
|
||||
dispatch({ type: 'UPDATE_LANGUAGE', language: browserLang });
|
||||
}, []);
|
||||
return (
|
||||
<Dropdown
|
||||
trigger={['hover']}
|
||||
menu={{
|
||||
items,
|
||||
style:{minWidth:'80px'},
|
||||
onClick: (e) => {
|
||||
style: { minWidth: '80px' },
|
||||
onClick: e => {
|
||||
const { key } = e;
|
||||
dispatch({ type: 'UPDATE_LANGUAGE', language: key });
|
||||
dispatch({ type: 'UPDATE_LANGUAGE', language: key });
|
||||
i18n.changeLanguage(key);
|
||||
}
|
||||
},
|
||||
}}
|
||||
>
|
||||
<Button className={`border-none ${mode==='dark' ? "text-[#333] hover:text-[#333333b3]" : "text-[#ffffffb3] hover:text-[#fff] "}`} type="default" ghost >
|
||||
<span className='flex items-center gap-[8px]'> <Icon icon="ic:baseline-language" width="14" height="14"/>{langLabel}</span>
|
||||
</Button>
|
||||
<Button
|
||||
className={`border-none ${
|
||||
mode === 'dark'
|
||||
? 'text-[#333] hover:text-[#333333b3]'
|
||||
: 'text-[#ffffffb3] hover:text-[#fff] '
|
||||
}`}
|
||||
type="default"
|
||||
ghost
|
||||
>
|
||||
<span className="flex items-center gap-[8px]">
|
||||
{' '}
|
||||
<Icon icon="ic:baseline-language" width="14" height="14" />
|
||||
{langLabel}
|
||||
</span>
|
||||
</Button>
|
||||
</Dropdown>
|
||||
);
|
||||
};
|
||||
export default memo(LanguageSetting);
|
||||
|
||||
|
||||
@@ -146,20 +146,11 @@ export const PublishApprovalModalContent = forwardRef<PublishApprovalModalHandle
|
||||
...x,
|
||||
title: typeof x.title === 'string' ? $t(x.title) : x.title,
|
||||
...(x.dataIndex === 'status' ? {
|
||||
render:(_,entity)=> {
|
||||
switch(entity.change){
|
||||
case 'none':
|
||||
return '-'
|
||||
case 'new':
|
||||
return $t('新建')
|
||||
case 'update':
|
||||
return $t('更新')
|
||||
case 'delete':
|
||||
return $t('删除')
|
||||
default:
|
||||
return '-'
|
||||
}
|
||||
}
|
||||
render:(_,entity)=> (
|
||||
<span className={`${ApprovalStatusColorClass[entity.change as keyof typeof ApprovalStatusColorClass]} truncate block`}>
|
||||
{$t(ChangeTypeEnum[entity.change as (keyof typeof ChangeTypeEnum)] || '-')}
|
||||
</span>
|
||||
)
|
||||
}:{})
|
||||
}
|
||||
}),[state.language])
|
||||
|
||||
@@ -295,7 +295,7 @@ export interface IconParkIconElement extends HTMLElement {
|
||||
| 'apispace'
|
||||
| 'auto-generate-api'
|
||||
| 'compare-api'
|
||||
| 'multi-protocal'
|
||||
| 'multi-protocol'
|
||||
| 'read-good'
|
||||
| 'richdoc'
|
||||
| 'mockapi'
|
||||
|
||||
@@ -486,17 +486,17 @@ export const PERMISSION_DEFINITION = [
|
||||
},
|
||||
"team.application.subscription.add": {
|
||||
"granted": {
|
||||
"anyOf": [{ "backend": ["system.workspace.application.manager_al","team.consumer.subscription.subscribe"] }]
|
||||
"anyOf": [{ "backend": ["system.workspace.application.manager_all","team.consumer.subscription.subscribe"] }]
|
||||
}
|
||||
},
|
||||
"team.application.subscription.edit": {
|
||||
"granted": {
|
||||
"anyOf": [{ "backend": ["system.workspace.application.manager_al","team.consumer.subscription.manager_subscribed_services"] }]
|
||||
"anyOf": [{ "backend": ["system.workspace.application.manager_all","team.consumer.subscription.manager_subscribed_services"] }]
|
||||
}
|
||||
},
|
||||
"team.application.subscription.delete": {
|
||||
"granted": {
|
||||
"anyOf": [{ "backend": ["system.workspace.application.manager_al","team.team.consumer.subscription.manager_subscribed_services"] }]
|
||||
"anyOf": [{ "backend": ["system.workspace.application.manager_all","team.team.consumer.subscription.manager_subscribed_services"] }]
|
||||
}
|
||||
},
|
||||
"team.application.application.view": {
|
||||
@@ -506,47 +506,47 @@ export const PERMISSION_DEFINITION = [
|
||||
},
|
||||
"team.application.application.add": {
|
||||
"granted": {
|
||||
"anyOf": [{ "backend": ["system.workspace.application.manager_al",'team.team.consumer.manager',"team.consumer.application.manager"] }]
|
||||
"anyOf": [{ "backend": ["system.workspace.application.manager_all",'team.team.consumer.manager',"team.consumer.application.manager"] }]
|
||||
}
|
||||
},
|
||||
"team.application.application.edit": {
|
||||
"granted": {
|
||||
"anyOf": [{ "backend": ["system.workspace.application.manager_al",'team.team.consumer.manager',"team.consumer.application.manager"] }]
|
||||
"anyOf": [{ "backend": ["system.workspace.application.manager_all",'team.team.consumer.manager',"team.consumer.application.manager"] }]
|
||||
}
|
||||
},
|
||||
"team.application.application.delete": {
|
||||
"granted": {
|
||||
"anyOf": [{ "backend": ["system.workspace.application.manager_al",'team.team.consumer.manager',"team.consumer.application.manager"] }]
|
||||
"anyOf": [{ "backend": ["system.workspace.application.manager_all",'team.team.consumer.manager',"team.consumer.application.manager"] }]
|
||||
}
|
||||
},
|
||||
"team.consumer.authorization.view": {
|
||||
"granted": {
|
||||
"anyOf": [{ "backend": ["system.workspace.application.manager_al","system.workspace.application.view_all","team.consumer.authorization.view"] }]
|
||||
"anyOf": [{ "backend": ["system.workspace.application.manager_all","system.workspace.application.view_all","team.consumer.authorization.view"] }]
|
||||
}
|
||||
},
|
||||
"team.application.authorization.add": {
|
||||
"granted": {
|
||||
"anyOf": [{ "backend": ["system.workspace.application.manager_al","team.consumer.authorization.manager"] }]
|
||||
"anyOf": [{ "backend": ["system.workspace.application.manager_all","team.consumer.authorization.manager"] }]
|
||||
}
|
||||
},
|
||||
"team.application.authorization.edit": {
|
||||
"granted": {
|
||||
"anyOf": [{ "backend": ["system.workspace.application.manager_al","team.consumer.authorization.manager"] }]
|
||||
"anyOf": [{ "backend": ["system.workspace.application.manager_all","team.consumer.authorization.manager"] }]
|
||||
}
|
||||
},
|
||||
"team.application.authorization.delete": {
|
||||
"granted": {
|
||||
"anyOf": [{ "backend": ["system.workspace.application.manager_al","team.consumer.authorization.manager"] }]
|
||||
"anyOf": [{ "backend": ["system.workspace.application.manager_all","team.consumer.authorization.manager"] }]
|
||||
}
|
||||
},
|
||||
"team.application.authorization.cancelSubApply": {
|
||||
"granted": {
|
||||
"anyOf": [{ "backend": ["system.workspace.application.manager_al","team.consumer.authorization.manager"] }]
|
||||
"anyOf": [{ "backend": ["system.workspace.application.manager_all","team.consumer.authorization.manager"] }]
|
||||
}
|
||||
},
|
||||
"team.application.authorization.cancelSub": {
|
||||
"granted": {
|
||||
"anyOf": [{ "backend": ["system.workspace.application.manager_al","team.consumer.authorization.manager"] }]
|
||||
"anyOf": [{ "backend": ["system.workspace.application.manager_all","team.consumer.authorization.manager"] }]
|
||||
}
|
||||
},
|
||||
"team.team.team.view": {
|
||||
|
||||
@@ -106,9 +106,9 @@ const AiSettingList = ()=>{
|
||||
</a>
|
||||
<div>
|
||||
<CancelBtn/>
|
||||
<WithPermission access="system.devops.ai_provider.edit" showDisabled={false}>
|
||||
<OkBtn/>
|
||||
</WithPermission>
|
||||
{
|
||||
checkAccess('system.devops.ai_provider.edit', accessData) ? <OkBtn/> : null
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -88,7 +88,7 @@ const PartitionInsideDashboardSetting: FC = () => {
|
||||
pageTitle={$t('数据源')}
|
||||
description={$t("设置监控报表的数据来源,设置完成之后即可获得详细的API调用统计图表。")}
|
||||
showBorder={false}
|
||||
scrollPage={true}
|
||||
scrollPage={false}
|
||||
>
|
||||
<div className="flex flex-col overflow-auto pb-PAGE_INSIDE_B pr-PAGE_INSIDE_X">
|
||||
<Spin wrapperClassName="flex-1" indicator={<LoadingOutlined style={{ fontSize: 24 }} spin />} spinning={loading}>
|
||||
|
||||
@@ -77,7 +77,8 @@ export default defineConfig({
|
||||
target: 'http://172.18.166.219:8288/',
|
||||
changeOrigin: true,
|
||||
}
|
||||
}
|
||||
},
|
||||
open: true
|
||||
},
|
||||
logLevel:'info'
|
||||
})
|
||||
|
||||
@@ -11,7 +11,7 @@ import { RouterParams } from "@core/components/aoplatform/RenderRoutes";
|
||||
import { SimpleTeamItem } from "@common/const/type";
|
||||
import { useTenantManagementContext } from "../../../contexts/TenantManagementContext";
|
||||
import { Icon } from "@iconify/react/dist/iconify.js";
|
||||
import { useGlobalContext } from "@common/contexts/GlobalStateContext";
|
||||
import { GlobalProvider, useGlobalContext } from "@common/contexts/GlobalStateContext";
|
||||
import { $t } from "@common/locales";
|
||||
import WithPermission from "@common/components/aoplatform/WithPermission";
|
||||
import InsidePage from "@common/components/aoplatform/InsidePage";
|
||||
@@ -149,7 +149,7 @@ export default function ServiceHubManagement() {
|
||||
switch (type){
|
||||
case 'add':
|
||||
title=$t('添加消费者')
|
||||
content=<ManagementConfig ref={addManagementRef} dataShowType={dataShowType} type={type} teamId={teamId!} />
|
||||
content=<GlobalProvider><ManagementConfig ref={addManagementRef} dataShowType={dataShowType} type={type} teamId={teamId!} /></GlobalProvider>
|
||||
break;
|
||||
// case 'edit':{
|
||||
// title='配置 Open Api'
|
||||
|
||||
+1
-1
@@ -34,7 +34,7 @@ func newAIUpstream(provider string, uri model_runtime.IProviderURI) *gateway.Dyn
|
||||
"driver": "http",
|
||||
"balance": "round-robin",
|
||||
"nodes": []string{fmt.Sprintf("%s weight=100", uri.Host())},
|
||||
"pass_node": "node",
|
||||
"pass_host": "node",
|
||||
"scheme": uri.Scheme(),
|
||||
"timeout": 300000,
|
||||
},
|
||||
|
||||
@@ -3,6 +3,7 @@ package api_doc
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
api_doc_dto "github.com/APIParkLab/APIPark/module/api-doc/dto"
|
||||
api_doc "github.com/APIParkLab/APIPark/service/api-doc"
|
||||
"github.com/APIParkLab/APIPark/service/service"
|
||||
@@ -20,16 +21,19 @@ type imlAPIDocModule struct {
|
||||
}
|
||||
|
||||
func (i *imlAPIDocModule) UpdateDoc(ctx context.Context, serviceId string, input *api_doc_dto.UpdateDoc) (*api_doc_dto.ApiDocDetail, error) {
|
||||
_, err := i.serviceService.Get(ctx, serviceId)
|
||||
info, err := i.serviceService.Get(ctx, serviceId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if input.Id == "" {
|
||||
input.Id = uuid.New().String()
|
||||
}
|
||||
// 每个API加上前缀
|
||||
|
||||
err = i.apiDocService.UpdateDoc(ctx, serviceId, &api_doc.UpdateDoc{
|
||||
ID: input.Id,
|
||||
Content: input.Content,
|
||||
Prefix: info.Prefix,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -3,9 +3,9 @@ package aksk
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
|
||||
auth_driver "github.com/APIParkLab/APIPark/module/application-authorization/auth-driver"
|
||||
|
||||
|
||||
application_authorization_dto "github.com/APIParkLab/APIPark/module/application-authorization/dto"
|
||||
)
|
||||
|
||||
@@ -26,8 +26,7 @@ type Config struct {
|
||||
}
|
||||
|
||||
func (a *Config) ID() string {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
return a.Ak
|
||||
}
|
||||
|
||||
func (a *Config) Valid() ([]byte, error) {
|
||||
|
||||
+1
-23
@@ -165,29 +165,7 @@ func (i *imlLogModule) Get(ctx context.Context, driver string) (*log_dto.LogSour
|
||||
}
|
||||
|
||||
func (i *imlLogModule) OnComplete() {
|
||||
drivers := log_driver.Drivers()
|
||||
if len(drivers) < 1 {
|
||||
return
|
||||
}
|
||||
ctx := context.Background()
|
||||
for _, driver := range drivers {
|
||||
factory, has := log_driver.GetFactory(driver)
|
||||
if !has {
|
||||
log_print.Errorf("driver %s not found", driver)
|
||||
continue
|
||||
}
|
||||
info, err := i.service.GetLogSource(ctx, driver)
|
||||
if err != nil {
|
||||
log_print.Errorf("get log source %s error: %s", driver, err)
|
||||
continue
|
||||
}
|
||||
d, _, err := factory.Create(info.Config)
|
||||
if err != nil {
|
||||
log_print.Errorf("create driver %s error: %s,config: %s", driver, err, info.Config)
|
||||
continue
|
||||
}
|
||||
log_driver.SetDriver(driver, d)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (i *imlLogModule) initGateway(ctx context.Context, clusterId string, clientDriver gateway.IClientDriver) error {
|
||||
|
||||
+12
-1
@@ -76,6 +76,17 @@ func (i *imlAPIDocService) UpdateDoc(ctx context.Context, serviceId string, inpu
|
||||
if err := doc.Valid(); err != nil {
|
||||
return err
|
||||
}
|
||||
if input.Prefix != "" {
|
||||
err = doc.AddPrefixInAll(input.Prefix)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
data, err := doc.Marshal()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
input.Content = string(data)
|
||||
|
||||
info, err := i.store.First(ctx, map[string]interface{}{
|
||||
"service": serviceId,
|
||||
@@ -94,9 +105,9 @@ func (i *imlAPIDocService) UpdateDoc(ctx context.Context, serviceId string, inpu
|
||||
APICount: doc.APICount(),
|
||||
})
|
||||
}
|
||||
info.Content = input.Content
|
||||
info.Updater = operator
|
||||
info.UpdateAt = time.Now()
|
||||
info.Content = input.Content
|
||||
info.APICount = doc.APICount()
|
||||
return i.store.Save(ctx, info)
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import "time"
|
||||
type UpdateDoc struct {
|
||||
ID string
|
||||
Content string
|
||||
Prefix string
|
||||
}
|
||||
|
||||
type Doc struct {
|
||||
|
||||
+32
-10
@@ -3,10 +3,14 @@ package api_doc
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
yaml "gopkg.in/yaml.v3"
|
||||
|
||||
"github.com/APIParkLab/APIPark/service/universally/commit"
|
||||
"github.com/eolinker/go-common/autowire"
|
||||
"github.com/getkin/kin-openapi/openapi3"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
type IAPIDocService interface {
|
||||
@@ -65,15 +69,6 @@ func (d *DocLoader) Valid() error {
|
||||
if d.openAPI3Doc.Paths == nil {
|
||||
return fmt.Errorf("openAPI3Doc.Paths is nil")
|
||||
}
|
||||
//err := d.openAPI3Doc.Validate(openapi3Loader.Context)
|
||||
//if err != nil {
|
||||
// openAPI2Doc, err := openapi2conv.FromV3(d.openAPI3Doc)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// validate.
|
||||
//
|
||||
//}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -110,3 +105,30 @@ func (d *DocLoader) APICount() int64 {
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
func (d *DocLoader) AddPrefixInAll(prefix string) error {
|
||||
prefix = strings.TrimSpace(prefix)
|
||||
if prefix == "" || d.openAPI3Doc == nil || d.openAPI3Doc.Paths == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
prefix = fmt.Sprintf("/%s/", strings.Trim(prefix, "/"))
|
||||
for path, item := range d.openAPI3Doc.Paths.Map() {
|
||||
path = strings.TrimSpace(path)
|
||||
if strings.HasPrefix(path, prefix) {
|
||||
continue
|
||||
}
|
||||
newPath := fmt.Sprintf("%s%s", prefix, strings.TrimPrefix(path, "/"))
|
||||
d.openAPI3Doc.Paths.Delete(path)
|
||||
d.openAPI3Doc.Paths.Set(newPath, item)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *DocLoader) Marshal() ([]byte, error) {
|
||||
result, err := d.openAPI3Doc.MarshalYAML()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return yaml.Marshal(result)
|
||||
}
|
||||
|
||||
@@ -162,6 +162,9 @@ func (i *imlAPIService) Save(ctx context.Context, id string, model *Edit) error
|
||||
if model.Disable != nil {
|
||||
ev.Disable = *model.Disable
|
||||
}
|
||||
if model.Upstream != nil {
|
||||
ev.Upstream = *model.Upstream
|
||||
}
|
||||
|
||||
e := i.apiInfoStore.Save(ctx, ev)
|
||||
if e != nil {
|
||||
|
||||
+25
-1
@@ -5,6 +5,8 @@ import (
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
log_print "github.com/eolinker/eosc/log"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
log_driver "github.com/APIParkLab/APIPark/log-driver"
|
||||
@@ -25,7 +27,29 @@ type imlLogService struct {
|
||||
}
|
||||
|
||||
func (i *imlLogService) OnComplete() {
|
||||
|
||||
drivers := log_driver.Drivers()
|
||||
if len(drivers) < 1 {
|
||||
return
|
||||
}
|
||||
ctx := context.Background()
|
||||
for _, driver := range drivers {
|
||||
factory, has := log_driver.GetFactory(driver)
|
||||
if !has {
|
||||
log_print.Errorf("driver %s not found", driver)
|
||||
continue
|
||||
}
|
||||
info, err := i.GetLogSource(ctx, driver)
|
||||
if err != nil {
|
||||
log_print.Errorf("get log source %s error: %s", driver, err)
|
||||
continue
|
||||
}
|
||||
d, _, err := factory.Create(info.Config)
|
||||
if err != nil {
|
||||
log_print.Errorf("create driver %s error: %s,config: %s", driver, err, info.Config)
|
||||
continue
|
||||
}
|
||||
log_driver.SetDriver(driver, d)
|
||||
}
|
||||
}
|
||||
|
||||
func (i *imlLogService) UpdateLogSource(ctx context.Context, driver string, input *Save) error {
|
||||
|
||||
Reference in New Issue
Block a user