Skip to content

BillionMail gives you open-source MailServer, NewsLetter, Email Marketing — fully self-hosted, dev-friendly, and free from monthly fees. Join the discord: https://discord.gg/asfXzBUhZr

Add project status retrieval and setting API

hwliang387d4478eaf8
diff --git a/core/api/askai/askai.go b/core/api/askai/askai.go
index 5612a53c..1a6c79b8 100644
--- a/core/api/askai/askai.go
+++ b/core/api/askai/askai.go
@@ -45,6 +45,8 @@ type IAskAiV1 interface {
RemoveImage(req *v1.RemoveImageReq) (res *v1.RemoveImageRes, err error)
ModifyImage(req *v1.ModifyImageReq) (res *v1.ModifyImageRes, err error)
GetImages(req *v1.GetImagesReq) (res *v1.GetImagesRes, err error)
+ GetProjectStatus(req *v1.GetProjectStatusReq) (res *v1.GetProjectStatusRes, err error)
+ SetProjectStatus(req *v1.SetProjectStatusReq) (res *v1.SetProjectStatusRes, err error)
// Chat related methods
CreateChat(req *v1.CreateChatReq) (res *v1.CreateChatRes, err error)
diff --git a/core/api/askai/v1/project.go b/core/api/askai/v1/project.go
index 09f58bb4..1273fcf8 100644
--- a/core/api/askai/v1/project.go
+++ b/core/api/askai/v1/project.go
@@ -241,3 +241,23 @@ type GetImagesReq struct {
type GetImagesRes struct {
api_v1.StandardRes
}
+
+// GetProjectStatusReq is the request structure for retrieving the status of a project in AskAi.
+type GetProjectStatusReq struct {
+ g.Meta `path:"/askai/project/get_project_status" method:"post" tags:"AskAi" summary:"get project status"`
+ Domain string `json:"domain" dc:"domain" v:"required#domain is required"`
+}
+type GetProjectStatusRes struct {
+ api_v1.StandardRes
+}
+
+// SetProjectStatusReq is the request structure for setting the status of a project in AskAi.
+type SetProjectStatusReq struct {
+ g.Meta `path:"/askai/project/set_project_status" method:"post" tags:"AskAi" summary:"set project status"`
+ Domain string `json:"domain" dc:"domain" v:"required#domain is required"`
+ Status bool `json:"status" dc:"status" v:"required#status is required"`
+}
+
+type SetProjectStatusRes struct {
+ api_v1.StandardRes
+}
diff --git a/core/internal/controller/askai/askai_v1_project.go b/core/internal/controller/askai/askai_v1_project.go
index 543f7385..e0de3090 100644
--- a/core/internal/controller/askai/askai_v1_project.go
+++ b/core/internal/controller/askai/askai_v1_project.go
@@ -17,6 +17,32 @@ func (c *ControllerV1) Create(ctx context.Context, req *v1.CreateReq) (res *v1.C
return res, nil
}
+func (c *ControllerV1) GetProjectStatus(ctx context.Context, req *v1.GetProjectStatusReq) (res *v1.GetProjectStatusRes, err error) {
+ res = &v1.GetProjectStatusRes{}
+ projectStatus, createStatus, err := askai.GetProjectStatus(req.Domain)
+ if err != nil {
+ res.SetError(err)
+ } else {
+ res.Data = map[string]interface{}{
+ "status": projectStatus,
+ "create_status": createStatus,
+ }
+ res.SetSuccess("Project status retrieved successfully")
+ }
+ return res, nil
+}
+
+func (c *ControllerV1) SetProjectStatus(ctx context.Context, req *v1.SetProjectStatusReq) (res *v1.SetProjectStatusRes, err error) {
+ res = &v1.SetProjectStatusRes{}
+ err = askai.SetProjectStatus(req.Domain, req.Status)
+ if err != nil {
+ res.SetError(err)
+ } else {
+ res.SetSuccess("Project status set successfully")
+ }
+ return res, nil
+}
+
func (c *ControllerV1) GetBaseInfo(ctx context.Context, req *v1.GetBaseInfoReq) (res *v1.GetBaseInfoRes, err error) {
res = &v1.GetBaseInfoRes{}
res.Data, err = askai.GetBaseInfo(req.Domain)
diff --git a/core/internal/service/askai/project.go b/core/internal/service/askai/project.go
index b84282eb..0b318408 100644
--- a/core/internal/service/askai/project.go
+++ b/core/internal/service/askai/project.go
@@ -33,6 +33,7 @@ type ProjectConfig struct {
SecondaryLogo string `json:"secondary_logo"` // 副Logo
Favicon string `json:"favicon"` // 网站图标
KnowledgeBase []KnowledgeInfo `json:"knowledge_base"` // 知识库
+ Status bool `json:"status"` // 项目状态
UpdateTime int64 `json:"update_time"` // 更新时间
}
@@ -162,6 +163,7 @@ func Create(Domain string, urls []string) error {
PrimaryLogo: "",
SecondaryLogo: "",
Favicon: "",
+ Status: true, // Default status is active
KnowledgeBase: []KnowledgeInfo{},
}
@@ -192,6 +194,7 @@ func GetBaseInfo(Domain string) (ProjectConfig, error) {
SecondaryLogo: config.SecondaryLogo,
Favicon: config.Favicon,
UpdateTime: config.UpdateTime,
+ Status: config.Status,
}
// Get the knowledge base list
@@ -204,6 +207,36 @@ func GetBaseInfo(Domain string) (ProjectConfig, error) {
return baseInfo, nil
}
+// GetProjectStatus retrieves the status of a project configuration based on the provided domain.
+// It reads the project configuration and returns a boolean indicating whether the project is active or not.
+func GetProjectStatus(Domain string) (bool, bool, error) {
+ config, err := ReadProjectConfig(Domain)
+ if err != nil {
+ return false, false, nil
+ }
+
+ // Return the project status
+ return config.Status, true, nil
+}
+
+// SetProjectStatus updates the status of a project configuration based on the provided domain.
+// It reads the existing configuration, modifies the status, and saves the updated configuration back to the file.
+func SetProjectStatus(Domain string, status bool) error {
+ config, err := ReadProjectConfig(Domain)
+ if err != nil {
+ return fmt.Errorf("error reading project configuration: %v", err)
+ }
+
+ // Update the project status
+ config.Status = status
+
+ err = SaveProjectConfig(Domain, config)
+ if err != nil {
+ return fmt.Errorf("error saving project configuration: %v", err)
+ }
+ return nil
+}
+
// ModifyBaseInfo updates the base information of a project configuration based on the provided domain.
// It reads the existing configuration, modifies the specified fields, and saves the updated configuration back to the file.
// If any field is empty, it will not be updated.