U import server

This commit is contained in:
zhenorzz 2022-03-17 21:09:12 +08:00
parent a6c6eac0c2
commit 21db582a16
5 changed files with 551 additions and 12 deletions

View File

@ -1,6 +1,8 @@
package controller
import (
"encoding/csv"
"fmt"
"github.com/pkg/sftp"
"github.com/zhenorzz/goploy/core"
"github.com/zhenorzz/goploy/middleware"
@ -12,6 +14,7 @@ import (
"net/http"
"strconv"
"strings"
"sync"
)
// Server struct
@ -24,6 +27,7 @@ func (s Server) Routes() []core.Route {
core.NewRoute("/server/getOption", http.MethodGet, s.GetOption),
core.NewRoute("/server/getPublicKey", http.MethodGet, s.GetPublicKey),
core.NewRoute("/server/check", http.MethodPost, s.Check).Roles(core.RoleAdmin, core.RoleManager),
core.NewRoute("/server/import", http.MethodPost, s.Import).Roles(core.RoleAdmin, core.RoleManager),
core.NewRoute("/server/add", http.MethodPost, s.Add).Roles(core.RoleAdmin, core.RoleManager),
core.NewRoute("/server/edit", http.MethodPut, s.Edit).Roles(core.RoleAdmin, core.RoleManager),
core.NewRoute("/server/toggle", http.MethodPut, s.Toggle).Roles(core.RoleAdmin, core.RoleManager),
@ -131,6 +135,109 @@ func (Server) Check(gp *core.Goploy) core.Response {
return response.JSON{Message: "Connected"}
}
func (Server) Import(gp *core.Goploy) core.Response {
file, _, err := gp.Request.FormFile("file")
if err != nil {
return response.JSON{Code: response.IllegalParam, Message: err.Error()}
}
defer file.Close()
r := csv.NewReader(file)
i := 0
headerIdx := map[string]int{
"name": -1,
"host": -1,
"port": -1,
"owner": -1,
"path": -1,
"password": -1,
"description": -1,
"jumpHost": -1,
"jumpPort": -1,
"jumpOwner": -1,
"jumpPath": -1,
"jumpPassword": -1,
}
errOccur := false
var wg sync.WaitGroup
for {
record, err := r.Read()
if err == io.EOF {
break
}
if err != nil {
return response.JSON{Code: response.Error, Message: err.Error()}
}
fmt.Printf("%v", record)
i++
if i == 1 {
for index, header := range record {
if _, ok := headerIdx[header]; !ok {
return response.JSON{Code: response.Error, Message: fmt.Sprintf("%s does not match the csv field", header)}
} else {
headerIdx[header] = index
}
}
continue
}
wg.Add(1)
go func() {
server := model.Server{
NamespaceID: gp.Namespace.ID,
}
if headerIdx["name"] != -1 {
server.Name = record[headerIdx["name"]]
}
if headerIdx["host"] != -1 {
server.IP = record[headerIdx["host"]]
}
if headerIdx["port"] != -1 {
server.Port, _ = strconv.Atoi(record[headerIdx["port"]])
}
if headerIdx["owner"] != -1 {
server.Owner = record[headerIdx["owner"]]
}
if headerIdx["path"] != -1 {
server.Path = record[headerIdx["path"]]
}
if headerIdx["password"] != -1 {
server.Password = record[headerIdx["password"]]
}
if headerIdx["description"] != -1 {
server.Description = record[headerIdx["description"]]
}
if headerIdx["jumpHost"] != -1 {
server.JumpIP = record[headerIdx["jumpHost"]]
}
if headerIdx["jumpPort"] != -1 {
server.JumpPort, _ = strconv.Atoi(record[headerIdx["jumpPort"]])
}
if headerIdx["jumpOwner"] != -1 {
server.JumpOwner = record[headerIdx["jumpOwner"]]
}
if headerIdx["jumpPath"] != -1 {
server.JumpPath = record[headerIdx["jumpPath"]]
}
if headerIdx["jumpPassword"] != -1 {
server.JumpPassword = record[headerIdx["jumpPassword"]]
}
server.OSInfo = server.Convert2SSHConfig().GetOSInfo()
if _, err := server.AddRow(); err != nil {
errOccur = true
core.Log(core.ERROR, fmt.Sprintf("Record <%s> error, %s", record, err.Error()))
}
wg.Done()
}()
}
wg.Wait()
if errOccur {
return response.JSON{Code: response.Error, Message: "Encountered some unknown errors, please check the log details"}
}
return response.JSON{}
}
func (s Server) Add(gp *core.Goploy) core.Response {
type ReqData struct {
Name string `json:"name" validate:"required"`

396
web/package-lock.json generated
View File

@ -460,6 +460,177 @@
"integrity": "sha512-RkqfJHz9wdLKBp5Yi+kQL8BAljdrvPoccQm2PTZc/UcL4EjD11xsv2PPCduYx2oV1a/bpSKA3sD5sxOHFhz+LA==",
"dev": true
},
"@volar/code-gen": {
"version": "0.33.2",
"resolved": "https://registry.npmjs.org/@volar/code-gen/-/code-gen-0.33.2.tgz",
"integrity": "sha512-PByxCupmCcMZwIL6KIkKzxGV6edxrckYnxQ6lMx9XC1wqBgtHPAHtLF+mAeqBxLRetMbhIb3lIswQEy+T+OmLg==",
"dev": true,
"requires": {
"@volar/shared": "0.33.2",
"@volar/source-map": "0.33.2"
}
},
"@volar/pug-language-service": {
"version": "0.33.2",
"resolved": "https://registry.npmjs.org/@volar/pug-language-service/-/pug-language-service-0.33.2.tgz",
"integrity": "sha512-Kv8pPsI+y2cyKyZEETdtmmNBT+Yu5+SqDxAjs5VvNhQ+R6Sjo1rr45h3ey+XqlE9ABSXIMECGefsabOAI1h0bA==",
"dev": true,
"requires": {
"@volar/code-gen": "0.33.2",
"@volar/shared": "0.33.2",
"@volar/source-map": "0.33.2",
"@volar/transforms": "0.33.2",
"pug-lexer": "^5.0.1",
"pug-parser": "^6.0.0",
"vscode-languageserver-textdocument": "^1.0.3",
"vscode-languageserver-types": "^3.17.0-next.6"
},
"dependencies": {
"vscode-languageserver-types": {
"version": "3.17.0-next.9",
"resolved": "https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.17.0-next.9.tgz",
"integrity": "sha512-9/PeDNPYduaoXRUzYpqmu4ZV9L01HGo0wH9FUt+sSHR7IXwA7xoXBfNUlv8gB9H0D2WwEmMomSy1NmhjKQyn3A==",
"dev": true
}
}
},
"@volar/shared": {
"version": "0.33.2",
"resolved": "https://registry.npmjs.org/@volar/shared/-/shared-0.33.2.tgz",
"integrity": "sha512-WTJItfRhLGwHkKwUH0LnyQXNzLFmqdyA9QZEXSgVOst0MKzExhFvuxbZX7BX6VVidYiekoKLZ6GooslSjxzVIA==",
"dev": true,
"requires": {
"upath": "^2.0.1",
"vscode-html-languageservice": "^4.2.1",
"vscode-jsonrpc": "^8.0.0-next.5",
"vscode-uri": "^3.0.3"
}
},
"@volar/source-map": {
"version": "0.33.2",
"resolved": "https://registry.npmjs.org/@volar/source-map/-/source-map-0.33.2.tgz",
"integrity": "sha512-ZT+t0wqMDl0sQ4wxmXL0yeE1VsFoAj/984XuGdb4TDTD4bKh9iwARNr/B+az4IZUJQrMeHx/YNr3yYUdwRZkKA==",
"dev": true,
"requires": {
"@volar/shared": "0.33.2",
"vscode-languageserver-textdocument": "^1.0.3"
}
},
"@volar/transforms": {
"version": "0.33.2",
"resolved": "https://registry.npmjs.org/@volar/transforms/-/transforms-0.33.2.tgz",
"integrity": "sha512-dcIGlxaZ5CmGYhc7e1huVQx9nMF5m6GVwvaP+c4XrYtHyISUl2GpIFvIlxWfqE2FUytyabUyrTkYK+Kv6Shd5g==",
"dev": true,
"requires": {
"@volar/shared": "0.33.2",
"vscode-languageserver-types": "^3.17.0-next.6"
},
"dependencies": {
"vscode-languageserver-types": {
"version": "3.17.0-next.9",
"resolved": "https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.17.0-next.9.tgz",
"integrity": "sha512-9/PeDNPYduaoXRUzYpqmu4ZV9L01HGo0wH9FUt+sSHR7IXwA7xoXBfNUlv8gB9H0D2WwEmMomSy1NmhjKQyn3A==",
"dev": true
}
}
},
"@volar/typescript-language-service": {
"version": "0.33.2",
"resolved": "https://registry.npmjs.org/@volar/typescript-language-service/-/typescript-language-service-0.33.2.tgz",
"integrity": "sha512-jD4XtL89let4ilDSrVI2BB0PiVbqYXmK7ARv8LrkOQTAZlpkNesOaY8BMEDsEg/L3ZBqj48EPPrwmBXNt8PWxQ==",
"dev": true,
"requires": {
"@volar/shared": "0.33.2",
"semver": "^7.3.5",
"upath": "^2.0.1",
"vscode-languageserver-protocol": "^3.17.0-next.12",
"vscode-languageserver-textdocument": "^1.0.3",
"vscode-nls": "^5.0.0"
},
"dependencies": {
"semver": {
"version": "7.3.5",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz",
"integrity": "sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==",
"dev": true,
"requires": {
"lru-cache": "^6.0.0"
}
}
}
},
"@volar/vue-code-gen": {
"version": "0.33.2",
"resolved": "https://registry.npmjs.org/@volar/vue-code-gen/-/vue-code-gen-0.33.2.tgz",
"integrity": "sha512-Yfvdk3u3x3TFw84/wsxS3QBfkoEB3flqTTG7CsC24C7Ou0DsB66eNaRSDJ/3P/bienFV7e7v0nH1BtqcV2/QPg==",
"dev": true,
"requires": {
"@volar/code-gen": "0.33.2",
"@volar/shared": "0.33.2",
"@volar/source-map": "0.33.2",
"@vue/compiler-core": "^3.2.27",
"@vue/compiler-dom": "^3.2.27",
"@vue/shared": "^3.2.27",
"upath": "^2.0.1"
},
"dependencies": {
"@babel/parser": {
"version": "7.17.7",
"resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.17.7.tgz",
"integrity": "sha512-bm3AQf45vR4gKggRfvJdYJ0gFLoCbsPxiFLSH6hTVYABptNHY6l9NrhnucVjQ/X+SPtLANT9lc0fFhikj+VBRA==",
"dev": true
},
"@vue/compiler-core": {
"version": "3.2.31",
"resolved": "https://registry.npmjs.org/@vue/compiler-core/-/compiler-core-3.2.31.tgz",
"integrity": "sha512-aKno00qoA4o+V/kR6i/pE+aP+esng5siNAVQ422TkBNM6qA4veXiZbSe8OTXHXquEi/f6Akc+nLfB4JGfe4/WQ==",
"dev": true,
"requires": {
"@babel/parser": "^7.16.4",
"@vue/shared": "3.2.31",
"estree-walker": "^2.0.2",
"source-map": "^0.6.1"
}
},
"@vue/compiler-dom": {
"version": "3.2.31",
"resolved": "https://registry.npmjs.org/@vue/compiler-dom/-/compiler-dom-3.2.31.tgz",
"integrity": "sha512-60zIlFfzIDf3u91cqfqy9KhCKIJgPeqxgveH2L+87RcGU/alT6BRrk5JtUso0OibH3O7NXuNOQ0cDc9beT0wrg==",
"dev": true,
"requires": {
"@vue/compiler-core": "3.2.31",
"@vue/shared": "3.2.31"
}
},
"@vue/shared": {
"version": "3.2.31",
"resolved": "https://registry.npmjs.org/@vue/shared/-/shared-3.2.31.tgz",
"integrity": "sha512-ymN2pj6zEjiKJZbrf98UM2pfDd6F2H7ksKw7NDt/ZZ1fh5Ei39X5tABugtT03ZRlWd9imccoK0hE8hpjpU7irQ==",
"dev": true
}
}
},
"@volar/vue-typescript": {
"version": "0.33.2",
"resolved": "https://registry.npmjs.org/@volar/vue-typescript/-/vue-typescript-0.33.2.tgz",
"integrity": "sha512-k5Uo0Uw+KgBEzJgUp2vh8qLjTIXXJvEud5yzSbECoKzc+dhOCYfpuZQx5bSNCEaUiRdi99kvekeeWNypQgha+Q==",
"dev": true,
"requires": {
"@volar/code-gen": "0.33.2",
"@volar/pug-language-service": "0.33.2",
"@volar/shared": "0.33.2",
"@volar/source-map": "0.33.2",
"@volar/typescript-language-service": "0.33.2",
"@volar/vue-code-gen": "0.33.2",
"@vue/reactivity": "^3.2.27",
"upath": "^2.0.1",
"vscode-css-languageservice": "^5.1.9",
"vscode-html-languageservice": "^4.2.1",
"vscode-json-languageservice": "^4.1.10",
"vscode-languageserver-protocol": "^3.17.0-next.12",
"vscode-languageserver-textdocument": "^1.0.3"
}
},
"@vue/compiler-core": {
"version": "3.2.4",
"resolved": "https://registry.npmjs.org/@vue/compiler-core/-/compiler-core-3.2.4.tgz",
@ -953,6 +1124,16 @@
"unset-value": "^1.0.0"
}
},
"call-bind": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz",
"integrity": "sha512-7O+FbCihrB5WGbFYesctwmTKae6rOiIzmz1icreWJ+0aA7LJfuqhEso2T9ncpcFtzMQtzXf2QGGueWJGTYsqrA==",
"dev": true,
"requires": {
"function-bind": "^1.1.1",
"get-intrinsic": "^1.0.2"
}
},
"callsites": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz",
@ -1008,6 +1189,15 @@
}
}
},
"character-parser": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/character-parser/-/character-parser-2.2.0.tgz",
"integrity": "sha1-x84o821LzZdE5f/CxfzeHHMmH8A=",
"dev": true,
"requires": {
"is-regex": "^1.0.3"
}
},
"chokidar": {
"version": "3.5.2",
"resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.5.2.tgz",
@ -1977,6 +2167,12 @@
"rimraf": "2"
}
},
"function-bind": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz",
"integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==",
"dev": true
},
"functional-red-black-tree": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz",
@ -1997,6 +2193,17 @@
"resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz",
"integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg=="
},
"get-intrinsic": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.1.1.tgz",
"integrity": "sha512-kWZrnVM42QCiEA2Ig1bG8zjoIMOgxWwYCEeNdwY6Tv/cOSeGpcoX4pXHfKUxNKVoArnrEr2e9srnAxxGIraS9Q==",
"dev": true,
"requires": {
"function-bind": "^1.1.1",
"has": "^1.0.3",
"has-symbols": "^1.0.1"
}
},
"get-value": {
"version": "2.0.6",
"resolved": "https://registry.npmjs.org/get-value/-/get-value-2.0.6.tgz",
@ -2068,6 +2275,15 @@
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.8.tgz",
"integrity": "sha512-qkIilPUYcNhJpd33n0GBXTB1MMPp14TxEsEs0pTrsSVucApsYzW5V+Q8Qxhik6KU3evy+qkAAowTByymK0avdg=="
},
"has": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz",
"integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==",
"dev": true,
"requires": {
"function-bind": "^1.1.1"
}
},
"has-ansi": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/has-ansi/-/has-ansi-2.0.0.tgz",
@ -2091,6 +2307,21 @@
"integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==",
"dev": true
},
"has-symbols": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz",
"integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==",
"dev": true
},
"has-tostringtag": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.0.tgz",
"integrity": "sha512-kFjcSNhnlGV1kyoGk7OXKSawH5JOb/LzUc5w9B02hOTO0dfFRjbHQKvg1d6cf3HbeUmtU9VbbV3qzZ2Teh97WQ==",
"dev": true,
"requires": {
"has-symbols": "^1.0.2"
}
},
"has-value": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/has-value/-/has-value-1.0.0.tgz",
@ -2307,6 +2538,16 @@
"kind-of": "^5.0.0"
}
},
"is-expression": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/is-expression/-/is-expression-4.0.0.tgz",
"integrity": "sha512-zMIXX63sxzG3XrkHkrAPvm/OVZVSCPNkwMHU8oTX7/U3AL78I0QXCEICXUM13BIa8TYGZ68PiTKfQz3yaTNr4A==",
"dev": true,
"requires": {
"acorn": "^7.1.1",
"object-assign": "^4.1.1"
}
},
"is-extendable": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/is-extendable/-/is-extendable-0.1.1.tgz",
@ -2354,6 +2595,16 @@
"isobject": "^3.0.1"
}
},
"is-regex": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.1.4.tgz",
"integrity": "sha512-kvRdxDsxZjhzUX07ZnLydzS1TU/TJlTUHHY4YLL87e37oUA49DfkLqgy+VjFocowy29cKvcSiu+kIv728jTTVg==",
"dev": true,
"requires": {
"call-bind": "^1.0.2",
"has-tostringtag": "^1.0.0"
}
},
"is-windows": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/is-windows/-/is-windows-1.0.2.tgz",
@ -2430,6 +2681,12 @@
"semver": "^6.3.0"
}
},
"jsonc-parser": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/jsonc-parser/-/jsonc-parser-3.0.0.tgz",
"integrity": "sha512-fQzRfAbIBnR0IQvftw9FJveWiHp72Fg20giDrHz6TdfB12UH/uue0D3hm57UB5KgAVuniLMCaS8P1IMj9NR7cA==",
"dev": true
},
"jsonfile": {
"version": "6.1.0",
"resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz",
@ -3101,6 +3358,33 @@
"resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz",
"integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag=="
},
"pug-error": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/pug-error/-/pug-error-2.0.0.tgz",
"integrity": "sha512-sjiUsi9M4RAGHktC1drQfCr5C5eriu24Lfbt4s+7SykztEOwVZtbFk1RRq0tzLxcMxMYTBR+zMQaG07J/btayQ==",
"dev": true
},
"pug-lexer": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/pug-lexer/-/pug-lexer-5.0.1.tgz",
"integrity": "sha512-0I6C62+keXlZPZkOJeVam9aBLVP2EnbeDw3An+k0/QlqdwH6rv8284nko14Na7c0TtqtogfWXcRoFE4O4Ff20w==",
"dev": true,
"requires": {
"character-parser": "^2.2.0",
"is-expression": "^4.0.0",
"pug-error": "^2.0.0"
}
},
"pug-parser": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/pug-parser/-/pug-parser-6.0.0.tgz",
"integrity": "sha512-ukiYM/9cH6Cml+AOl5kETtM9NR3WulyVP2y4HOU45DyMim1IeP/OOiyEWRr6qk5I5klpsBnbuHpwKmTx6WURnw==",
"dev": true,
"requires": {
"pug-error": "^2.0.0",
"token-stream": "1.0.0"
}
},
"punycode": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz",
@ -3914,6 +4198,12 @@
"is-number": "^7.0.0"
}
},
"token-stream": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/token-stream/-/token-stream-1.0.0.tgz",
"integrity": "sha1-zCAOqyYT9BZtJ/+a/HylbUnfbrQ=",
"dev": true
},
"traverse": {
"version": "0.3.9",
"resolved": "https://registry.npmjs.org/traverse/-/traverse-0.3.9.tgz",
@ -3950,9 +4240,9 @@
"dev": true
},
"typescript": {
"version": "4.3.5",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.3.5.tgz",
"integrity": "sha512-DqQgihaQ9cUrskJo9kIyW/+g0Vxsk8cDtZ52a3NGh0YNTfpUSArXSohyUGnvbPazEPLu398C0UxmKSOrPumUzA==",
"version": "4.6.2",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.6.2.tgz",
"integrity": "sha512-HM/hFigTBHZhLXshn9sN37H085+hQGeJHJ/X7LpBWLID/fbc2acUMfU+lGD98X81sKP+pFa9f0DZmCwB9GnbAg==",
"dev": true
},
"union-value": {
@ -4036,6 +4326,12 @@
"setimmediate": "~1.0.4"
}
},
"upath": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/upath/-/upath-2.0.1.tgz",
"integrity": "sha512-1uEe95xksV1O0CYKXo8vQvN1JEbtJp7lb7C5U9HMsIp6IVwntkH/oNUzyVNQSd4S1sYk2FpSSW44FqMc8qee5w==",
"dev": true
},
"uri-js": {
"version": "4.4.1",
"resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz",
@ -4177,6 +4473,91 @@
"svgo": "^2.3.0"
}
},
"vscode-css-languageservice": {
"version": "5.1.13",
"resolved": "https://registry.npmjs.org/vscode-css-languageservice/-/vscode-css-languageservice-5.1.13.tgz",
"integrity": "sha512-FA0foqMzMmEoO0WJP+MjoD4dRERhKS+Ag+yBrtmWQDmw2OuZ1R/5FkvI/XdTkCpHmTD9VMczugpHRejQyTXCNQ==",
"dev": true,
"requires": {
"vscode-languageserver-textdocument": "^1.0.1",
"vscode-languageserver-types": "^3.16.0",
"vscode-nls": "^5.0.0",
"vscode-uri": "^3.0.2"
}
},
"vscode-html-languageservice": {
"version": "4.2.2",
"resolved": "https://registry.npmjs.org/vscode-html-languageservice/-/vscode-html-languageservice-4.2.2.tgz",
"integrity": "sha512-4ICwlpplGbiNQq6D/LZr4qLbPZuMmnSQeX/57UAYP7jD1LOvKeru4lVI+f6d6Eyd7uS46nLJ5DUY4AAlq35C0g==",
"dev": true,
"requires": {
"vscode-languageserver-textdocument": "^1.0.3",
"vscode-languageserver-types": "^3.16.0",
"vscode-nls": "^5.0.0",
"vscode-uri": "^3.0.3"
}
},
"vscode-json-languageservice": {
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/vscode-json-languageservice/-/vscode-json-languageservice-4.2.0.tgz",
"integrity": "sha512-XNawv0Vdy/sUK0S+hGf7cq/qsVAbIniGJr89TvZOqMCNJmpgKTy1e8PL1aWW0uy6BfWMG7vxa5lZb3ypuFtuGQ==",
"dev": true,
"requires": {
"jsonc-parser": "^3.0.0",
"vscode-languageserver-textdocument": "^1.0.3",
"vscode-languageserver-types": "^3.16.0",
"vscode-nls": "^5.0.0",
"vscode-uri": "^3.0.3"
}
},
"vscode-jsonrpc": {
"version": "8.0.0-next.7",
"resolved": "https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-8.0.0-next.7.tgz",
"integrity": "sha512-JX/F31LEsims0dAlOTKFE4E+AJMiJvdRSRViifFJSqSN7EzeYyWlfuDchF7g91oRNPZOIWfibTkDf3/UMsQGzQ==",
"dev": true
},
"vscode-languageserver-protocol": {
"version": "3.17.0-next.16",
"resolved": "https://registry.npmjs.org/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.17.0-next.16.tgz",
"integrity": "sha512-tx4DnXw9u3N7vw+bx6n2NKp6FoxoNwiP/biH83AS30I2AnTGyLd7afSeH6Oewn2E8jvB7K15bs12sMppkKOVeQ==",
"dev": true,
"requires": {
"vscode-jsonrpc": "8.0.0-next.7",
"vscode-languageserver-types": "3.17.0-next.9"
},
"dependencies": {
"vscode-languageserver-types": {
"version": "3.17.0-next.9",
"resolved": "https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.17.0-next.9.tgz",
"integrity": "sha512-9/PeDNPYduaoXRUzYpqmu4ZV9L01HGo0wH9FUt+sSHR7IXwA7xoXBfNUlv8gB9H0D2WwEmMomSy1NmhjKQyn3A==",
"dev": true
}
}
},
"vscode-languageserver-textdocument": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/vscode-languageserver-textdocument/-/vscode-languageserver-textdocument-1.0.4.tgz",
"integrity": "sha512-/xhqXP/2A2RSs+J8JNXpiiNVvvNM0oTosNVmQnunlKvq9o4mupHOBAnnzH0lwIPKazXKvAKsVp1kr+H/K4lgoQ==",
"dev": true
},
"vscode-languageserver-types": {
"version": "3.16.0",
"resolved": "https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.16.0.tgz",
"integrity": "sha512-k8luDIWJWyenLc5ToFQQMaSrqCHiLwyKPHKPQZ5zz21vM+vIVUSvsRpcbiECH4WR88K2XZqc4ScRcZ7nk/jbeA==",
"dev": true
},
"vscode-nls": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/vscode-nls/-/vscode-nls-5.0.0.tgz",
"integrity": "sha512-u0Lw+IYlgbEJFF6/qAqG2d1jQmJl0eyAGJHoAJqr2HT4M2BNuQYSEiSE75f52pXHSJm8AlTjnLLbBFPrdz2hpA==",
"dev": true
},
"vscode-uri": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/vscode-uri/-/vscode-uri-3.0.3.tgz",
"integrity": "sha512-EcswR2S8bpR7fD0YPeS7r2xXExrScVMxg4MedACaWHEtx9ftCF/qHG1xGkolzTPcEmjTavCQgbVzHUIdTMzFGA==",
"dev": true
},
"vue": {
"version": "3.2.31",
"resolved": "https://registry.npmjs.org/vue/-/vue-3.2.31.tgz",
@ -4332,12 +4713,13 @@
}
},
"vue-tsc": {
"version": "0.0.24",
"resolved": "https://registry.npmjs.org/vue-tsc/-/vue-tsc-0.0.24.tgz",
"integrity": "sha512-Qx0V7jkWMtvddtaWa1SA8YKkBCRmjq9zZUB2UIMZiso6JSH538oHD2VumSzkoDnAfFbY3t0/j1mB2abpA0bGWA==",
"version": "0.33.2-patch.1",
"resolved": "https://registry.npmjs.org/vue-tsc/-/vue-tsc-0.33.2-patch.1.tgz",
"integrity": "sha512-Wr1b5Dt/fqJejBk9rHHCDhSbt/sU0pekUhmyupeKbAWw9eT2DTPn1od6N3dV9jdjGitqDESVRFsw6R1hSLdAQA==",
"dev": true,
"requires": {
"unzipper": "0.10.11"
"@volar/shared": "0.33.2",
"@volar/vue-typescript": "0.33.2"
}
},
"vue3-ace-editor": {

View File

@ -49,10 +49,10 @@
"eslint-plugin-vue": "^8.5.0",
"prettier": "^2.2.1",
"sass": "^1.32.12",
"typescript": "^4.2.4",
"typescript": "^4.6.2",
"vconsole": "^3.6.1",
"vite": "^2.5.0",
"vite-plugin-svg-icons": "^0.5.0",
"vue-tsc": "^0.0.24"
"vue-tsc": "^0.33.2-patch.1"
}
}

