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 {
prefixes := []string{}
endPoints := server.GetEndPoints(prefixes)
result :=
"import Penpal from 'penpal';\n\n" +
"export default {\n"
result := `
const encodeResponse = (code, data, status) => {
return {
code,
data,
status
};
};
export default {
`
methods := generatePenpalRemoteMethods(endPoints)
......@@ -590,31 +598,13 @@ func generatePenpalRemoteMethods(endPoints map[string]*server.EndPoint) string {
privateCheckSnippet := `
const authenticationPublicKey = localStorage.getItem("authenticatedIdentity");
if (authenticationPublicKey === null) {
result({
"data" : "",
"code" : "400",
"status" : "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"
})
}
if (
!authenticationPublicKey ||
!window.loadedIdentities[authenticationPublicKey] ||
!extendPinCodeTtl(authenticationPublicKey)
) {
return encodeResponse("400", "", "Identity not authenticated");
}
`
for i := 0; i < keysLen; i++ {
......@@ -626,24 +616,14 @@ func generatePenpalRemoteMethods(endPoints map[string]*server.EndPoint) string {
if url == "/identity/getIdentityProfileData" {
privateCheckSnippet = `
const authenticationPublicKey = localStorage.getItem("authenticatedIdentity");
if (authenticationPublicKey === null) {
result({
"data" : "",
"code" : "400",
"status" : "Identity not authenticated"
});
}
if (loadedIdentities[authenticationPublicKey] === null) {
result({
"data" : "",
"code" : "400",
"status" : "Identity not authenticated"
});
}
const authenticationPublicKey = localStorage.getItem("authenticatedIdentity");
if (
!authenticationPublicKey ||
!window.loadedIdentities[authenticationPublicKey]
) {
return encodeResponse("400", "", "Identity not authenticated");
}
`
}
......@@ -685,12 +665,9 @@ func generatePenpalRemoteMethods(endPoints map[string]*server.EndPoint) string {
lastComma = ""
}
method := packageStr + strings.Title(methodStr) + ": function(" + args + ") {\n" +
" return new Penpal.Promise(function(result) {\n" + snippet +
" executeRestfulFunction(\"" + endPoints[url].HandlerType + "\", viamApi, viamApi." + packageStr + strings.Title(methodStr) + ", null" + lastComma + args + ").then(function(executeResult) {\n" +
" result(executeResult);\n" +
" });\n" +
" });\n" +
method := packageStr + strings.Title(methodStr) + ": async function(" + args + ") {\n" +
snippet +
" return await executeRestfulFunction(\"" + endPoints[url].HandlerType + "\", viamApi, viamApi." + packageStr + strings.Title(methodStr) + ", null" + lastComma + args + ");\n" +
"}"
methods += method
......@@ -713,12 +690,9 @@ func generatePenpalRemoteMethods(endPoints map[string]*server.EndPoint) string {
snippet = privateCheckSnippet
}
method := packageStr + strings.Title(methodStr) + ": function() {\n" +
" return new Penpal.Promise(function(result) {\n" + snippet +
" executeRestfulFunction(\"" + endPoints[url].HandlerType + "\", viamApi, viamApi." + packageStr + strings.Title(methodStr) + ", null).then(function(executeResult) {\n" +
" result(executeResult);\n" +
" });\n" +
" });\n" +
method := packageStr + strings.Title(methodStr) + ": async function() {\n" +
snippet +
" return await executeRestfulFunction(\"" + endPoints[url].HandlerType + "\", viamApi, viamApi." + packageStr + strings.Title(methodStr) + ", null);\n" +
"}"
methods += method
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment