Updated docs routing

This commit is contained in:
frikky
2020-05-21 20:49:07 +02:00
parent 4dd558beea
commit 34f7fbe76e
3 changed files with 122 additions and 35 deletions
+38 -18
View File
@@ -3921,6 +3921,14 @@ func setBadMemcache(ctx context.Context, path string) {
//}
}
type Result struct {
Success bool `json:"success"`
Reason string `json:"reason"`
List []string `json:"list"`
}
var docs_list = Result{List: []string{}}
func getDocList(resp http.ResponseWriter, request *http.Request) {
cors := handleCors(resp, request)
if cors {
@@ -3939,11 +3947,24 @@ func getDocList(resp http.ResponseWriter, request *http.Request) {
// return
//}
if len(docs_list.List) > 0 {
b, err := json.Marshal(docs_list)
if err != nil {
log.Printf("Failed marshaling result: %s", err)
//http.Error(resp, err.Error(), 500)
} else {
resp.WriteHeader(200)
resp.Write(b)
return
}
}
client := github.NewClient(nil)
_, item1, _, err := client.Repositories.GetContents(ctx, "shaffuru", "shuffle-docs", "docs", nil)
_, item1, _, err := client.Repositories.GetContents(ctx, "frikky", "shuffle-docs", "docs", nil)
if err != nil {
log.Printf("Github error: %s", err)
resp.WriteHeader(500)
resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "Error listing directory"`)))
resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "Error listing directory: %s"`, err)))
return
}
@@ -3964,16 +3985,12 @@ func getDocList(resp http.ResponseWriter, request *http.Request) {
log.Println(names)
type Result struct {
Success bool `json:"success"`
Reason string `json:"reason"`
List []string `json:"list"`
}
var result Result
result.Success = true
result.Reason = "Success"
result.List = names
docs_list = result
b, err := json.Marshal(result)
if err != nil {
http.Error(resp, err.Error(), 500)
@@ -4001,6 +4018,8 @@ func getDocList(resp http.ResponseWriter, request *http.Request) {
}
// r.HandleFunc("/api/v1/docs/{key}", getDocs).Methods("GET", "OPTIONS")
var alldocs = map[string][]byte{}
func getDocs(resp http.ResponseWriter, request *http.Request) {
cors := handleCors(resp, request)
if cors {
@@ -4016,16 +4035,15 @@ func getDocs(resp http.ResponseWriter, request *http.Request) {
//ctx := context.Background()
docPath := fmt.Sprintf("https://raw.githubusercontent.com/shaffuru/shuffle-docs/master/docs/%s.md", location[4])
//if item, err := memcache.Get(ctx, docPath); err == memcache.ErrCacheMiss {
// // Not in cache
//} else if err != nil {
// // Error with cache
// log.Printf("Error getting item: %v", err)
//} else {
// resp.WriteHeader(200)
// resp.Write([]byte(item.Value))
// return
//}
//location[4]
//var, ok := alldocs["asd"]
key, ok := alldocs[fmt.Sprintf("%s", location[4])]
// Custom cache for github issues lol
if ok {
resp.WriteHeader(200)
resp.Write(key)
return
}
client := &http.Client{}
req, err := http.NewRequest(
@@ -4078,6 +4096,8 @@ func getDocs(resp http.ResponseWriter, request *http.Request) {
return
}
alldocs[location[4]] = b
// Add to cache if it doesn't exist
//item := &memcache.Item{
// Key: docPath,
+4 -4
View File
@@ -338,11 +338,11 @@ const Apps = (props) => {
<div>
<Paper square style={uploadViewPaperStyle}>
<div style={{width: "100%", margin: 25}}>
<h2>App creation</h2>
<Link to="/docs/apps" style={{textDecoration: "none", color: "#f85a3e"}}>What are apps?</Link>
&nbsp;- <a href="https://swagger.io/specification/" style={{textDecoration: "none", color: "#f85a3e"}}>OpenAPI specification</a>
<h2>App Creator</h2>
<a href="https://github.com/frikky/OpenAPI-security-definitions" style={{textDecoration: "none", color: "#f85a3e"}} target="_blank">Security API's</a>
&nbsp;- <a href="https://apis.guru/browse-apis/" style={{textDecoration: "none", color: "#f85a3e"}} target="_blank">OpenAPI directory</a>
<div/>
Apps are how you interact with workflows, and are used to execute workflows. They are created with the app creator, using OpenAPI specification or manually in python.
Apps interact with eachother in workflows. They are created with the app creator, using OpenAPI specification or manually in python. Use the links above to find potential apps you're looking for using OpenAPI or make one from scratch. There's 1000+ available.
<div/>
<div style={{marginTop: 20}}>
<Button
+80 -13
View File
@@ -32,7 +32,7 @@ const hrefStyle = {
}
const Docs = (props) => {
const { isLoaded, globalUrl } = props;
const { isLoaded, globalUrl } = props;
const [data, setData] = useState("");
const [firstrequest, setFirstrequest] = useState(true);
@@ -55,16 +55,81 @@ const Docs = (props) => {
fetchDocs()
return
}
// Continue this, and find the h2 with the data in it lol
if (window.location.hash.length > 0) {
console.log("HELLO")
var parent = document.getElementById("markdown_wrapper")
if (parent !== null) {
var elements = parent.getElementsByTagName('h2')
const name = window.location.hash.slice(1, window.location.hash.lenth).toLowerCase().split("%20").join(" ")
console.log(name)
var found = false
for (var key in elements) {
const element = elements[key]
if (element.innerHTML === undefined) {
continue
}
// Fix location..
if (element.innerHTML.toLowerCase() === name) {
element.scrollIntoView({behavior: "smooth"})
found = true
//element.scrollTo({
// top: element.offsetTop-100,
// behavior: "smooth"
//})
}
}
// H#
if (!found) {
var elements = parent.getElementsByTagName('h3')
console.log(name)
var found = false
for (var key in elements) {
const element = elements[key]
if (element.innerHTML === undefined) {
continue
}
// Fix location..
if (element.innerHTML.toLowerCase() === name) {
element.scrollIntoView({behavior: "smooth"})
found = true
//element.scrollTo({
// top: element.offsetTop-100,
// behavior: "smooth"
//})
}
}
}
}
//console.log(element)
//console.log("NAME: ", name)
//console.log(document.body.innerHTML)
// parent = document.getElementById(parent);
//var descendants = parent.getElementsByTagName(tagname);
// this.scrollDiv.current.scrollIntoView({ behavior: 'smooth' });
//$(".parent").find("h2:contains('Statistics')").parent();
}
})
const fetchDocList = () => {
fetch(globalUrl+"/api/v1/docs", {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
})
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
})
.then((response) => response.json())
.then((responseJson) => {
if (responseJson.success) {
@@ -101,8 +166,8 @@ const Docs = (props) => {
flex: "1",
}
function Link(props) {
return <a href={props.href} style={{color: "#f85a3e", textDecoration: "none"}}>{props.children}</a>
function OuterLink(props) {
return <Link to={props.href} style={{color: "#f85a3e", textDecoration: "none"}}>{props.children}</Link>
}
function Img(props) {
@@ -117,7 +182,7 @@ const Docs = (props) => {
// );
//}
const postDataBrowser =
const postDataBrowser =
<div style={Body}>
<div style={SideBar}>
<ul style={{listStyle: "none", paddingLeft: "0"}}>
@@ -139,11 +204,12 @@ const Docs = (props) => {
})}
</ul>
</div>
<div style={markdownStyle}>
<div id="markdown_wrapper" style={markdownStyle}>
<ReactMarkdown
id="markdown_wrapper"
escapeHtml={false}
source={data}
renderers={{link: Link, image: Img}}
renderers={{link: OuterLink, image: Img}}
/>
</div>
</div>
@@ -180,9 +246,10 @@ const Docs = (props) => {
</Menu>
<div style={markdownStyle}>
<ReactMarkdown
id="markdown_wrapper"
escapeHtml={false}
source={data}
renderers={{link: Link, image: Img}}
renderers={{link: OuterLink, image: Img}}
/>
</div>
<Divider style={{marginTop: "10px", marginBottom: "10px", backgroundColor: dividerColor}}/>