-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Release 6.0
- Loading branch information
Showing
438 changed files
with
13,009 additions
and
8,978 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
.env | ||
/jsight-server | ||
/local | ||
.tool-versions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
package main | ||
|
||
import ( | ||
"io" | ||
"log" | ||
"net/http" | ||
|
||
"github.com/jsightapi/jsight-schema-core/fs" | ||
|
||
"github.com/jsightapi/jsight-api-core/kit" | ||
) | ||
|
||
func convertJSight(w http.ResponseWriter, r *http.Request) { | ||
to := r.FormValue("to") | ||
format := r.FormValue("format") | ||
log.Printf("%s %s %s %s", r.Method, r.URL.Path, to, format) | ||
|
||
if getBoolEnv("JSIGHT_SERVER_CORS") { | ||
cors(w) | ||
} | ||
|
||
wr := httpResponseWriter{writer: w} | ||
|
||
switch r.Method { | ||
case http.MethodOptions: | ||
|
||
case http.MethodPost: | ||
convertJSightPOST(wr, r) | ||
return | ||
|
||
default: | ||
wr.errorStr("HTTP POST request required") | ||
return | ||
} | ||
} | ||
|
||
func convertJSightPOST(wr httpResponseWriter, r *http.Request) { | ||
to := r.FormValue("to") | ||
format := r.FormValue("format") | ||
|
||
body, err := io.ReadAll(r.Body) | ||
if err != nil { | ||
wr.error(err) | ||
return | ||
} | ||
|
||
jAPI, jErr := kit.NewJApiFromFile(fs.NewFile("root", body)) | ||
|
||
if getBoolEnv("JSIGHT_SERVER_STATISTICS") { | ||
clientID := r.Header.Get("X-Browser-UUID") | ||
clientIP := getIP(r) | ||
sendDatagram(clientID, clientIP, len(body), jAPI, jErr) | ||
} | ||
|
||
if jErr != nil { | ||
wr.error(jErr) | ||
return | ||
} | ||
|
||
switch to { | ||
case "jdoc-2.0": | ||
switch format { | ||
case "json", "": | ||
writeJDocJSON(wr, jAPI) | ||
return | ||
default: | ||
wr.errorStr("not supported format") | ||
return | ||
} | ||
case "openapi-3.0.3": | ||
switch format { | ||
case "json", "": | ||
writeOpenapiJSON(wr, jAPI) | ||
return | ||
case "yaml": | ||
writeOpenapiYAML(wr, jAPI) | ||
return | ||
default: | ||
wr.errorStr("not supported format") | ||
return | ||
} | ||
default: | ||
wr.errorStr(`you must specify the "to" parameter`) | ||
return | ||
} | ||
} | ||
|
||
func writeJDocJSON(wr httpResponseWriter, jAPI kit.JApi) { | ||
resp, err := jdocJSON(jAPI) | ||
if err != nil { | ||
wr.error(err) | ||
return | ||
} | ||
|
||
wr.jdocJSON(resp) | ||
} | ||
|
||
func writeOpenapiJSON(wr httpResponseWriter, jAPI kit.JApi) { | ||
resp, err := openapiJSON(jAPI) | ||
if err != nil { | ||
wr.error(err) | ||
return | ||
} | ||
|
||
wr.json(resp) | ||
} | ||
|
||
func writeOpenapiYAML(wr httpResponseWriter, jAPI kit.JApi) { | ||
resp, err := openapiYAML(jAPI) | ||
if err != nil { | ||
wr.error(err) | ||
return | ||
} | ||
|
||
wr.yaml(resp) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
"strconv" | ||
|
||
"github.com/jsightapi/datagram" | ||
|
||
"github.com/jsightapi/jsight-api-core/jerr" | ||
"github.com/jsightapi/jsight-api-core/kit" | ||
) | ||
|
||
func sendDatagram(clientID, clientIP string, projectSize int, j kit.JApi, je *jerr.JApiError) { | ||
d := datagram.New() | ||
d.Append("cid", clientID) | ||
d.Append("cip", clientIP) | ||
d.Append("at", "1") // Application Type | ||
d.AppendTruncatable("pt", j.Title()) // Project title | ||
d.Append("ps", strconv.Itoa(projectSize)) // Project size | ||
if je != nil { | ||
d.AppendTruncatable("pem", je.Error()) // Project error message | ||
d.Append("pel", strconv.FormatUint(uint64(je.Line), 10)) // Project error line | ||
d.Append("pei", strconv.FormatUint(uint64(je.Index), 10)) // Project error index | ||
} | ||
|
||
err := sendToStatisticServer(d.Pack()) | ||
if err != nil { | ||
log.Print("... " + err.Error()) | ||
} | ||
} |
Oops, something went wrong.