1
0
Эх сурвалжийг харах

enhance: added info to config editor

0xJacky 1 жил өмнө
parent
commit
ccf548e7b7

+ 3 - 0
frontend/components.d.ts

@@ -76,6 +76,9 @@ declare module '@vue/runtime-core' {
     NginxControlNginxControl: typeof import('./src/components/NginxControl/NginxControl.vue')['default']
     NodeSelectorNodeSelector: typeof import('./src/components/NodeSelector/NodeSelector.vue')['default']
     PageHeaderPageHeader: typeof import('./src/components/PageHeader/PageHeader.vue')['default']
+    RightSettingsDeploy: typeof import('./src/components/RightSettings/Deploy.vue')['default']
+    RightSettingsRightSettings: typeof import('./src/components/RightSettings/RightSettings.vue')['default']
+    RightSettingsSiteDuplicate: typeof import('./src/components/RightSettings/SiteDuplicate.vue')['default']
     RouterLink: typeof import('vue-router')['RouterLink']
     RouterView: typeof import('vue-router')['RouterView']
     SetLanguageSetLanguage: typeof import('./src/components/SetLanguage/SetLanguage.vue')['default']

+ 1 - 0
frontend/src/components/NodeSelector/NodeSelector.vue

@@ -46,6 +46,7 @@ const value = computed({
                 <a-tag color="error" v-else>{{ $gettext('Offline') }}</a-tag>
             </a-col>
         </a-row>
+        <a-empty v-if="hidden_local&&data.length===0"/>
     </a-checkbox-group>
 </template>
 

+ 38 - 4
frontend/src/views/config/ConfigEdit.vue

@@ -9,6 +9,7 @@ import CodeEditor from '@/components/CodeEditor/CodeEditor.vue'
 import ngx from '@/api/ngx'
 import InspectConfig from '@/views/config/InspectConfig.vue'
 import ChatGPT from '@/components/ChatGPT/ChatGPT.vue'
+import {formatDateTime} from '../../lib/helper'
 
 const {$gettext, interpolate} = gettext
 const route = useRoute()
@@ -26,6 +27,8 @@ const name = computed(() => {
 const configText = ref('')
 const history_chatgpt_record = ref([])
 const file_path = ref('')
+const active_key = ref(['1', '2'])
+const modified_at = ref('')
 
 function init() {
     if (name.value) {
@@ -33,6 +36,7 @@ function init() {
             configText.value = r.config
             history_chatgpt_record.value = r.chatgpt_messages
             file_path.value = r.file_path
+            modified_at.value = r.modified_at
         }).catch(r => {
             message.error(r.message ?? $gettext('Server error'))
         })
@@ -90,15 +94,45 @@ function format_code() {
             </a-card>
         </a-col>
 
-        <a-col class="col-right" :xs="24" :sm="24" :md="6">
-            <a-card>
-                <chat-g-p-t :content="configText" :path="file_path"
-                            v-model:history_messages="history_chatgpt_record"/>
+        <a-col :xs="24" :sm="24" :md="6">
+            <a-card class="col-right">
+                <a-collapse v-model:activeKey="active_key" ghost>
+                    <a-collapse-panel key="1" :header="$gettext('Basic')">
+                        <a-form layout="vertical">
+                            <a-form-item :label="$gettext('Path')">
+                                {{ file_path }}
+                            </a-form-item>
+                            <a-form-item :label="$gettext('Updated at')">
+                                {{ formatDateTime(modified_at) }}
+                            </a-form-item>
+                        </a-form>
+                    </a-collapse-panel>
+                    <a-collapse-panel key="2" header="ChatGPT">
+                        <chat-g-p-t :content="configText" :path="file_path"
+                                    v-model:history_messages="history_chatgpt_record"/>
+                    </a-collapse-panel>
+                </a-collapse>
             </a-card>
         </a-col>
     </a-row>
 </template>
 
 <style lang="less" scoped>
+.col-right {
+    position: sticky;
+    top: 78px;
 
+    :deep(.ant-card-body) {
+        max-height: 100vh;
+        overflow-y: scroll;
+    }
+}
+
+:deep(.ant-collapse-ghost > .ant-collapse-item > .ant-collapse-content > .ant-collapse-content-box) {
+    padding: 0;
+}
+
+:deep(.ant-collapse > .ant-collapse-item > .ant-collapse-header) {
+    padding: 0 0 10px 0;
+}
 </style>

+ 1 - 1
frontend/src/views/domain/components/RightSettings.vue

@@ -19,7 +19,7 @@ const history_chatgpt_record = inject('history_chatgpt_record')
 const filename = inject('filename')
 const data: any = inject('data')
 
-const active_key = ref('1')
+const active_key = ref(['1', '2', '3'])
 
 function enable() {
     domain.enable(name.value).then(() => {

+ 13 - 0
server/api/config.go

@@ -6,6 +6,7 @@ import (
 	"github.com/0xJacky/Nginx-UI/server/internal/nginx"
 	"github.com/0xJacky/Nginx-UI/server/query"
 	"github.com/gin-gonic/gin"
+	"github.com/sashabaranov/go-openai"
 	"net/http"
 	"os"
 )
@@ -78,6 +79,13 @@ func GetConfig(c *gin.Context) {
 	name := c.Param("name")
 	path := nginx.GetConfPath("/", name)
 
+	stat, err := os.Stat(path)
+
+	if err != nil {
+		ErrHandler(c, err)
+		return
+	}
+
 	content, err := os.ReadFile(path)
 
 	if err != nil {
@@ -93,10 +101,15 @@ func GetConfig(c *gin.Context) {
 		return
 	}
 
+	if chatgpt.Content == nil {
+		chatgpt.Content = make([]openai.ChatCompletionMessage, 0)
+	}
+
 	c.JSON(http.StatusOK, gin.H{
 		"config":           string(content),
 		"chatgpt_messages": chatgpt.Content,
 		"file_path":        path,
+		"modified_at":      stat.ModTime(),
 	})
 
 }

+ 17 - 16
server/model/chatgpt_log.go

@@ -1,34 +1,35 @@
 package model
 
 import (
-	"database/sql/driver"
-	"encoding/json"
-	"fmt"
-	"github.com/pkg/errors"
-	"github.com/sashabaranov/go-openai"
+    "database/sql/driver"
+    "encoding/json"
+    "fmt"
+    "github.com/pkg/errors"
+    "github.com/sashabaranov/go-openai"
 )
 
 type JSON []openai.ChatCompletionMessage
 
 // Scan scan value into Jsonb, implements sql.Scanner interface
 func (j *JSON) Scan(value interface{}) error {
-	bytes, ok := value.([]byte)
-	if !ok {
-		return errors.New(fmt.Sprint("Failed to unmarshal JSONB value:", value))
-	}
+    bytes, ok := value.([]byte)
+    if !ok {
+        return errors.New(fmt.Sprint("Failed to unmarshal JSONB value:", value))
+    }
 
-	result := make([]openai.ChatCompletionMessage, 0)
-	err := json.Unmarshal(bytes, &result)
-	*j = result
-	return err
+    result := make([]openai.ChatCompletionMessage, 0)
+    err := json.Unmarshal(bytes, &result)
+    *j = result
+
+    return err
 }
 
 // Value return json value, implement driver.Valuer interface
 func (j *JSON) Value() (driver.Value, error) {
-	return json.Marshal(*j)
+    return json.Marshal(*j)
 }
 
 type ChatGPTLog struct {
-	Name    string `json:"name"`
-	Content JSON   `json:"content" gorm:"serializer:json"`
+    Name    string `json:"name"`
+    Content JSON   `json:"content" gorm:"serializer:json"`
 }