2023-01-10 16:43:42 +08:00
|
|
|
package schema
|
|
|
|
|
2023-02-21 17:28:05 +08:00
|
|
|
import (
|
|
|
|
"github.com/answerdev/answer/plugin"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
2023-01-29 16:06:17 +08:00
|
|
|
|
2023-01-11 10:02:45 +08:00
|
|
|
const (
|
|
|
|
PluginStatusActive PluginStatus = "active"
|
|
|
|
PluginStatusInactive PluginStatus = "inactive"
|
|
|
|
)
|
|
|
|
|
|
|
|
type PluginStatus string
|
|
|
|
|
2023-01-13 12:50:20 +08:00
|
|
|
type GetPluginListReq struct {
|
|
|
|
Status PluginStatus `form:"status"`
|
|
|
|
HaveConfig bool `form:"have_config"`
|
|
|
|
}
|
|
|
|
|
2023-01-11 10:02:45 +08:00
|
|
|
type GetPluginListResp struct {
|
|
|
|
Name string `json:"name"`
|
2023-01-13 12:50:20 +08:00
|
|
|
SlugName string `json:"slug_name"`
|
2023-01-11 10:02:45 +08:00
|
|
|
Description string `json:"description"`
|
|
|
|
Version string `json:"version"`
|
|
|
|
Enabled bool `json:"enabled"`
|
2023-01-13 12:50:20 +08:00
|
|
|
HaveConfig bool `json:"have_config"`
|
2023-03-02 11:03:24 +08:00
|
|
|
Link string `json:"link"`
|
2023-01-11 10:02:45 +08:00
|
|
|
}
|
|
|
|
|
2023-01-10 16:43:42 +08:00
|
|
|
type UpdatePluginStatusReq struct {
|
|
|
|
PluginSlugName string `validate:"required,gt=1,lte=100" json:"plugin_slug_name"`
|
|
|
|
Enabled bool `json:"enabled"`
|
|
|
|
}
|
2023-01-11 10:02:45 +08:00
|
|
|
|
|
|
|
type GetPluginConfigReq struct {
|
2023-01-13 12:50:20 +08:00
|
|
|
PluginSlugName string `validate:"required,gt=1,lte=100" form:"plugin_slug_name"`
|
2023-01-11 10:02:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
type GetPluginConfigResp struct {
|
2023-02-21 17:28:05 +08:00
|
|
|
Name string `json:"name"`
|
|
|
|
SlugName string `json:"slug_name"`
|
|
|
|
Description string `json:"description"`
|
|
|
|
Version string `json:"version"`
|
|
|
|
ConfigFields []ConfigField `json:"config_fields"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *GetPluginConfigResp) SetConfigFields(ctx *gin.Context, fields []plugin.ConfigField) {
|
|
|
|
for _, field := range fields {
|
|
|
|
configField := ConfigField{
|
|
|
|
Name: field.Name,
|
|
|
|
Type: string(field.Type),
|
2023-02-22 16:49:03 +08:00
|
|
|
Title: field.Title.Translate(ctx),
|
|
|
|
Description: field.Description.Translate(ctx),
|
2023-02-21 17:28:05 +08:00
|
|
|
Required: field.Required,
|
|
|
|
Value: field.Value,
|
|
|
|
UIOptions: ConfigFieldUIOptions{
|
|
|
|
Rows: field.UIOptions.Rows,
|
|
|
|
InputType: string(field.UIOptions.InputType),
|
|
|
|
},
|
|
|
|
}
|
2023-02-22 16:49:03 +08:00
|
|
|
configField.UIOptions.Placeholder = field.UIOptions.Placeholder.Translate(ctx)
|
2023-03-17 17:43:35 +08:00
|
|
|
configField.UIOptions.Label = field.UIOptions.Label.Translate(ctx)
|
2023-02-21 17:28:05 +08:00
|
|
|
|
|
|
|
for _, option := range field.Options {
|
|
|
|
configField.Options = append(configField.Options, ConfigFieldOption{
|
2023-02-22 16:49:03 +08:00
|
|
|
Label: option.Label.Translate(ctx),
|
2023-02-21 17:28:05 +08:00
|
|
|
Value: option.Value,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
g.ConfigFields = append(g.ConfigFields, configField)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type ConfigField struct {
|
|
|
|
Name string `json:"name"`
|
|
|
|
Type string `json:"type"`
|
|
|
|
Title string `json:"title"`
|
|
|
|
Description string `json:"description"`
|
|
|
|
Required bool `json:"required"`
|
2023-03-17 17:43:35 +08:00
|
|
|
Value any `json:"value"`
|
2023-02-21 17:28:05 +08:00
|
|
|
UIOptions ConfigFieldUIOptions `json:"ui_options"`
|
|
|
|
Options []ConfigFieldOption `json:"options,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type ConfigFieldUIOptions struct {
|
|
|
|
Placeholder string `json:"placeholder,omitempty"`
|
|
|
|
Rows string `json:"rows,omitempty"`
|
|
|
|
InputType string `json:"input_type,omitempty"`
|
2023-03-17 17:43:35 +08:00
|
|
|
Label string `json:"label,omitempty"`
|
2023-02-21 17:28:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
type ConfigFieldOption struct {
|
|
|
|
Label string `json:"label"`
|
|
|
|
Value string `json:"value"`
|
2023-01-11 10:02:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
type UpdatePluginConfigReq struct {
|
2023-01-13 12:50:20 +08:00
|
|
|
PluginSlugName string `validate:"required,gt=1,lte=100" json:"plugin_slug_name"`
|
|
|
|
ConfigFields map[string]any `json:"config_fields"`
|
2023-01-11 10:02:45 +08:00
|
|
|
}
|