Skip to content
Snippets Groups Projects
Commit 1c1d62e1 authored by Gospodin Bodurov's avatar Gospodin Bodurov
Browse files

Merge branch '479-image-fetching-optimiation' into 'master'

Implement centralized image fetching logic

See merge request !39
parents 6821eb90 a0672d7e
No related branches found
No related tags found
1 merge request!39Implement centralized image fetching logic
...@@ -38,9 +38,17 @@ func buildPenpalMethods() string { ...@@ -38,9 +38,17 @@ func buildPenpalMethods() string {
prefixes := []string{} prefixes := []string{}
endPoints := server.GetEndPoints(prefixes) endPoints := server.GetEndPoints(prefixes)
result := result := `
"import Penpal from 'penpal';\n\n" + const encodeResponse = (code, data, status) => {
"export default {\n" return {
code,
data,
status
};
};
export default {
`
methods := generatePenpalRemoteMethods(endPoints) methods := generatePenpalRemoteMethods(endPoints)
...@@ -590,31 +598,13 @@ func generatePenpalRemoteMethods(endPoints map[string]*server.EndPoint) string { ...@@ -590,31 +598,13 @@ func generatePenpalRemoteMethods(endPoints map[string]*server.EndPoint) string {
privateCheckSnippet := ` privateCheckSnippet := `
const authenticationPublicKey = localStorage.getItem("authenticatedIdentity"); const authenticationPublicKey = localStorage.getItem("authenticatedIdentity");
if (authenticationPublicKey === null) { if (
result({ !authenticationPublicKey ||
"data" : "", !window.loadedIdentities[authenticationPublicKey] ||
"code" : "400", !extendPinCodeTtl(authenticationPublicKey)
"status" : "Identity not authenticated" ) {
}); return encodeResponse("400", "", "Identity not authenticated");
} }
if (loadedIdentities[authenticationPublicKey] === null) {
result({
"data" : "",
"code" : "400",
"status" : "Identity not authenticated"
});
}
const success = extendPinCodeTtl(authenticationPublicKey);
if(success === false) {
result({"data" : "",
"code" : "400",
"status" : "Identity not authenticated"
})
}
` `
for i := 0; i < keysLen; i++ { for i := 0; i < keysLen; i++ {
...@@ -626,24 +616,14 @@ func generatePenpalRemoteMethods(endPoints map[string]*server.EndPoint) string { ...@@ -626,24 +616,14 @@ func generatePenpalRemoteMethods(endPoints map[string]*server.EndPoint) string {
if url == "/identity/getIdentityProfileData" { if url == "/identity/getIdentityProfileData" {
privateCheckSnippet = ` privateCheckSnippet = `
const authenticationPublicKey = localStorage.getItem("authenticatedIdentity"); const authenticationPublicKey = localStorage.getItem("authenticatedIdentity");
if (authenticationPublicKey === null) { if (
result({ !authenticationPublicKey ||
"data" : "", !window.loadedIdentities[authenticationPublicKey]
"code" : "400", ) {
"status" : "Identity not authenticated" return encodeResponse("400", "", "Identity not authenticated");
}); }
}
if (loadedIdentities[authenticationPublicKey] === null) {
result({
"data" : "",
"code" : "400",
"status" : "Identity not authenticated"
});
}
` `
} }
...@@ -685,12 +665,9 @@ func generatePenpalRemoteMethods(endPoints map[string]*server.EndPoint) string { ...@@ -685,12 +665,9 @@ func generatePenpalRemoteMethods(endPoints map[string]*server.EndPoint) string {
lastComma = "" lastComma = ""
} }
method := packageStr + strings.Title(methodStr) + ": function(" + args + ") {\n" + method := packageStr + strings.Title(methodStr) + ": async function(" + args + ") {\n" +
" return new Penpal.Promise(function(result) {\n" + snippet + snippet +
" executeRestfulFunction(\"" + endPoints[url].HandlerType + "\", viamApi, viamApi." + packageStr + strings.Title(methodStr) + ", null" + lastComma + args + ").then(function(executeResult) {\n" + " return await executeRestfulFunction(\"" + endPoints[url].HandlerType + "\", viamApi, viamApi." + packageStr + strings.Title(methodStr) + ", null" + lastComma + args + ");\n" +
" result(executeResult);\n" +
" });\n" +
" });\n" +
"}" "}"
methods += method methods += method
...@@ -713,12 +690,9 @@ func generatePenpalRemoteMethods(endPoints map[string]*server.EndPoint) string { ...@@ -713,12 +690,9 @@ func generatePenpalRemoteMethods(endPoints map[string]*server.EndPoint) string {
snippet = privateCheckSnippet snippet = privateCheckSnippet
} }
method := packageStr + strings.Title(methodStr) + ": function() {\n" + method := packageStr + strings.Title(methodStr) + ": async function() {\n" +
" return new Penpal.Promise(function(result) {\n" + snippet + snippet +
" executeRestfulFunction(\"" + endPoints[url].HandlerType + "\", viamApi, viamApi." + packageStr + strings.Title(methodStr) + ", null).then(function(executeResult) {\n" + " return await executeRestfulFunction(\"" + endPoints[url].HandlerType + "\", viamApi, viamApi." + packageStr + strings.Title(methodStr) + ", null);\n" +
" result(executeResult);\n" +
" });\n" +
" });\n" +
"}" "}"
methods += method methods += method
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment