mirror of
				https://github.com/yangjian102621/geekai.git
				synced 2025-11-04 16:23:42 +08:00 
			
		
		
		
	完成前后端框架搭建,完成聊天页面布局
This commit is contained in:
		
							
								
								
									
										25
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,25 @@
 | 
			
		||||
# Logs
 | 
			
		||||
logs
 | 
			
		||||
*.log
 | 
			
		||||
npm-debug.log*
 | 
			
		||||
yarn-debug.log*
 | 
			
		||||
yarn-error.log*
 | 
			
		||||
pnpm-debug.log*
 | 
			
		||||
lerna-debug.log*
 | 
			
		||||
 | 
			
		||||
node_modules
 | 
			
		||||
dist
 | 
			
		||||
dist-ssr
 | 
			
		||||
*.local
 | 
			
		||||
 | 
			
		||||
# Editor directories and files
 | 
			
		||||
.vscode/*
 | 
			
		||||
!.vscode/extensions.json
 | 
			
		||||
.idea
 | 
			
		||||
.DS_Store
 | 
			
		||||
*.suo
 | 
			
		||||
*.ntvs*
 | 
			
		||||
*.njsproj
 | 
			
		||||
*.sln
 | 
			
		||||
*.sw?
 | 
			
		||||
tmp
 | 
			
		||||
							
								
								
									
										14
									
								
								fresh.conf
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								fresh.conf
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,14 @@
 | 
			
		||||
root:              .
 | 
			
		||||
tmp_path:          ./tmp
 | 
			
		||||
build_name:        runner-build
 | 
			
		||||
build_log:         runner-build-errors.log
 | 
			
		||||
valid_ext:         .go, .tpl, .tmpl, .html
 | 
			
		||||
no_rebuild_ext:    .tpl, .tmpl, .html, .js, .vue
 | 
			
		||||
ignored:           assets, tmp, web
 | 
			
		||||
build_delay:       600
 | 
			
		||||
colors:            1
 | 
			
		||||
log_color_main:    cyan
 | 
			
		||||
log_color_build:   yellow
 | 
			
		||||
log_color_runner:  green
 | 
			
		||||
log_color_watcher: magenta
 | 
			
		||||
log_color_app:
 | 
			
		||||
							
								
								
									
										34
									
								
								go.mod
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								go.mod
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,34 @@
 | 
			
		||||
module openai
 | 
			
		||||
 | 
			
		||||
go 1.19
 | 
			
		||||
 | 
			
		||||
require (
 | 
			
		||||
	github.com/BurntSushi/toml v1.1.0
 | 
			
		||||
	github.com/gin-contrib/sessions v0.0.5
 | 
			
		||||
	github.com/gin-gonic/gin v1.7.7
 | 
			
		||||
	github.com/gorilla/websocket v1.5.0
 | 
			
		||||
	github.com/mitchellh/go-homedir v1.1.0
 | 
			
		||||
	go.uber.org/zap v1.21.0
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
require (
 | 
			
		||||
	github.com/gin-contrib/sse v0.1.0 // indirect
 | 
			
		||||
	github.com/go-playground/locales v0.13.0 // indirect
 | 
			
		||||
	github.com/go-playground/universal-translator v0.17.0 // indirect
 | 
			
		||||
	github.com/go-playground/validator/v10 v10.4.1 // indirect
 | 
			
		||||
	github.com/golang/protobuf v1.3.3 // indirect
 | 
			
		||||
	github.com/gorilla/context v1.1.1 // indirect
 | 
			
		||||
	github.com/gorilla/securecookie v1.1.1 // indirect
 | 
			
		||||
	github.com/gorilla/sessions v1.2.1 // indirect
 | 
			
		||||
	github.com/json-iterator/go v1.1.9 // indirect
 | 
			
		||||
	github.com/leodido/go-urn v1.2.0 // indirect
 | 
			
		||||
	github.com/mattn/go-isatty v0.0.12 // indirect
 | 
			
		||||
	github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
 | 
			
		||||
	github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 // indirect
 | 
			
		||||
	github.com/ugorji/go/codec v1.1.7 // indirect
 | 
			
		||||
	go.uber.org/atomic v1.7.0 // indirect
 | 
			
		||||
	go.uber.org/multierr v1.6.0 // indirect
 | 
			
		||||
	golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83 // indirect
 | 
			
		||||
	golang.org/x/sys v0.0.0-20220408201424-a24fb2fb8a0f // indirect
 | 
			
		||||
	gopkg.in/yaml.v2 v2.2.8 // indirect
 | 
			
		||||
)
 | 
			
		||||
							
								
								
									
										113
									
								
								go.sum
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										113
									
								
								go.sum
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,113 @@
 | 
			
		||||
github.com/BurntSushi/toml v1.1.0 h1:ksErzDEI1khOiGPgpwuI7x2ebx/uXQNw7xJpn9Eq1+I=
 | 
			
		||||
github.com/BurntSushi/toml v1.1.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
 | 
			
		||||
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
 | 
			
		||||
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
 | 
			
		||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
 | 
			
		||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
 | 
			
		||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
 | 
			
		||||
github.com/gin-contrib/sessions v0.0.5 h1:CATtfHmLMQrMNpJRgzjWXD7worTh7g7ritsQfmF+0jE=
 | 
			
		||||
github.com/gin-contrib/sessions v0.0.5/go.mod h1:vYAuaUPqie3WUSsft6HUlCjlwwoJQs97miaG2+7neKY=
 | 
			
		||||
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
 | 
			
		||||
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
 | 
			
		||||
github.com/gin-gonic/gin v1.7.7 h1:3DoBmSbJbZAWqXJC3SLjAPfutPJJRN1U5pALB7EeTTs=
 | 
			
		||||
github.com/gin-gonic/gin v1.7.7/go.mod h1:axIBovoeJpVj8S3BwE0uPMTeReE4+AfFtqpqaZ1qq1U=
 | 
			
		||||
github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A=
 | 
			
		||||
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
 | 
			
		||||
github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q=
 | 
			
		||||
github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8=
 | 
			
		||||
github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no=
 | 
			
		||||
github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA=
 | 
			
		||||
github.com/go-playground/validator/v10 v10.4.1 h1:pH2c5ADXtd66mxoE0Zm9SUhxE20r7aM3F26W0hOn+GE=
 | 
			
		||||
github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4=
 | 
			
		||||
github.com/golang/protobuf v1.3.3 h1:gyjaxf+svBWX08ZjK86iN9geUJF0H6gp2IRKX6Nf6/I=
 | 
			
		||||
github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
 | 
			
		||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
 | 
			
		||||
github.com/gorilla/context v1.1.1 h1:AWwleXJkX/nhcU9bZSnZoi3h/qGYqQAGhq6zZe/aQW8=
 | 
			
		||||
github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg=
 | 
			
		||||
github.com/gorilla/securecookie v1.1.1 h1:miw7JPhV+b/lAHSXz4qd/nN9jRiAFV5FwjeKyCS8BvQ=
 | 
			
		||||
github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4=
 | 
			
		||||
github.com/gorilla/sessions v1.2.1 h1:DHd3rPN5lE3Ts3D8rKkQ8x/0kqfeNmBAaiSi+o7FsgI=
 | 
			
		||||
github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM=
 | 
			
		||||
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
 | 
			
		||||
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
 | 
			
		||||
github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns=
 | 
			
		||||
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
 | 
			
		||||
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
 | 
			
		||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
 | 
			
		||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
 | 
			
		||||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
 | 
			
		||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
 | 
			
		||||
github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y=
 | 
			
		||||
github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
 | 
			
		||||
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
 | 
			
		||||
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
 | 
			
		||||
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
 | 
			
		||||
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
 | 
			
		||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
 | 
			
		||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
 | 
			
		||||
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg=
 | 
			
		||||
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
 | 
			
		||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
 | 
			
		||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
 | 
			
		||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
 | 
			
		||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
 | 
			
		||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
 | 
			
		||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
 | 
			
		||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
 | 
			
		||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
 | 
			
		||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
 | 
			
		||||
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
 | 
			
		||||
github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs=
 | 
			
		||||
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
 | 
			
		||||
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
 | 
			
		||||
go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
 | 
			
		||||
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
 | 
			
		||||
go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI=
 | 
			
		||||
go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
 | 
			
		||||
go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4=
 | 
			
		||||
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
 | 
			
		||||
go.uber.org/zap v1.21.0 h1:WefMeulhovoZ2sYXz7st6K0sLj7bBhpiFaud4r4zST8=
 | 
			
		||||
go.uber.org/zap v1.21.0/go.mod h1:wjWOCqI0f2ZZrJF/UufIOkiC8ii6tm1iqIsLo76RfJw=
 | 
			
		||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
 | 
			
		||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
 | 
			
		||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
 | 
			
		||||
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83 h1:/ZScEX8SfEmUGRHs0gxpqteO5nfNW6axyZbBdw9A12g=
 | 
			
		||||
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
 | 
			
		||||
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
 | 
			
		||||
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
 | 
			
		||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
 | 
			
		||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
 | 
			
		||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
 | 
			
		||||
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
 | 
			
		||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 | 
			
		||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 | 
			
		||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
 | 
			
		||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 | 
			
		||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 | 
			
		||||
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 | 
			
		||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 | 
			
		||||
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 | 
			
		||||
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 | 
			
		||||
golang.org/x/sys v0.0.0-20220408201424-a24fb2fb8a0f h1:8w7RhxzTVgUzw/AH/9mUV5q0vMgy40SQRursCcfmkCw=
 | 
			
		||||
golang.org/x/sys v0.0.0-20220408201424-a24fb2fb8a0f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 | 
			
		||||
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
 | 
			
		||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
 | 
			
		||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
 | 
			
		||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
 | 
			
		||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
 | 
			
		||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
 | 
			
		||||
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
 | 
			
		||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
 | 
			
		||||
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
 | 
			
		||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
 | 
			
		||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
 | 
			
		||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
 | 
			
		||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
 | 
			
		||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
 | 
			
		||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
 | 
			
		||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
 | 
			
		||||
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
 | 
			
		||||
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
 | 
			
		||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
 | 
			
		||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
 | 
			
		||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
 | 
			
		||||
							
								
								
									
										24
									
								
								logger/logger.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								logger/logger.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,24 @@
 | 
			
		||||
package logger
 | 
			
		||||
 | 
			
		||||
import "go.uber.org/zap"
 | 
			
		||||
 | 
			
		||||
var logger *zap.SugaredLogger
 | 
			
		||||
 | 
			
		||||
func GetLogger() *zap.SugaredLogger {
 | 
			
		||||
	if logger != nil {
 | 
			
		||||
		return logger
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	logLevel := zap.NewAtomicLevel()
 | 
			
		||||
	logLevel.SetLevel(zap.InfoLevel)
 | 
			
		||||
	log, _ := zap.Config{
 | 
			
		||||
		Level:            logLevel,
 | 
			
		||||
		Development:      false,
 | 
			
		||||
		Encoding:         "console",
 | 
			
		||||
		EncoderConfig:    zap.NewDevelopmentEncoderConfig(),
 | 
			
		||||
		OutputPaths:      []string{"stderr"},
 | 
			
		||||
		ErrorOutputPaths: []string{"stderr"},
 | 
			
		||||
	}.Build()
 | 
			
		||||
	logger = log.Sugar()
 | 
			
		||||
	return logger
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										46
									
								
								main.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								main.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,46 @@
 | 
			
		||||
package main
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"embed"
 | 
			
		||||
	"github.com/mitchellh/go-homedir"
 | 
			
		||||
	logger2 "openai/logger"
 | 
			
		||||
	"openai/server"
 | 
			
		||||
	config2 "openai/types"
 | 
			
		||||
	"os"
 | 
			
		||||
	"path/filepath"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var logger = logger2.GetLogger()
 | 
			
		||||
 | 
			
		||||
//go:embed web
 | 
			
		||||
var webRoot embed.FS
 | 
			
		||||
 | 
			
		||||
func main() {
 | 
			
		||||
	defer func() {
 | 
			
		||||
		if err := recover(); err != nil {
 | 
			
		||||
			logger.Error(err)
 | 
			
		||||
		}
 | 
			
		||||
	}()
 | 
			
		||||
 | 
			
		||||
	// create config dir
 | 
			
		||||
	configDir, _ := homedir.Expand("~/.config/chat-gpt")
 | 
			
		||||
	_, err := os.Stat(configDir)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		err := os.MkdirAll(configDir, 0755)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			logger.Error(err)
 | 
			
		||||
			return
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// load service configs
 | 
			
		||||
	config, err := config2.LoadConfig(filepath.Join(configDir, "/config.toml"))
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		logger.Errorf("failed to load web types: %v", err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// start server
 | 
			
		||||
	s := server.NewServer(config)
 | 
			
		||||
	s.Run(webRoot, "web")
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										11
									
								
								server/chat_handler.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								server/chat_handler.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,11 @@
 | 
			
		||||
package server
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"github.com/gin-gonic/gin"
 | 
			
		||||
	"net/http"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func (s *Server) Chat(c *gin.Context) {
 | 
			
		||||
	c.JSON(http.StatusOK, gin.H{"code": 0, "message": fmt.Sprintf("HELLO, ChatGPT !!!")})
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										65
									
								
								server/client.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										65
									
								
								server/client.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,65 @@
 | 
			
		||||
package server
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"errors"
 | 
			
		||||
	"github.com/gorilla/websocket"
 | 
			
		||||
	"sync"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var ErrConClosed = errors.New("connection closed")
 | 
			
		||||
 | 
			
		||||
type Client interface {
 | 
			
		||||
	Close()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// WsClient websocket client
 | 
			
		||||
type WsClient struct {
 | 
			
		||||
	NodeId    string
 | 
			
		||||
	SessionId string
 | 
			
		||||
	Conn      *websocket.Conn
 | 
			
		||||
	lock      sync.Mutex
 | 
			
		||||
	mt        int
 | 
			
		||||
	closed    bool
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func NewWsClient(nodeId string, sessionId string, conn *websocket.Conn) *WsClient {
 | 
			
		||||
	return &WsClient{
 | 
			
		||||
		NodeId:    nodeId,
 | 
			
		||||
		SessionId: sessionId,
 | 
			
		||||
		Conn:      conn,
 | 
			
		||||
		lock:      sync.Mutex{},
 | 
			
		||||
		mt:        2, // fixed bug for 'Invalid UTF-8 in text frame'
 | 
			
		||||
		closed:    false,
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (wc *WsClient) Send(message []byte) error {
 | 
			
		||||
	wc.lock.Lock()
 | 
			
		||||
	defer wc.lock.Unlock()
 | 
			
		||||
 | 
			
		||||
	if wc.closed {
 | 
			
		||||
		return ErrConClosed
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return wc.Conn.WriteMessage(wc.mt, message)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (wc *WsClient) Receive() (int, []byte, error) {
 | 
			
		||||
	if wc.closed {
 | 
			
		||||
		return 0, nil, ErrConClosed
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return wc.Conn.ReadMessage()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (wc *WsClient) Close() {
 | 
			
		||||
	wc.lock.Lock()
 | 
			
		||||
	defer wc.lock.Unlock()
 | 
			
		||||
 | 
			
		||||
	if wc.closed {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	_ = wc.Conn.Close()
 | 
			
		||||
	wc.closed = true
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										137
									
								
								server/server.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										137
									
								
								server/server.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,137 @@
 | 
			
		||||
package server
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"embed"
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"github.com/gin-contrib/sessions"
 | 
			
		||||
	"github.com/gin-contrib/sessions/cookie"
 | 
			
		||||
	"github.com/gin-gonic/gin"
 | 
			
		||||
	"io/fs"
 | 
			
		||||
	"log"
 | 
			
		||||
	"net/http"
 | 
			
		||||
	logger2 "openai/logger"
 | 
			
		||||
	"openai/types"
 | 
			
		||||
	"os"
 | 
			
		||||
	"path/filepath"
 | 
			
		||||
	"strings"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var logger = logger2.GetLogger()
 | 
			
		||||
 | 
			
		||||
type StaticFile struct {
 | 
			
		||||
	embedFS embed.FS
 | 
			
		||||
	path    string
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (s StaticFile) Open(name string) (fs.File, error) {
 | 
			
		||||
	filename := filepath.Join(s.path, strings.TrimLeft(name, "/"))
 | 
			
		||||
	file, err := s.embedFS.Open(filename)
 | 
			
		||||
	return file, err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type Server struct {
 | 
			
		||||
	Config *types.Config
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func NewServer(config *types.Config) *Server {
 | 
			
		||||
	return &Server{Config: config}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (s *Server) Run(webRoot embed.FS, path string) {
 | 
			
		||||
	gin.SetMode(gin.DebugMode)
 | 
			
		||||
	engine := gin.Default()
 | 
			
		||||
	engine.Use(sessionMiddleware(s.Config))
 | 
			
		||||
	engine.Use(corsMiddleware())
 | 
			
		||||
	engine.Use(AuthorizeMiddleware())
 | 
			
		||||
 | 
			
		||||
	engine.GET("/hello", Hello)
 | 
			
		||||
	engine.Any("/api/chat", s.Chat)
 | 
			
		||||
 | 
			
		||||
	// process front-end web static files
 | 
			
		||||
	engine.StaticFS("/chat", http.FS(StaticFile{
 | 
			
		||||
		embedFS: webRoot,
 | 
			
		||||
		path:    path,
 | 
			
		||||
	}))
 | 
			
		||||
 | 
			
		||||
	logger.Infof("http://%s", s.Config.Listen)
 | 
			
		||||
	err := engine.Run(s.Config.Listen)
 | 
			
		||||
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		logger.Error("Fail to start server:", err.Error())
 | 
			
		||||
		os.Exit(1)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func sessionMiddleware(config *types.Config) gin.HandlerFunc {
 | 
			
		||||
	// encrypt the cookie
 | 
			
		||||
	store := cookie.NewStore([]byte(config.Session.SecretKey))
 | 
			
		||||
	store.Options(sessions.Options{
 | 
			
		||||
		Path:     config.Session.Path,
 | 
			
		||||
		Domain:   config.Session.Domain,
 | 
			
		||||
		MaxAge:   config.Session.MaxAge,
 | 
			
		||||
		Secure:   config.Session.Secure,
 | 
			
		||||
		HttpOnly: config.Session.HttpOnly,
 | 
			
		||||
		SameSite: config.Session.SameSite,
 | 
			
		||||
	})
 | 
			
		||||
	return sessions.Sessions(config.Session.Name, store)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 跨域中间件设置
 | 
			
		||||
func corsMiddleware() gin.HandlerFunc {
 | 
			
		||||
	return func(c *gin.Context) {
 | 
			
		||||
		method := c.Request.Method
 | 
			
		||||
		origin := c.Request.Header.Get("Origin")
 | 
			
		||||
		if origin != "" {
 | 
			
		||||
			// 设置允许的请求源
 | 
			
		||||
			c.Writer.Header().Set("Access-Control-Allow-Origin", origin)
 | 
			
		||||
			c.Header("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE, UPDATE")
 | 
			
		||||
			//允许跨域设置可以返回其他子段,可以自定义字段
 | 
			
		||||
			c.Header("Access-Control-Allow-Headers", "Authorization, Content-Length, Content-Type, Session-Name, Session")
 | 
			
		||||
			// 允许浏览器(客户端)可以解析的头部 (重要)
 | 
			
		||||
			c.Header("Access-Control-Expose-Headers", "Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers")
 | 
			
		||||
			//设置缓存时间
 | 
			
		||||
			c.Header("Access-Control-Max-Age", "172800")
 | 
			
		||||
			//允许客户端传递校验信息比如 cookie (重要)
 | 
			
		||||
			c.Header("Access-Control-Allow-Credentials", "true")
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if method == http.MethodOptions {
 | 
			
		||||
			c.JSON(http.StatusOK, "ok!")
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		defer func() {
 | 
			
		||||
			if err := recover(); err != nil {
 | 
			
		||||
				log.Printf("Panic info is: %v", err)
 | 
			
		||||
			}
 | 
			
		||||
		}()
 | 
			
		||||
 | 
			
		||||
		c.Next()
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// AuthorizeMiddleware 用户授权验证
 | 
			
		||||
func AuthorizeMiddleware() gin.HandlerFunc {
 | 
			
		||||
	return func(c *gin.Context) {
 | 
			
		||||
		c.Next()
 | 
			
		||||
		//if c.Request.URL.Path == "/login" {
 | 
			
		||||
		//	c.Next()
 | 
			
		||||
		//	return
 | 
			
		||||
		//}
 | 
			
		||||
 | 
			
		||||
		//sessionName := c.GetHeader("Session-Name")
 | 
			
		||||
		//session, err := c.Cookie(sessionName)
 | 
			
		||||
		//if err == nil {
 | 
			
		||||
		//	c.Request.Header.Set(utils.SessionKey, session)
 | 
			
		||||
		//	c.Next()
 | 
			
		||||
		//} else {
 | 
			
		||||
		//	logger.Fatal(err)
 | 
			
		||||
		//	c.Abort()
 | 
			
		||||
		//	c.JSON(http.StatusUnauthorized, "No session data found")
 | 
			
		||||
		//}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func Hello(c *gin.Context) {
 | 
			
		||||
	c.JSON(http.StatusOK, gin.H{"code": 0, "message": fmt.Sprintf("HELLO, XWEBSSH !!!")})
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										85
									
								
								types/config.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										85
									
								
								types/config.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,85 @@
 | 
			
		||||
package types
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"bytes"
 | 
			
		||||
	"github.com/BurntSushi/toml"
 | 
			
		||||
	"net/http"
 | 
			
		||||
	"openai/utils"
 | 
			
		||||
	"os"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type Config struct {
 | 
			
		||||
	Listen  string
 | 
			
		||||
	Session Session
 | 
			
		||||
	OpenAi  OpenAi
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// OpenAi configs struct
 | 
			
		||||
type OpenAi struct {
 | 
			
		||||
	ApiKey      string
 | 
			
		||||
	Model       string
 | 
			
		||||
	Temperature float32
 | 
			
		||||
	MaxTokens   int
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Session configs struct
 | 
			
		||||
type Session struct {
 | 
			
		||||
	SecretKey string // session encryption key
 | 
			
		||||
	Name      string
 | 
			
		||||
	Path      string
 | 
			
		||||
	Domain    string
 | 
			
		||||
	MaxAge    int
 | 
			
		||||
	Secure    bool
 | 
			
		||||
	HttpOnly  bool
 | 
			
		||||
	SameSite  http.SameSite
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func NewDefaultConfig() *Config {
 | 
			
		||||
	return &Config{
 | 
			
		||||
		Listen: "0.0.0.0:5678",
 | 
			
		||||
 | 
			
		||||
		Session: Session{
 | 
			
		||||
			SecretKey: utils.RandString(64),
 | 
			
		||||
			Name:      "CHAT_GPT_SESSION_ID",
 | 
			
		||||
			Domain:    "",
 | 
			
		||||
			Path:      "/",
 | 
			
		||||
			MaxAge:    86400,
 | 
			
		||||
			Secure:    false,
 | 
			
		||||
			HttpOnly:  false,
 | 
			
		||||
			SameSite:  http.SameSiteLaxMode,
 | 
			
		||||
		},
 | 
			
		||||
		OpenAi: OpenAi{
 | 
			
		||||
			Model:       "gpt-3.5-turbo",
 | 
			
		||||
			MaxTokens:   1024,
 | 
			
		||||
			Temperature: 1.0,
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func LoadConfig(configFile string) (*Config, error) {
 | 
			
		||||
	var config *Config
 | 
			
		||||
	_, err := os.Stat(configFile)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		config = NewDefaultConfig()
 | 
			
		||||
		// generate types file
 | 
			
		||||
		buf := new(bytes.Buffer)
 | 
			
		||||
		encoder := toml.NewEncoder(buf)
 | 
			
		||||
 | 
			
		||||
		if err := encoder.Encode(&config); err != nil {
 | 
			
		||||
			return nil, err
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		err := os.WriteFile(configFile, buf.Bytes(), 0644)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return nil, err
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		return config, nil
 | 
			
		||||
	}
 | 
			
		||||
	_, err = toml.DecodeFile(configFile, &config)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return config, err
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										49
									
								
								types/types.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										49
									
								
								types/types.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,49 @@
 | 
			
		||||
package types
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"sync"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type LockedMap struct {
 | 
			
		||||
	lock sync.RWMutex
 | 
			
		||||
	data map[string]interface{}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func NewLockedMap() *LockedMap {
 | 
			
		||||
	return &LockedMap{
 | 
			
		||||
		lock: sync.RWMutex{},
 | 
			
		||||
		data: make(map[string]interface{}),
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m *LockedMap) Put(key string, value interface{}) {
 | 
			
		||||
	m.lock.Lock()
 | 
			
		||||
	defer m.lock.Unlock()
 | 
			
		||||
 | 
			
		||||
	m.data[key] = value
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m *LockedMap) Get(key string) interface{} {
 | 
			
		||||
	m.lock.RLock()
 | 
			
		||||
	defer m.lock.RUnlock()
 | 
			
		||||
 | 
			
		||||
	return m.data[key]
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m *LockedMap) Delete(key string) {
 | 
			
		||||
	m.lock.Lock()
 | 
			
		||||
	defer m.lock.Unlock()
 | 
			
		||||
 | 
			
		||||
	delete(m.data, key)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m *LockedMap) ToList() []interface{} {
 | 
			
		||||
	m.lock.Lock()
 | 
			
		||||
	defer m.lock.Unlock()
 | 
			
		||||
 | 
			
		||||
	var s = make([]interface{}, 0)
 | 
			
		||||
	for _, v := range m.data {
 | 
			
		||||
		s = append(s, v)
 | 
			
		||||
	}
 | 
			
		||||
	return s
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										32
									
								
								utils/utils.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								utils/utils.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,32 @@
 | 
			
		||||
package utils
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"math/rand"
 | 
			
		||||
	"strconv"
 | 
			
		||||
	"strings"
 | 
			
		||||
	"time"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// RandString generate rand string with specified length
 | 
			
		||||
func RandString(length int) string {
 | 
			
		||||
	str := "0123456789abcdefghijklmnopqrstuvwxyz"
 | 
			
		||||
	data := []byte(str)
 | 
			
		||||
	var result []byte
 | 
			
		||||
	r := rand.New(rand.NewSource(time.Now().UnixNano()))
 | 
			
		||||
	for i := 0; i < length; i++ {
 | 
			
		||||
		result = append(result, data[r.Intn(len(data))])
 | 
			
		||||
	}
 | 
			
		||||
	return string(result)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func Long2IP(ipInt int64) string {
 | 
			
		||||
	b0 := strconv.FormatInt((ipInt>>24)&0xff, 10)
 | 
			
		||||
	b1 := strconv.FormatInt((ipInt>>16)&0xff, 10)
 | 
			
		||||
	b2 := strconv.FormatInt((ipInt>>8)&0xff, 10)
 | 
			
		||||
	b3 := strconv.FormatInt(ipInt&0xff, 10)
 | 
			
		||||
	return b0 + "." + b1 + "." + b2 + "." + b3
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func IsBlank(value string) bool {
 | 
			
		||||
	return len(strings.TrimSpace(value)) == 0
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										1
									
								
								web/.env.development
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								web/.env.development
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1 @@
 | 
			
		||||
VUE_APP_API_HOST=127.0.0.1:5678
 | 
			
		||||
							
								
								
									
										1
									
								
								web/.env.production
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								web/.env.production
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1 @@
 | 
			
		||||
VUE_APP_WS_HOST=ws://127.0.0.1:5678
 | 
			
		||||
							
								
								
									
										21
									
								
								web/README.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								web/README.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,21 @@
 | 
			
		||||
# qark-webssh
 | 
			
		||||
 | 
			
		||||
## Project setup
 | 
			
		||||
```
 | 
			
		||||
npm install
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
### Compiles and hot-reloads for development
 | 
			
		||||
```
 | 
			
		||||
npm run serve
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
### Compiles and minifies for production
 | 
			
		||||
```
 | 
			
		||||
npm run build
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
### Lints and fixes files
 | 
			
		||||
```
 | 
			
		||||
npm run lint
 | 
			
		||||
```
 | 
			
		||||
							
								
								
									
										5
									
								
								web/babel.config.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								web/babel.config.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,5 @@
 | 
			
		||||
module.exports = {
 | 
			
		||||
  presets: [
 | 
			
		||||
    '@vue/cli-plugin-babel/preset'
 | 
			
		||||
  ]
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										20
									
								
								web/index.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								web/index.html
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,20 @@
 | 
			
		||||
<!DOCTYPE html>
 | 
			
		||||
<html lang="zh-cn">
 | 
			
		||||
 | 
			
		||||
<head>
 | 
			
		||||
    <meta charset="utf-8">
 | 
			
		||||
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
 | 
			
		||||
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
 | 
			
		||||
    <link rel="icon" href="favicon.ico">
 | 
			
		||||
    <title>ChatGPT 助手</title>
 | 
			
		||||
</head>
 | 
			
		||||
 | 
			
		||||
<body>
 | 
			
		||||
<noscript>
 | 
			
		||||
    <strong>请开启JavaScript支持</strong>
 | 
			
		||||
</noscript>
 | 
			
		||||
<div id="app"></div>
 | 
			
		||||
<script type="module" src="src/main.js"></script>
 | 
			
		||||
</body>
 | 
			
		||||
 | 
			
		||||
</html>
 | 
			
		||||
							
								
								
									
										20
									
								
								web/jsconfig.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								web/jsconfig.json
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,20 @@
 | 
			
		||||
{
 | 
			
		||||
  "compilerOptions": {
 | 
			
		||||
    "target": "es5",
 | 
			
		||||
    "module": "esnext",
 | 
			
		||||
    "baseUrl": "./",
 | 
			
		||||
    "jsx": "preserve",
 | 
			
		||||
    "moduleResolution": "node",
 | 
			
		||||
    "paths": {
 | 
			
		||||
      "@/*": [
 | 
			
		||||
        "src/*"
 | 
			
		||||
      ]
 | 
			
		||||
    },
 | 
			
		||||
    "lib": [
 | 
			
		||||
      "esnext",
 | 
			
		||||
      "dom",
 | 
			
		||||
      "dom.iterable",
 | 
			
		||||
      "scripthost"
 | 
			
		||||
    ]
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										19700
									
								
								web/package-lock.json
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										19700
									
								
								web/package-lock.json
									
									
									
										generated
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										50
									
								
								web/package.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										50
									
								
								web/package.json
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,50 @@
 | 
			
		||||
{
 | 
			
		||||
  "name": "yycloud-webssh",
 | 
			
		||||
  "version": "0.1.0",
 | 
			
		||||
  "private": true,
 | 
			
		||||
  "scripts": {
 | 
			
		||||
    "dev": "vue-cli-service serve",
 | 
			
		||||
    "build": "vue-cli-service build",
 | 
			
		||||
    "lint": "vue-cli-service lint"
 | 
			
		||||
  },
 | 
			
		||||
  "dependencies": {
 | 
			
		||||
    "axios": "^0.27.2",
 | 
			
		||||
    "core-js": "^3.8.3",
 | 
			
		||||
    "element-plus": "^2.1.11",
 | 
			
		||||
    "good-storage": "^1.1.1",
 | 
			
		||||
    "json-bigint": "^1.0.0",
 | 
			
		||||
    "vue": "^3.2.13",
 | 
			
		||||
    "vue-router": "^4.0.15"
 | 
			
		||||
  },
 | 
			
		||||
  "devDependencies": {
 | 
			
		||||
    "@babel/core": "^7.12.16",
 | 
			
		||||
    "@babel/eslint-parser": "^7.12.16",
 | 
			
		||||
    "@vue/cli-plugin-babel": "~5.0.0",
 | 
			
		||||
    "@vue/cli-plugin-eslint": "~5.0.0",
 | 
			
		||||
    "@vue/cli-service": "~5.0.0",
 | 
			
		||||
    "eslint": "^7.32.0",
 | 
			
		||||
    "eslint-plugin-vue": "^8.0.3",
 | 
			
		||||
    "stylus": "^0.58.1",
 | 
			
		||||
    "stylus-loader": "^7.0.0"
 | 
			
		||||
  },
 | 
			
		||||
  "eslintConfig": {
 | 
			
		||||
    "root": true,
 | 
			
		||||
    "env": {
 | 
			
		||||
      "node": true
 | 
			
		||||
    },
 | 
			
		||||
    "extends": [
 | 
			
		||||
      "plugin:vue/vue3-essential",
 | 
			
		||||
      "eslint:recommended"
 | 
			
		||||
    ],
 | 
			
		||||
    "parserOptions": {
 | 
			
		||||
      "parser": "@babel/eslint-parser"
 | 
			
		||||
    },
 | 
			
		||||
    "rules": {}
 | 
			
		||||
  },
 | 
			
		||||
  "browserslist": [
 | 
			
		||||
    "> 1%",
 | 
			
		||||
    "last 2 versions",
 | 
			
		||||
    "not dead",
 | 
			
		||||
    "not ie 11"
 | 
			
		||||
  ]
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										
											BIN
										
									
								
								web/public/favicon.ico
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								web/public/favicon.ico
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 4.2 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								web/public/images/gpt-icon.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								web/public/images/gpt-icon.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 3.5 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								web/public/images/user-icon.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								web/public/images/user-icon.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 24 KiB  | 
							
								
								
									
										28
									
								
								web/src/App.vue
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								web/src/App.vue
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,28 @@
 | 
			
		||||
<template>
 | 
			
		||||
  <router-view></router-view>
 | 
			
		||||
</template>
 | 
			
		||||
 | 
			
		||||
<script>
 | 
			
		||||
import { defineComponent } from 'vue'
 | 
			
		||||
 | 
			
		||||
export default defineComponent({
 | 
			
		||||
  setup () {
 | 
			
		||||
    // TODO: 获取会话
 | 
			
		||||
  },
 | 
			
		||||
})
 | 
			
		||||
</script>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
<style lang="stylus">
 | 
			
		||||
html, body {
 | 
			
		||||
  height: 100%;
 | 
			
		||||
  margin: 0;
 | 
			
		||||
  padding: 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#app {
 | 
			
		||||
  margin: 0 !important;
 | 
			
		||||
  padding: 0 !important;
 | 
			
		||||
  font-family: 'Helvetica Neue', Helvetica, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', '微软雅黑', Arial, sans-serif;
 | 
			
		||||
}
 | 
			
		||||
</style>
 | 
			
		||||
							
								
								
									
										3
									
								
								web/src/actions/chat.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								web/src/actions/chat.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,3 @@
 | 
			
		||||
/**
 | 
			
		||||
 * actions for chat page
 | 
			
		||||
 */
 | 
			
		||||
							
								
								
									
										69
									
								
								web/src/components/ChatPrompt.vue
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										69
									
								
								web/src/components/ChatPrompt.vue
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,69 @@
 | 
			
		||||
