1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-03-01 03:24:14 +08:00

feat: Modified the logic for AI Tool (#7894)

This commit is contained in:
zhengkunwang 2025-02-18 13:59:10 +08:00 committed by GitHub
parent 10a7fb3be2
commit e492c6573c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 54 additions and 12 deletions

View File

@ -14,8 +14,8 @@ type OllamaBindDomain struct {
Domain string `json:"domain" validate:"required"`
AppInstallID uint `json:"appInstallID" validate:"required"`
SSLID uint `json:"sslID"`
AllowIPs []string `json:"allowIPs"`
WebsiteID uint `json:"websiteID"`
IPList string `json:"ipList"`
}
type OllamaBindDomainReq struct {

View File

@ -3,6 +3,7 @@ package service
import (
"context"
"fmt"
"github.com/1Panel-dev/1Panel/backend/utils/common"
"io"
"os"
"os/exec"
@ -203,6 +204,16 @@ func (u *AIToolService) BindDomain(req dto.OllamaBindDomain) error {
if nginxInstall.ID == 0 {
return buserr.New("ErrOpenrestyInstall")
}
var (
ipList []string
err error
)
if len(req.IPList) > 0 {
ipList, err = common.HandleIPList(req.IPList)
if err != nil {
return err
}
}
createWebsiteReq := request.WebsiteCreate{
PrimaryDomain: req.Domain,
Alias: strings.ToLower(req.Domain),
@ -218,9 +229,11 @@ func (u *AIToolService) BindDomain(req dto.OllamaBindDomain) error {
if err != nil {
return err
}
if err = ConfigAllowIPs(req.AllowIPs, website); err != nil {
if len(ipList) > 0 {
if err = ConfigAllowIPs(ipList, website); err != nil {
return err
}
}
if req.SSLID > 0 {
sslReq := request.WebsiteHTTPSOp{
WebsiteID: website.ID,
@ -263,12 +276,22 @@ func (u *AIToolService) UpdateBindDomain(req dto.OllamaBindDomain) error {
if nginxInstall.ID == 0 {
return buserr.New("ErrOpenrestyInstall")
}
var (
ipList []string
err error
)
if len(req.IPList) > 0 {
ipList, err = common.HandleIPList(req.IPList)
if err != nil {
return err
}
}
websiteService := NewIWebsiteService()
website, err := websiteRepo.GetFirst(commonRepo.WithByID(req.WebsiteID))
if err != nil {
return err
}
if err = ConfigAllowIPs(req.AllowIPs, website); err != nil {
if err = ConfigAllowIPs(ipList, website); err != nil {
return err
}
if req.SSLID > 0 {

View File

@ -3,6 +3,7 @@ package common
import (
"crypto/rand"
"fmt"
"github.com/1Panel-dev/1Panel/backend/buserr"
"github.com/gin-gonic/gin"
"io"
mathRand "math/rand"
@ -351,3 +352,22 @@ func GetLang(c *gin.Context) string {
}
return lang
}
func HandleIPList(content string) ([]string, error) {
ipList := strings.Split(content, "\n")
var res []string
for _, ip := range ipList {
if ip == "" {
continue
}
if net.ParseIP(ip) != nil {
res = append(res, ip)
continue
}
if _, _, err := net.ParseCIDR(ip); err != nil {
return nil, buserr.New("ErrParseIP")
}
res = append(res, ip)
}
return res, nil
}

View File

@ -83,7 +83,7 @@ export namespace AI {
export interface BindDomain {
domain: string;
sslID: number;
allowIPs: string[];
ipList: string;
appInstallID: number;
websiteID?: number;
}

View File

@ -30,7 +30,7 @@
:rows="3"
type="textarea"
clearable
v-model.trim="req.ipList"
v-model="req.ipList"
:placeholder="$t('xpack.waf.ipGroupHelper')"
/>
</el-form-item>
@ -128,7 +128,7 @@ const req = ref({
websiteID: 0,
});
const rules = reactive<FormRules>({
domain: [Rules.requiredInput],
domain: [Rules.domainWithPort],
});
const emit = defineEmits(['search']);
@ -196,7 +196,6 @@ const onSubmit = async (formEl: FormInstance | undefined) => {
if (!formEl) return;
formEl.validate(async (valid) => {
if (!valid) return;
req.value.allowIPs = req.value.ipList.split('\n');
if (operate.value === 'update') {
await updateBindDomain(req.value);
} else {