View File

@ -1,7 +1,26 @@
<template>
<el-row class="app-container">
<el-row class="app-bar" type="flex" justify="end">
<el-button type="primary" icon="el-icon-plus" @click="handleAdd" />
<el-upload
:action="uploadHref"
accept=".csv"
:show-file-list="false"
:before-upload="beforeUpload"
:on-success="handleUploadSuccess"
:on-error="handleUploadError"
>
<el-button
type="primary"
icon="el-icon-upload2"
:loading="uploading"
></el-button>
</el-upload>
<el-button
type="primary"
style="margin-left: 10px"
icon="el-icon-plus"
@click="handleAdd"
/>
</el-row>
<el-table
:key="tableHeight"
@ -261,7 +280,9 @@ import {
ServerData,
} from '@/api/server'
import getTableHeight from '@/composables/tableHeight'
import { ref } from 'vue'
import { HttpResponse } from '@/api/types'
import { NamespaceKey, getNamespaceId } from '@/utils/namespace'
import { ref, computed } from 'vue'
import { copy, humanSize } from '@/utils'
import { ElMessageBox, ElMessage } from 'element-plus'
import { useRouter } from 'vue-router'
@ -324,6 +345,13 @@ const formRules = {
description: [{ max: 255, message: 'Max 255 characters', trigger: 'blur' }],
}
const uploading = ref(false)
const uploadHref = computed(() => {
return `${
import.meta.env.VITE_APP_BASE_API
}/server/import?${NamespaceKey}=${getNamespaceId()}`
})
getList()
getTotal()
@ -364,6 +392,28 @@ function handlePageChange(val = 1) {
getList()
}
function beforeUpload(file: File) {
uploading.value = true
return Promise.resolve()
}
function handleUploadSuccess(response: HttpResponse<string>) {
if (response.code > 0) {
ElMessage.error(`upload failed, detail: ${response.message}`)
} else {
ElMessage.success('Success')
}
getList()
uploading.value = false
return true
}
function handleUploadError(err: Error) {
ElMessage.error(err.message)
uploading.value = false
return true
}
function handleAdd() {
restoreFormData()
dialogVisible.value = true

View File

@ -9,7 +9,7 @@
"resolveJsonModule": true,
"esModuleInterop": true,
"lib": ["esnext", "dom"],
"types": ["vite/client", "node", "@intlify/vite-plugin-vue-i18n/client"],
"types": ["vite/client", "element-plus/global", "node"],
"baseUrl": "./",
"paths": {
"@/*": [