<template>
 | 
			
		||||
  <div class="chat-line chat-line-right">
 | 
			
		||||
    <div class="chat-item">
 | 
			
		||||
      <span class="content">{{ content }}</span>
 | 
			
		||||
      <div class="triangle"></div>
 | 
			
		||||
    </div>
 | 
			
		||||
 | 
			
		||||
    <div class="chat-icon">
 | 
			
		||||
      <img :src="icon" alt="User"/>
 | 
			
		||||
    </div>
 | 
			
		||||
  </div>
 | 
			
		||||
</template>
 | 
			
		||||
 | 
			
		||||
<script>
 | 
			
		||||
import {defineComponent} from "vue"
 | 
			
		||||
 | 
			
		||||
export default defineComponent({
 | 
			
		||||
  name: 'ChatPrompt',
 | 
			
		||||
  props: {
 | 
			
		||||
    content: {
 | 
			
		||||
      type: String,
 | 
			
		||||
      default: '',
 | 
			
		||||
    },
 | 
			
		||||
    icon: {
 | 
			
		||||
      type: String,
 | 
			
		||||
      default: 'images/user-icon.png',
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
  data() {
 | 
			
		||||
    return {}
 | 
			
		||||
  },
 | 
			
		||||
})
 | 
			
		||||
</script>
 | 
			
		||||
 | 
			
		||||
<style lang="stylus">
 | 
			
		||||
.chat-line-right {
 | 
			
		||||
  justify-content: end;
 | 
			
		||||
 | 
			
		||||
  .chat-icon {
 | 
			
		||||
    margin-left 5px;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  .chat-item {
 | 
			
		||||
    position: relative;
 | 
			
		||||
    padding: 0 5px 0 0;
 | 
			
		||||
    overflow: hidden;
 | 
			
		||||
 | 
			
		||||
    .triangle {
 | 
			
		||||
      width: 0;
 | 
			
		||||
      height: 0;
 | 
			
		||||
      border-top: 5px solid transparent;
 | 
			
		||||
      border-bottom: 5px solid transparent;
 | 
			
		||||
      border-left: 5px solid #98E165;
 | 
			
		||||
      position: absolute;
 | 
			
		||||
      right: 0;
 | 
			
		||||
      top: 10px;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    .content {
 | 
			
		||||
      float: right;
 | 
			
		||||
      padding: 5px 10px;
 | 
			
		||||
      background-color: #98E165;
 | 
			
		||||
      color var(--content-color);
 | 
			
		||||
      font-size: var(--content-font-size);
 | 
			
		||||
      border-radius: 5px;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
</style>
 | 
			
		||||
							
								
								
									
										71
									
								
								web/src/components/ChatReply.vue
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										71
									
								
								web/src/components/ChatReply.vue
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,71 @@
 | 
			
		||||
<template>
 | 
			
		||||
  <div class="chat-line chat-line-left">
 | 
			
		||||
    <div class="chat-icon">
 | 
			
		||||
      <img :src="icon" alt="ChatGPT">
 | 
			
		||||
    </div>
 | 
			
		||||
 | 
			
		||||
    <div class="chat-item">
 | 
			
		||||
      <div class="triangle"></div>
 | 
			
		||||
      <span class="content">{{ content }}</span>
 | 
			
		||||
    </div>
 | 
			
		||||
  </div>
 | 
			
		||||
</template>
 | 
			
		||||
 | 
			
		||||
<script>
 | 
			
		||||
import {defineComponent} from "vue"
 | 
			
		||||
 | 
			
		||||
export default defineComponent({
 | 
			
		||||
  name: 'ChatReply',
 | 
			
		||||
  props: {
 | 
			
		||||
    content: {
 | 
			
		||||
      type: String,
 | 
			
		||||
      default: '',
 | 
			
		||||
    },
 | 
			
		||||
    icon: {
 | 
			
		||||
      type: String,
 | 
			
		||||
      default: 'images/gpt-icon.png',
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
  data() {
 | 
			
		||||
    return {}
 | 
			
		||||
  },
 | 
			
		||||
})
 | 
			
		||||
</script>
 | 
			
		||||
 | 
			
		||||
<style lang="stylus">
 | 
			
		||||
.chat-line-left {
 | 
			
		||||
  justify-content: start;
 | 
			
		||||
 | 
			
		||||
  .chat-icon {
 | 
			
		||||
    margin-right 5px;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  .chat-item {
 | 
			
		||||
    display: inline-block;
 | 
			
		||||
    position: relative;
 | 
			
		||||
    padding: 0 0 0 5px;
 | 
			
		||||
    overflow: hidden;
 | 
			
		||||
 | 
			
		||||
    .triangle {
 | 
			
		||||
      width: 0;
 | 
			
		||||
      height: 0;
 | 
			
		||||
      border-top: 5px solid transparent;
 | 
			
		||||
      border-bottom: 5px solid transparent;
 | 
			
		||||
      border-right: 5px solid #fff;
 | 
			
		||||
      position: absolute;
 | 
			
		||||
      left: 0;
 | 
			
		||||
      top: 13px;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    .content {
 | 
			
		||||
      float: left;
 | 
			
		||||
      padding: 8px 10px;
 | 
			
		||||
      color var(--content-color)
 | 
			
		||||
      background-color: #fff;
 | 
			
		||||
      font-size: var(--content-font-size);
 | 
			
		||||
      border-radius: 5px;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
</style>
 | 
			
		||||
							
								
								
									
										40
									
								
								web/src/main.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								web/src/main.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,40 @@
 | 
			
		||||
import {createRouter, createWebHashHistory} from 'vue-router'
 | 
			
		||||
import {createApp} from 'vue'
 | 
			
		||||
import ElementPlus from "element-plus"
 | 
			
		||||
import "element-plus/dist/index.css"
 | 
			
		||||
import App from './App.vue'
 | 
			
		||||
import Home from './views/Chat.vue'
 | 
			
		||||
import NotFound from './views/404.vue'
 | 
			
		||||
import './utils/prototype'
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
const routes = [
 | 
			
		||||
    {
 | 
			
		||||
        name: 'home', path: '/', component: Home, meta: {
 | 
			
		||||
            title: 'ChatGPT-Console'
 | 
			
		||||
        }
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
        name: 'NotFound', path: '/:all(.*)', component: NotFound, meta: {
 | 
			
		||||
            title: '页面没有找到'
 | 
			
		||||
        }
 | 
			
		||||
    },
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
const router = createRouter({
 | 
			
		||||
    history: createWebHashHistory(),
 | 
			
		||||
    routes: routes,
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
// dynamic change the title when router change
 | 
			
		||||
router.beforeEach((to, from, next) => {
 | 
			
		||||
    if (to.meta.title) {
 | 
			
		||||
        document.title = to.meta.title
 | 
			
		||||
    }
 | 
			
		||||
    next()
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
const app = createApp(App)
 | 
			
		||||
app.use(router).use(ElementPlus).mount('#app')
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										77
									
								
								web/src/utils/http.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										77
									
								
								web/src/utils/http.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,77 @@
 | 
			
		||||
import axios from 'axios'
 | 
			
		||||
import JSONBigInt from 'json-bigint'
 | 
			
		||||
import qs from 'qs'
 | 
			
		||||
 | 
			
		||||
import { ElMessageBox } from 'element-plus'
 | 
			
		||||
 | 
			
		||||
axios.defaults.timeout = 5000
 | 
			
		||||
axios.defaults.baseURL = process.env.VUE_APP_API_SECURE === true ? 'https://' + process.env.VUE_APP_API_HOST : 'http://' + process.env.VUE_APP_API_HOST
 | 
			
		||||
axios.defaults.withCredentials = true
 | 
			
		||||
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded'
 | 
			
		||||
axios.defaults.transformResponse = [(data, headers) => {
 | 
			
		||||
  if (headers['content-type'].indexOf('application/json') !== -1) {
 | 
			
		||||
    try {
 | 
			
		||||
      data = JSONBigInt.parse(data)
 | 
			
		||||
    } catch (e) { /* Ignore */ }
 | 
			
		||||
  }
 | 
			
		||||
  return data
 | 
			
		||||
}]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// HTTP拦截器
 | 
			
		||||
axios.interceptors.request.use(
 | 
			
		||||
  config => {
 | 
			
		||||
    // set session-name
 | 
			
		||||
    config.headers['Session-Name'] = "xwebssh-sess-token"
 | 
			
		||||
    return config
 | 
			
		||||
  }, error => {
 | 
			
		||||
    return Promise.reject(error)
 | 
			
		||||
  })
 | 
			
		||||
axios.interceptors.response.use(
 | 
			
		||||
  response => {
 | 
			
		||||
    if (response.data.code == 0) {
 | 
			
		||||
      return response
 | 
			
		||||
    } else {
 | 
			
		||||
      return Promise.reject(response.data)
 | 
			
		||||
    }
 | 
			
		||||
  }, error => {
 | 
			
		||||
    if (error.response.status === 401) {
 | 
			
		||||
      ElMessageBox.alert('您未登录或者登录已退出,请先登录再操作。', '登录提醒', {
 | 
			
		||||
        confirmButtonText: '确定',
 | 
			
		||||
        callback: () => {
 | 
			
		||||
          // TODO: goto login page
 | 
			
		||||
        },
 | 
			
		||||
      })
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (error.response.status === 400) {
 | 
			
		||||
      return Promise.reject(error.response.data)
 | 
			
		||||
    }
 | 
			
		||||
    return Promise.reject(error)
 | 
			
		||||
  })
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// send a http get request
 | 
			
		||||
export function httpGet (url, params = {}) {
 | 
			
		||||
  return new Promise((resolve, reject) => {
 | 
			
		||||
    axios.get(url, {
 | 
			
		||||
      params: params
 | 
			
		||||
    }).then(response => {
 | 
			
		||||
      resolve(response.data)
 | 
			
		||||
    }).catch(err => {
 | 
			
		||||
      reject(err)
 | 
			
		||||
    })
 | 
			
		||||
  })
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// send a http post request
 | 
			
		||||
export function httpPost (url, data = {}, options = {}) {
 | 
			
		||||
  return new Promise((resolve, reject) => {
 | 
			
		||||
    axios.post(url, qs.stringify(data), options).then(response => {
 | 
			
		||||
      resolve(response.data)
 | 
			
		||||
    }).catch(err => {
 | 
			
		||||
      reject(err)
 | 
			
		||||
    })
 | 
			
		||||
  })
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										15
									
								
								web/src/utils/libs.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								web/src/utils/libs.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,15 @@
 | 
			
		||||
/**
 | 
			
		||||
 * Util lib functions
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
// generate a random string
 | 
			
		||||
export function randString(length) {
 | 
			
		||||
    const str = "0123456789abcdefghijklmnopqrstuvwxyz"
 | 
			
		||||
    const size = str.length
 | 
			
		||||
    let buf = []
 | 
			
		||||
    for (let i = 0; i < length; i++) {
 | 
			
		||||
        const rand = Math.random() * size
 | 
			
		||||
        buf.push(str.charAt(rand))
 | 
			
		||||
    }
 | 
			
		||||
    return buf.join("")
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										8
									
								
								web/src/utils/prototype.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								web/src/utils/prototype.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,8 @@
 | 
			
		||||
// add prototype method for array to insert item
 | 
			
		||||
Array.prototype.insert = function (index, item) {
 | 
			
		||||
  this.splice(index, 0, item)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Array.prototype.remove = function (index) {
 | 
			
		||||
  this.splice(index, 1)
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										7
									
								
								web/src/utils/storage.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								web/src/utils/storage.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,7 @@
 | 
			
		||||
/* eslint-disable no-constant-condition */
 | 
			
		||||
/**
 | 
			
		||||
 * storage handler
 | 
			
		||||
 */
 | 
			
		||||
// import Storage from 'good-storage'
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										17
									
								
								web/src/views/404.vue
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								web/src/views/404.vue
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,17 @@
 | 
			
		||||
<template>
 | 
			
		||||
  <div>{{ title }}</div>
 | 
			
		||||
</template>
 | 
			
		||||
 | 
			
		||||
<script>
 | 
			
		||||
import { defineComponent } from "vue"
 | 
			
		||||
 | 
			
		||||
export default defineComponent({
 | 
			
		||||
  name: 'NotFound',
 | 
			
		||||
  data () {
 | 
			
		||||
    return {
 | 
			
		||||
      title: "404 Page",
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
})
 | 
			
		||||
</script>
 | 
			
		||||
							
								
								
									
										227
									
								
								web/src/views/Chat.vue
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										227
									
								
								web/src/views/Chat.vue
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,227 @@
 | 
			
		||||
<template>
 | 
			
		||||
  <div class="common-layout">
 | 
			
		||||
    <div class="chat-box" :style="{height: chatBoxHeight+'px'}">
 | 
			
		||||
      <div v-for="chat in chatData" :key="chat.id">
 | 
			
		||||
        <chat-prompt
 | 
			
		||||
            v-if="chat.type==='prompt'"
 | 
			
		||||
            :icon="chat.icon"
 | 
			
		||||
            :content="chat.content"/>
 | 
			
		||||
        <chat-reply v-else-if="chat.type==='reply'"
 | 
			
		||||
                    :icon="chat.icon"
 | 
			
		||||
                    :content="chat.content"/>
 | 
			
		||||
      </div>
 | 
			
		||||
 | 
			
		||||
    </div>
 | 
			
		||||
 | 
			
		||||
    <div class="input-box" :style="{width: inputBoxWidth+'px'}" id="input-box">
 | 
			
		||||
      <div class="input-container">
 | 
			
		||||
        <textarea class="input-text" id="input-text" rows="1" :style="{minHeight:'24px', height: textHeight+'px'}"
 | 
			
		||||
                  v-on:keyup="inputKeyUp"
 | 
			
		||||
                  v-model="inputValue"
 | 
			
		||||
                  placeholder="Input any thing here..."
 | 
			
		||||
                  autofocus></textarea>
 | 
			
		||||
      </div>
 | 
			
		||||
      <div class="btn-container">
 | 
			
		||||
        <button type="button">发送</button>
 | 
			
		||||
      </div>
 | 
			
		||||
    </div>
 | 
			
		||||
  </div>
 | 
			
		||||
</template>
 | 
			
		||||
 | 
			
		||||
<script>
 | 
			
		||||
import {defineComponent} from 'vue'
 | 
			
		||||
import ChatPrompt from "@/components/ChatPrompt.vue";
 | 
			
		||||
import ChatReply from "@/components/ChatReply.vue";
 | 
			
		||||
import {randString} from "@/utils/libs";
 | 
			
		||||
 | 
			
		||||
export default defineComponent({
 | 
			
		||||
  name: "XChat",
 | 
			
		||||
  components: {ChatPrompt, ChatReply},
 | 
			
		||||
  data() {
 | 
			
		||||
    return {
 | 
			
		||||
      title: "ChatGPT 控制台",
 | 
			
		||||
      chatData: [
 | 
			
		||||
        {
 | 
			
		||||
          id: "1",
 | 
			
		||||
          type: 'prompt',
 | 
			
		||||
          icon: 'images/user-icon.png',
 | 
			
		||||
          content: '请问棒球棒可以放进人的耳朵里面吗'
 | 
			
		||||
        },
 | 
			
		||||
        {
 | 
			
		||||
          id: "2",
 | 
			
		||||
          type: 'reply',
 | 
			
		||||
          icon: 'images/gpt-icon.png',
 | 
			
		||||
          content: '不可以。棒球棒的直径通常都比人的耳道大得多,而且人的耳朵是非常敏感和易受伤的,如果硬塞棒球棒可能会导致耳道损伤、出血和疼痛等问题。此外,塞入耳道的物体还可能引起耳屎的囤积和感染等问题,因此强烈建议不要将任何非耳朵医学用品的物品插入耳朵。如果您有耳道不适或者其他耳朵健康问题,应该咨询专业医生的建议。'
 | 
			
		||||
        }
 | 
			
		||||
      ],
 | 
			
		||||
      inputBoxHeight: 63,
 | 
			
		||||
      inputBoxWidth: window.innerWidth - 20,
 | 
			
		||||
      inputValue: '',
 | 
			
		||||
      textHeight: 24,
 | 
			
		||||
      textWidth: 0,
 | 
			
		||||
      chatBoxHeight: 0,
 | 
			
		||||
      isMobile: false
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
 | 
			
		||||
  computed: {},
 | 
			
		||||
 | 
			
		||||
  mounted: function () {
 | 
			
		||||
    this.inputBoxHeight = document.getElementById("input-box").offsetHeight;
 | 
			
		||||
    this.textWidth = document.getElementById("input-text").offsetWidth;
 | 
			
		||||
    this.chatBoxHeight = window.innerHeight - this.inputBoxHeight - 40;
 | 
			
		||||
 | 
			
		||||
    //判断是否手机端访问
 | 
			
		||||
    const userAgentInfo = navigator.userAgent.toLowerCase();
 | 
			
		||||
    const Agents = ["android", "iphone", "windows phone", "ipad", "ipod"];
 | 
			
		||||
    for (let v = 0; v < Agents.length; v++) {
 | 
			
		||||
      if (userAgentInfo.indexOf(Agents[v]) >= 0) {
 | 
			
		||||
        this.isMobile = true;
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    window.addEventListener('resize', this.windowResize);
 | 
			
		||||
  },
 | 
			
		||||
 | 
			
		||||
  beforeUnmount() {
 | 
			
		||||
    window.removeEventListener("resize", this.windowResize);
 | 
			
		||||
  },
 | 
			
		||||
 | 
			
		||||
  methods: {
 | 
			
		||||
    inputKeyUp: function (e) {
 | 
			
		||||
      // PC 端按回车键直接提交数据
 | 
			
		||||
      if (e.keyCode === 13 && !this.isMobile) {
 | 
			
		||||
        this.chatData.push({
 | 
			
		||||
          type: "prompt",
 | 
			
		||||
          id: randString(32),
 | 
			
		||||
          icon: 'images/user-icon.png',
 | 
			
		||||
          content: this.inputValue
 | 
			
		||||
        });
 | 
			
		||||
        this.inputValue = '';
 | 
			
		||||
        console.log("提交数据")
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      this.inputResize();
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
    // 初始化
 | 
			
		||||
    inputResize: function () {
 | 
			
		||||
      // 根据输入的字数自动调整输入框的大小
 | 
			
		||||
      let line = 1;
 | 
			
		||||
      let textWidth = 0;
 | 
			
		||||
      for (let i in this.inputValue) {
 | 
			
		||||
        if (this.inputValue[i] === '\n') {
 | 
			
		||||
          line++;
 | 
			
		||||
          textWidth = 0; // 换行之后前面字数清零
 | 
			
		||||
        }
 | 
			
		||||
        if (this.inputValue.charCodeAt(Number(i)) < 128) {
 | 
			
		||||
          textWidth += 9.65; // 英文字符宽度
 | 
			
		||||
        } else {
 | 
			
		||||
          textWidth += 16.07; // 中文字符宽度
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
      line = line + (Math.ceil(textWidth / this.textWidth)) - 1;
 | 
			
		||||
      this.inputBoxHeight = 63 + (line - 1) * 24;
 | 
			
		||||
      this.textHeight = line * 24;
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
    windowResize: function () {
 | 
			
		||||
      this.inputResize();
 | 
			
		||||
      this.chatBoxHeight = window.innerHeight - this.inputBoxHeight - 40;
 | 
			
		||||
      this.inputBoxWidth = window.innerWidth - 20;
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
 | 
			
		||||
})
 | 
			
		||||
</script>
 | 
			
		||||
 | 
			
		||||
<style lang="stylus">
 | 
			
		||||
.chat-box {
 | 
			
		||||
  // 变量定义
 | 
			
		||||
  --content-font-size: 16px;
 | 
			
		||||
  --content-color: #374151;
 | 
			
		||||
 | 
			
		||||
  background-color: rgba(247, 247, 248, 1);
 | 
			
		||||
  font-family 'Microsoft YaHei', '微软雅黑', Arial, sans-serif;
 | 
			
		||||
  padding: 20px 10px;
 | 
			
		||||
 | 
			
		||||
  .chat-line {
 | 
			
		||||
    padding 10px;
 | 
			
		||||
    font-size 14px;
 | 
			
		||||
    display: flex;
 | 
			
		||||
    align-items: flex-start;
 | 
			
		||||
 | 
			
		||||
    .chat-icon {
 | 
			
		||||
      img {
 | 
			
		||||
        width 32px;
 | 
			
		||||
        height 32px;
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.input-box {
 | 
			
		||||
  background-color: rgba(255, 255, 255, 1);
 | 
			
		||||
  padding 10px;
 | 
			
		||||
 | 
			
		||||
  position: absolute;
 | 
			
		||||
  bottom: 0
 | 
			
		||||
  display: flex;
 | 
			
		||||
  justify-content: center;
 | 
			
		||||
  align-items: center;
 | 
			
		||||
 | 
			
		||||
  .input-container {
 | 
			
		||||
    overflow hidden
 | 
			
		||||
    width 100%
 | 
			
		||||
    margin: 0;
 | 
			
		||||
    background #ffffff
 | 
			
		||||
    border: none;
 | 
			
		||||
    border-radius: 6px;
 | 
			
		||||
    box-shadow: 0 2px 15px rgba(0, 0, 0, 0.1);
 | 
			
		||||
    padding: 5px 10px;
 | 
			
		||||
 | 
			
		||||
    .input-text {
 | 
			
		||||
      font-size: 16px;
 | 
			
		||||
      padding 0
 | 
			
		||||
      margin 0
 | 
			
		||||
      outline: none;
 | 
			
		||||
      width 100%;
 | 
			
		||||
      border none
 | 
			
		||||
      background transparent
 | 
			
		||||
      resize none
 | 
			
		||||
      line-height 24px;
 | 
			
		||||
      color #333;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    .input-text::-webkit-scrollbar {
 | 
			
		||||
      width: 0;
 | 
			
		||||
      height: 0;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  .btn-container {
 | 
			
		||||
    margin-left 10px;
 | 
			
		||||
 | 
			
		||||
    button {
 | 
			
		||||
      width 70px;
 | 
			
		||||
      outline none
 | 
			
		||||
      border none
 | 
			
		||||
      cursor pointer
 | 
			
		||||
      background-color: #07c160
 | 
			
		||||
      position: relative;
 | 
			
		||||
      margin-left: auto;
 | 
			
		||||
      margin-right: auto;
 | 
			
		||||
      font-size 16px
 | 
			
		||||
      box-sizing: border-box;
 | 
			
		||||
      font-weight: 700;
 | 
			
		||||
      text-align: center;
 | 
			
		||||
      text-decoration: none;
 | 
			
		||||
      color: #fff;
 | 
			
		||||
      line-height: 2.25;
 | 
			
		||||
      border-radius: 8px;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
</style>
 | 
			
		||||
							
								
								
									
										29
									
								
								web/vue.config.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								web/vue.config.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,29 @@
 | 
			
		||||
const {defineConfig} = require('@vue/cli-service')
 | 
			
		||||
let webpack = require('webpack')
 | 
			
		||||
// const fs = require('fs')
 | 
			
		||||
// const path = require('path')
 | 
			
		||||
// const os = require('os')
 | 
			
		||||
 | 
			
		||||
module.exports = defineConfig({
 | 
			
		||||
    transpileDependencies: true,
 | 
			
		||||
    configureWebpack: {
 | 
			
		||||
        // disable performance hints
 | 
			
		||||
        performance: {
 | 
			
		||||
            hints: false
 | 
			
		||||
        },
 | 
			
		||||
        plugins: [
 | 
			
		||||
            new webpack.optimize.MinChunkSizePlugin({minChunkSize: 10000})
 | 
			
		||||
        ]
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
    publicPath: process.env.NODE_ENV === 'production'
 | 
			
		||||
        ? '/web'
 | 
			
		||||
        : '/',
 | 
			
		||||
 | 
			
		||||
    outputDir: 'dist',
 | 
			
		||||
    crossorigin: "anonymous",
 | 
			
		||||
    devServer: {
 | 
			
		||||
        allowedHosts: ['127.0.0.1:5678'],
 | 
			
		||||
        port: 8888,
 | 
			
		||||
    }
 | 
			
		||||
})
 | 
			
		||||
		Reference in New Issue
	
	Block a user