Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
V
Vereign Client Library
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Code
Vereign Client Library
Commits
a311f42e
Commit
a311f42e
authored
6 years ago
by
Alexey Lunin
Browse files
Options
Downloads
Patches
Plain Diff
Implemented passing config to the axios when calling ViamAPI methods
parent
546703fe
No related branches found
No related tags found
1 merge request
!25
Ability to upload a document in Dashboard
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
javascript/package.json
+1
-0
1 addition, 0 deletions
javascript/package.json
javascript/src/iframe/viamapi-iframe.js
+49
-46
49 additions, 46 deletions
javascript/src/iframe/viamapi-iframe.js
main.go
+26
-37
26 additions, 37 deletions
main.go
with
76 additions
and
83 deletions
javascript/package.json
+
1
−
0
View file @
a311f42e
...
...
@@ -28,6 +28,7 @@
"data-uri-to-blob"
:
"^0.0.4"
,
"libmime"
:
"^4.0.1"
,
"libqp"
:
"^1.1.0"
,
"lodash"
:
"^4.17.11"
,
"penpal"
:
"^3.0.3"
,
"pkijs"
:
"^2.1.69"
,
"pvutils"
:
"^1.0.16"
,
...
...
This diff is collapsed.
Click to expand it.
javascript/src/iframe/viamapi-iframe.js
+
49
−
46
View file @
a311f42e
...
...
@@ -97,7 +97,7 @@ function setIdentityInLocalStorage(identityToStore, extendKey = true) {
function
getProfileData
(
identity
)
{
return
new
Penpal
.
Promise
(
executeResultUpper
=>
{
executeRestfulFunction
(
"
private
"
,
viamApi
,
viamApi
.
identityGetIdentityProfileData
).
then
(
executeResult
=>
{
viamApi
.
identityGetIdentityProfileData
,
null
).
then
(
executeResult
=>
{
if
(
executeResult
.
code
===
"
200
"
)
{
var
listItem
=
{};
...
...
@@ -219,22 +219,21 @@ const handleIdentityLogin = (identity, uuid, token) => {
setKeyForUUID
(
uuid
,
publicKey
);
};
function
executeRestfulFunction
(
type
,
that
,
fn
,
...
args
)
{
function
executeRestfulFunction
(
type
,
that
,
fn
,
config
,
...
args
)
{
const
{
currentlyAuthenticatedIdentity
,
viamApi
,
currentlyLoadedIdentity
}
=
window
;
return
new
Penpal
.
Promise
(
executeResult
=>
{
fn
.
apply
(
that
,
args
).
then
((
response
)
=>
{
fn
.
apply
(
that
,
[
config
,
...
args
]
).
then
((
response
)
=>
{
const
identity
=
currentlyAuthenticatedIdentity
||
currentlyLoadedIdentity
;
if
(
type
===
"
private
"
&&
identity
&&
response
.
data
.
code
===
"
400
"
&&
response
.
data
.
status
===
"
Bad session
"
)
{
viamApi
.
identityLogin
(
"
previousaddeddevice
"
)
viamApi
.
identityLogin
(
null
,
"
previousaddeddevice
"
)
.
then
((
response
)
=>
{
if
(
response
.
data
.
code
===
"
200
"
)
{
const
uuid
=
response
.
data
.
data
[
"
Uuid
"
];
const
token
=
response
.
data
.
data
[
"
Session
"
];
handleIdentityLogin
(
identity
,
uuid
,
token
);
// TODO: Previously there was fn.apply(null, args) where null is probably wrong context for fn.apply()
fn
.
apply
(
that
,
args
).
then
(({
data
})
=>
executeResult
(
data
));
fn
.
apply
(
that
,
[
config
,
...
args
]).
then
(({
data
})
=>
executeResult
(
data
));
}
else
{
executeResult
(
response
.
data
);
}
...
...
@@ -345,7 +344,7 @@ function getCertificateForPassport(passportUUID, internal) {
var
certificate
=
keys
[
"
certificatePEM
"
];
//download("passportCertificateBeforeSigning.crt", "text/plain", certificate)
//cryptoData.setx509Certificate(keys["certificate"])
executeRestfulFunction
(
"
private
"
,
viamApi
,
viamApi
.
signSignCertificate
,
btoa
(
certificate
),
passportUUID
).
then
(
executeResult
=>
{
executeRestfulFunction
(
"
private
"
,
viamApi
,
viamApi
.
signSignCertificate
,
null
,
btoa
(
certificate
),
passportUUID
).
then
(
executeResult
=>
{
if
(
executeResult
.
code
===
"
200
"
)
{
var
signedCertificate
=
atob
(
executeResult
.
data
[
"
SignedCertificate
"
]);
//download("passportCertificateAfterSigning.crt", "text/plain", signedCertificate)
...
...
@@ -504,7 +503,7 @@ const connection = Penpal.connectToParent({
return
new
Penpal
.
Promise
(
result
=>
{
viamApi
.
setIdentity
(
identity
.
authentication
.
publicKey
);
executeRestfulFunction
(
"
public
"
,
viamApi
,
viamApi
.
identityConfirmIdentificator
,
confirmationCodeArg
).
then
(
executeResult
=>
{
executeRestfulFunction
(
"
public
"
,
viamApi
,
viamApi
.
identityConfirmIdentificator
,
null
,
confirmationCodeArg
).
then
(
executeResult
=>
{
result
(
executeResult
);
});
});
...
...
@@ -513,7 +512,7 @@ const connection = Penpal.connectToParent({
return
new
Penpal
.
Promise
(
result
=>
{
viamApi
.
setIdentity
(
identity
.
authentication
.
publicKey
);
executeRestfulFunction
(
"
public
"
,
viamApi
,
viamApi
.
identityGetIdentificatorByRegisterToken
,
tokenArg
).
then
(
executeResult
=>
{
executeRestfulFunction
(
"
public
"
,
viamApi
,
viamApi
.
identityGetIdentificatorByRegisterToken
,
null
,
tokenArg
).
then
(
executeResult
=>
{
result
(
executeResult
);
});
});
...
...
@@ -522,7 +521,7 @@ const connection = Penpal.connectToParent({
return
new
Penpal
.
Promise
(
result
=>
{
viamApi
.
setIdentity
(
identity
.
authentication
.
publicKey
);
executeRestfulFunction
(
"
public
"
,
viamApi
,
viamApi
.
identitySubmitIdentificator
,
identificatorArg
,
registerToken
).
then
(
executeResult
=>
{
executeRestfulFunction
(
"
public
"
,
viamApi
,
viamApi
.
identitySubmitIdentificator
,
null
,
identificatorArg
,
registerToken
).
then
(
executeResult
=>
{
result
(
executeResult
);
});
});
...
...
@@ -531,7 +530,7 @@ const connection = Penpal.connectToParent({
return
new
Penpal
.
Promise
(
result
=>
{
viamApi
.
setIdentity
(
identity
.
authentication
.
publicKey
);
executeRestfulFunction
(
"
public
"
,
viamApi
,
viamApi
.
identitySubmitRegisterClaims
,
givennameArg
,
familynameArg
,
emailArg
,
phonenumberArg
).
then
(
executeResult
=>
{
executeRestfulFunction
(
"
public
"
,
viamApi
,
viamApi
.
identitySubmitRegisterClaims
,
null
,
givennameArg
,
familynameArg
,
emailArg
,
phonenumberArg
).
then
(
executeResult
=>
{
result
(
executeResult
);
});
});
...
...
@@ -540,7 +539,7 @@ const connection = Penpal.connectToParent({
return
new
Penpal
.
Promise
(
result
=>
{
viamApi
.
setIdentity
(
registerIdentity
.
authentication
.
publicKey
);
executeRestfulFunction
(
"
public
"
,
viamApi
,
viamApi
.
identityAgreeOnRegistration
).
then
(
executeResult
=>
{
executeRestfulFunction
(
"
public
"
,
viamApi
,
viamApi
.
identityAgreeOnRegistration
,
null
).
then
(
executeResult
=>
{
let
sequence
=
Promise
.
resolve
();
if
(
executeResult
.
code
===
"
200
"
)
{
sequence
=
sequence
.
then
(()
=>
{
...
...
@@ -564,7 +563,7 @@ const connection = Penpal.connectToParent({
return
new
Penpal
.
Promise
(
result
=>
{
viamApi
.
setIdentity
(
identity
.
authentication
.
publicKey
);
executeRestfulFunction
(
"
public
"
,
viamApi
,
viamApi
.
identityResendConfirmationCode
,
identificatorArg
).
then
(
executeResult
=>
{
executeRestfulFunction
(
"
public
"
,
viamApi
,
viamApi
.
identityResendConfirmationCode
,
null
,
identificatorArg
).
then
(
executeResult
=>
{
result
(
executeResult
);
});
});
...
...
@@ -587,6 +586,7 @@ const connection = Penpal.connectToParent({
"
public
"
,
window
.
viamApi
,
window
.
viamApi
.
identityLogin
,
null
,
mode
,
requestCode
,
requestActionID
);
...
...
@@ -637,7 +637,7 @@ const connection = Penpal.connectToParent({
})
}
executeRestfulFunction
(
"
private
"
,
viamApi
,
viamApi
.
identityAddNewDevice
).
then
(
executeResult
=>
{
executeRestfulFunction
(
"
private
"
,
viamApi
,
viamApi
.
identityAddNewDevice
,
null
).
then
(
executeResult
=>
{
if
(
executeResult
.
code
===
"
200
"
)
{
var
actionID
=
executeResult
.
data
[
"
ActionID
"
];
var
QrCode
=
executeResult
.
data
[
"
QrCode
"
];
...
...
@@ -676,7 +676,7 @@ const connection = Penpal.connectToParent({
})
}
executeRestfulFunction
(
"
private
"
,
viamApi
,
viamApi
.
identityDestroyKeysForDevice
,
btoa
(
authenticationPublicKeyArg
)).
then
(
executeResult
=>
{
executeRestfulFunction
(
"
private
"
,
viamApi
,
viamApi
.
identityDestroyKeysForDevice
,
null
,
btoa
(
authenticationPublicKeyArg
)).
then
(
executeResult
=>
{
result
(
executeResult
);
});
});
...
...
@@ -694,7 +694,8 @@ const connection = Penpal.connectToParent({
const
identityLogoutResponse
=
await
executeRestfulFunction
(
"
private
"
,
window
.
viamApi
,
window
.
viamApi
.
identityLogout
window
.
viamApi
.
identityLogout
,
null
);
window
.
viamApi
.
setIdentity
(
""
);
...
...
@@ -715,7 +716,7 @@ const connection = Penpal.connectToParent({
return
new
Penpal
.
Promise
(
result
=>
{
viamApi
.
setIdentity
(
restoreAccessIdentity
.
authentication
.
publicKey
);
executeRestfulFunction
(
"
public
"
,
viamApi
,
viamApi
.
identityRestoreAccess
,
identificator
).
then
(
executeResult
=>
{
executeRestfulFunction
(
"
public
"
,
viamApi
,
viamApi
.
identityRestoreAccess
,
null
,
identificator
).
then
(
executeResult
=>
{
result
(
executeResult
);
});
});
...
...
@@ -880,7 +881,7 @@ const connection = Penpal.connectToParent({
passportChain
.
push
(
passportCertificate
);
response
=
await
executeRestfulFunction
(
"
private
"
,
window
.
viamApi
,
window
.
viamApi
.
passportGetEmailWithHeaderByPassport
,
passportUUID
,
emailMessage
);
"
private
"
,
window
.
viamApi
,
window
.
viamApi
.
passportGetEmailWithHeaderByPassport
,
null
,
passportUUID
,
emailMessage
);
if
(
response
.
code
!==
"
200
"
)
{
return
encodeResponse
(
"
400
"
,
""
,
response
.
status
);
...
...
@@ -889,7 +890,7 @@ const connection = Penpal.connectToParent({
const
signedEmail
=
await
signEmail
(
response
.
data
,
certificateOneTime
,
passportChain
,
privateKeyOneTime
);
response
=
await
executeRestfulFunction
(
"
private
"
,
window
.
viamApi
,
window
.
viamApi
.
signResignEmail
,
passportUUID
,
signedEmail
);
"
private
"
,
window
.
viamApi
,
window
.
viamApi
.
signResignEmail
,
null
,
passportUUID
,
signedEmail
);
if
(
response
.
code
!==
"
200
"
)
{
return
encodeResponse
(
"
400
"
,
""
,
response
.
status
);
...
...
@@ -897,7 +898,7 @@ const connection = Penpal.connectToParent({
return
encodeResponse
(
"
200
"
,
response
.
data
,
"
Email signed
"
);
},
c
reateDocument
:
async
(
path
,
passportUUID
,
contenttype
)
=>
{
documentC
reateDocument
:
async
(
path
,
passportUUID
,
contenttype
)
=>
{
const
authenticationPublicKey
=
localStorage
.
getItem
(
"
authenticatedIdentity
"
);
if
(
!
authenticationPublicKey
||
...
...
@@ -907,17 +908,19 @@ const connection = Penpal.connectToParent({
return
encodeResponse
(
"
400
"
,
""
,
"
Identity not authenticated
"
);
}
const
headers
=
window
.
viamApi
.
getConfig
().
headers
;
headers
.
path
=
path
;
headers
.
passportuuid
=
passportUUID
;
headers
.
contenttype
=
contenttype
;
const
response
=
await
executeRestfulFunction
(
"
private
"
,
window
.
viamApi
,
window
.
viamApi
.
documentCreateDocument
);
const
config
=
{
headers
:
{
path
,
passportuuid
:
passportUUID
,
contenttype
}
};
const
response
=
await
executeRestfulFunction
(
"
private
"
,
window
.
viamApi
,
window
.
viamApi
.
documentCreateDocument
,
config
);
return
encodeResponse
(
"
200
"
,
response
.
data
,
"
Document created
"
);
},
p
utDocument
:
async
(
passportUUID
,
resourceid
,
file
)
=>
{
documentP
utDocument
:
async
(
passportUUID
,
resourceid
,
file
)
=>
{
const
authenticationPublicKey
=
localStorage
.
getItem
(
"
authenticatedIdentity
"
);
if
(
!
authenticationPublicKey
||
...
...
@@ -927,16 +930,16 @@ const connection = Penpal.connectToParent({
return
encodeResponse
(
"
400
"
,
""
,
"
Identity not authenticated
"
);
}
const
data
=
new
FormData
();
data
.
append
(
'
file
'
,
file
);
const
config
=
window
.
viamApi
.
getConfig
();
config
.
headers
.
passportuuid
=
passportUUID
;
config
.
headers
.
resourceid
=
resourceid
;
config
.
data
=
data
;
const
config
=
{
headers
:
{
'
Content-Type
'
:
'
multipart/form-data
'
,
passportuuid
:
passportUUID
,
resourceid
}
}
;
const
response
=
await
executeRestfulFunction
(
"
private
"
,
window
.
viamApi
,
window
.
viamApi
.
document
Create
Document
);
"
private
"
,
window
.
viamApi
,
window
.
viamApi
.
document
Put
Document
,
config
,
file
);
return
encodeResponse
(
"
200
"
,
response
.
data
,
"
Document created
"
);
},
...
...
@@ -965,7 +968,7 @@ const connection = Penpal.connectToParent({
})
}
executeRestfulFunction
(
"
private
"
,
viamApi
,
viamApi
.
identityHasSession
).
then
(
executeResult
=>
{
executeRestfulFunction
(
"
private
"
,
viamApi
,
viamApi
.
identityHasSession
,
null
).
then
(
executeResult
=>
{
result
(
executeResult
);
});
});
...
...
@@ -974,7 +977,7 @@ const connection = Penpal.connectToParent({
return
new
Penpal
.
Promise
(
result
=>
{
viamApi
.
setIdentity
(
"
marketingapppublickey
"
);
executeRestfulFunction
(
"
public
"
,
viamApi
,
viamApi
.
marketingSignUpIdentificator
,
identificator
,
reference
).
then
(
executeResult
=>
{
executeRestfulFunction
(
"
public
"
,
viamApi
,
viamApi
.
marketingSignUpIdentificator
,
null
,
identificator
,
reference
).
then
(
executeResult
=>
{
viamApi
.
setIdentity
(
""
);
viamApi
.
setSessionData
(
""
,
""
);
result
(
executeResult
);
...
...
@@ -985,7 +988,7 @@ const connection = Penpal.connectToParent({
return
new
Penpal
.
Promise
(
result
=>
{
viamApi
.
setIdentity
(
"
marketingapppublickey
"
);
executeRestfulFunction
(
"
public
"
,
viamApi
,
viamApi
.
marketingGetIdentificatorProfile
,
identificator
,
pincode
).
then
(
executeResult
=>
{
executeRestfulFunction
(
"
public
"
,
viamApi
,
viamApi
.
marketingGetIdentificatorProfile
,
null
,
identificator
,
pincode
).
then
(
executeResult
=>
{
viamApi
.
setIdentity
(
""
);
viamApi
.
setSessionData
(
""
,
""
);
result
(
executeResult
);
...
...
@@ -996,7 +999,7 @@ const connection = Penpal.connectToParent({
return
new
Penpal
.
Promise
(
result
=>
{
viamApi
.
setIdentity
(
"
marketingapppublickey
"
);
executeRestfulFunction
(
"
public
"
,
viamApi
,
viamApi
.
marketingExecuteEventForIdentificator
,
identificator
,
pincode
,
event
).
then
(
executeResult
=>
{
executeRestfulFunction
(
"
public
"
,
viamApi
,
viamApi
.
marketingExecuteEventForIdentificator
,
null
,
identificator
,
pincode
,
event
).
then
(
executeResult
=>
{
viamApi
.
setIdentity
(
""
);
viamApi
.
setSessionData
(
""
,
""
);
result
(
executeResult
);
...
...
@@ -1211,7 +1214,7 @@ connection.promise.then(parent => {
setInterval
(
function
()
{
if
(
window
.
currentlyLoadedIdentity
&&
!
anynomousDeviceKeyEventsProcessing
&&
!
window
.
currentlyAuthenticatedIdentity
)
{
anynomousDeviceKeyEventsProcessing
=
true
;
executeRestfulFunction
(
"
public
"
,
viamAnonymousApi
,
viamAnonymousApi
.
eventGetNewEventsWithoutSession
,
"
devicekey
"
).
then
(
async
executeResult
=>
{
executeRestfulFunction
(
"
public
"
,
viamAnonymousApi
,
viamAnonymousApi
.
eventGetNewEventsWithoutSession
,
null
,
"
devicekey
"
).
then
(
async
executeResult
=>
{
if
(
executeResult
.
code
===
"
200
"
)
{
var
eventsLen
=
executeResult
.
data
.
length
;
let
changedMaxDeviceKeyAnonymousEventTime
=
false
;
...
...
@@ -1270,7 +1273,7 @@ connection.promise.then(parent => {
if
(
changedMaxDeviceKeyAnonymousEventTime
)
{
executeRestfulFunction
(
"
public
"
,
viamAnonymousApi
,
viamAnonymousApi
.
eventUpdateLastViewedWithoutSession
,
"
devicekey
"
,
maxDeviceKeyAnonymousEventTime
.
toString
()).
then
(()
=>
{
null
,
"
devicekey
"
,
maxDeviceKeyAnonymousEventTime
.
toString
()).
then
(()
=>
{
anynomousDeviceKeyEventsProcessing
=
false
;
});
}
else
{
...
...
@@ -1284,7 +1287,7 @@ connection.promise.then(parent => {
if
(
window
.
currentlyAuthenticatedIdentity
!=
null
&&
eventsDeviceEventsProcessing
===
false
)
{
eventsDeviceEventsProcessing
=
true
;
executeRestfulFunction
(
"
private
"
,
viamApi
,
viamApi
.
eventGetNewEvents
,
"
devicekey
"
).
then
(
executeResult
=>
{
executeRestfulFunction
(
"
private
"
,
viamApi
,
viamApi
.
eventGetNewEvents
,
null
,
"
devicekey
"
).
then
(
executeResult
=>
{
if
(
executeResult
.
code
===
"
200
"
)
{
var
eventsLen
=
executeResult
.
data
.
length
;
const
changedMaxDeviceKeyEventTime
=
false
;
...
...
@@ -1306,7 +1309,7 @@ connection.promise.then(parent => {
maxDeviceKeyEventTime
=
Math
.
max
(
maxDeviceKeyEventTime
,
event
.
stamp
)
}
if
(
changedMaxDeviceKeyEventTime
)
{
executeRestfulFunction
(
"
private
"
,
viamApi
,
viamApi
.
eventUpdateLastViewed
,
"
devicekey
"
,
executeRestfulFunction
(
"
private
"
,
viamApi
,
viamApi
.
eventUpdateLastViewed
,
null
,
"
devicekey
"
,
maxDeviceKeyEventTime
.
toString
()).
then
(
executeResult1
=>
{
eventsDeviceEventsProcessing
=
false
})
...
...
@@ -1321,7 +1324,7 @@ connection.promise.then(parent => {
if
(
window
.
currentlyAuthenticatedIdentity
!=
null
&&
eventsEntityEventsProcessing
===
false
)
{
eventsEntityEventsProcessing
=
true
;
executeRestfulFunction
(
"
private
"
,
viamApi
,
viamApi
.
eventGetNewEvents
,
"
entity
"
).
then
(
executeResult
=>
{
executeRestfulFunction
(
"
private
"
,
viamApi
,
viamApi
.
eventGetNewEvents
,
null
,
"
entity
"
).
then
(
executeResult
=>
{
if
(
executeResult
.
code
===
"
200
"
)
{
var
eventsLen
=
executeResult
.
data
.
length
;
let
changedMaxEntityEventTime
=
false
;
...
...
@@ -1346,7 +1349,7 @@ connection.promise.then(parent => {
maxEntityEventTime
=
Math
.
max
(
maxEntityEventTime
,
event
.
stamp
)
}
if
(
changedMaxEntityEventTime
)
{
executeRestfulFunction
(
"
private
"
,
viamApi
,
viamApi
.
eventUpdateLastViewed
,
"
entity
"
,
executeRestfulFunction
(
"
private
"
,
viamApi
,
viamApi
.
eventUpdateLastViewed
,
null
,
"
entity
"
,
maxEntityEventTime
.
toString
()).
then
(
executeResult1
=>
{
eventsEntityEventsProcessing
=
false
})
...
...
This diff is collapsed.
Click to expand it.
main.go
+
26
−
37
View file @
a311f42e
...
...
@@ -57,6 +57,7 @@ func buildViamAPI() string {
endPoints
:=
server
.
GetEndPoints
(
prefixes
)
result
:=
"const axios = require('axios');
\n
"
result
+=
"const merge = require('lodash/merge');
\n
"
var
keys
[]
string
for
k
:=
range
endPoints
{
...
...
@@ -103,11 +104,6 @@ func buildViamAPI() string {
packageStr
:=
splits
[
len
(
splits
)
-
2
]
/*if !packageCreated[packageStr] {
result += "ViamAPI.prototype.\"" + packageStr + "\" = {}\n\n"
packageCreated[packageStr] = true
}*/
methodStr
:=
splits
[
len
(
splits
)
-
1
]
form
:=
endPoints
[
url
]
.
Form
...
...
@@ -129,7 +125,7 @@ func buildViamAPI() string {
}
}
result
+=
"ViamAPI.prototype."
+
packageStr
+
strings
.
Title
(
methodStr
)
+
" = function("
+
args
+
") {
\n
"
+
result
+=
"ViamAPI.prototype."
+
packageStr
+
strings
.
Title
(
methodStr
)
+
" = function(
config,
"
+
args
+
") {
\n
"
+
" return axios.post(window.API_HOST + '"
+
packageStr
+
"/"
+
methodStr
+
"', {
\n
"
for
i
:=
0
;
i
<
lenFields
;
i
++
{
...
...
@@ -140,7 +136,7 @@ func buildViamAPI() string {
result
+=
"
\n
"
}
result
+=
" }, this.config);
\n
"
+
result
+=
" },
merge(
this.config
, config)
);
\n
"
+
"};
\n\n
"
}
else
{
splits
:=
strings
.
Split
(
url
,
"/"
)
...
...
@@ -154,8 +150,8 @@ func buildViamAPI() string {
methodStr
:=
splits
[
len
(
splits
)
-
1
]
result
+=
"ViamAPI.prototype."
+
packageStr
+
strings
.
Title
(
methodStr
)
+
" = function() {
\n
"
+
" return axios.post(window.API_HOST + '"
+
packageStr
+
"/"
+
methodStr
+
"',
{},
this.config);
\n
"
+
result
+=
"ViamAPI.prototype."
+
packageStr
+
strings
.
Title
(
methodStr
)
+
" = function(
config, data
) {
\n
"
+
" return axios.post(window.API_HOST + '"
+
packageStr
+
"/"
+
methodStr
+
"',
data, merge(
this.config
, config)
);
\n
"
+
"};
\n\n
"
}
}
...
...
@@ -589,7 +585,7 @@ func generatePenpalRemoteMethods(endPoints map[string]*server.EndPoint) string {
privateCheckSnippet
:=
`
const authenticationPublicKey = localStorage.getItem("authenticatedIdentity");
if (authenticationPublicKey === null) {
result({
"data" : "",
...
...
@@ -597,15 +593,15 @@ func generatePenpalRemoteMethods(endPoints map[string]*server.EndPoint) string {
"status" : "Identity not authenticated"
});
}
if (loadedIdentities[authenticationPublicKey] === null) {
result({
"data" : "",
"code" : "400",
"status" : "Identity not authenticated"
});
}
}
const success = extendPinCodeTtl(authenticationPublicKey);
if(success === false) {
...
...
@@ -614,7 +610,7 @@ func generatePenpalRemoteMethods(endPoints map[string]*server.EndPoint) string {
"status" : "Identity not authenticated"
})
}
`
for
i
:=
0
;
i
<
keysLen
;
i
++
{
...
...
@@ -624,10 +620,18 @@ func generatePenpalRemoteMethods(endPoints map[string]*server.EndPoint) string {
continue
}
if
endPoints
[
url
]
.
Url
==
"/document/createDocument"
{
continue
}
if
endPoints
[
url
]
.
Url
==
"/document/putDocument"
{
continue
}
if
url
==
"/identity/getIdentityProfileData"
{
privateCheckSnippet
=
`
const authenticationPublicKey = localStorage.getItem("authenticatedIdentity");
if (authenticationPublicKey === null) {
result({
"data" : "",
...
...
@@ -635,15 +639,15 @@ func generatePenpalRemoteMethods(endPoints map[string]*server.EndPoint) string {
"status" : "Identity not authenticated"
});
}
if (loadedIdentities[authenticationPublicKey] === null) {
result({
"data" : "",
"code" : "400",
"status" : "Identity not authenticated"
});
}
}
`
}
...
...
@@ -652,11 +656,6 @@ func generatePenpalRemoteMethods(endPoints map[string]*server.EndPoint) string {
packageStr
:=
splits
[
len
(
splits
)
-
2
]
/*if !packageCreated[packageStr] {
result += "ViamAPI.prototype.\"" + packageStr + "\" = {}\n\n"
packageCreated[packageStr] = true
}*/
methodStr
:=
splits
[
len
(
splits
)
-
1
]
form
:=
endPoints
[
url
]
.
Form
...
...
@@ -678,11 +677,6 @@ func generatePenpalRemoteMethods(endPoints map[string]*server.EndPoint) string {
}
}
/*identity_login(modeArg,codeArg,actionIDArg) {
return new Penpal.Promise(result => {
viamApi.identity_login(modeArg,codeArg,actionIDArg).then((response) => { result(response.data);});
});
}*/
snippet
:=
""
...
...
@@ -698,7 +692,7 @@ func generatePenpalRemoteMethods(endPoints map[string]*server.EndPoint) string {
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
)
+
lastComma
+
args
+
").then(function(executeResult) {
\n
"
+
" executeRestfulFunction(
\"
"
+
endPoints
[
url
]
.
HandlerType
+
"
\"
, viamApi, viamApi."
+
packageStr
+
strings
.
Title
(
methodStr
)
+
", null"
+
lastComma
+
args
+
").then(function(executeResult) {
\n
"
+
" result(executeResult);
\n
"
+
" });
\n
"
+
" });
\n
"
+
...
...
@@ -716,11 +710,6 @@ func generatePenpalRemoteMethods(endPoints map[string]*server.EndPoint) string {
packageStr
:=
splits
[
len
(
splits
)
-
2
]
/*if !packageCreated[packageStr] {
result += "ViamAPI.prototype.\"" + packageStr + "\" = {}\n\n"
packageCreated[packageStr] = true
}*/
methodStr
:=
splits
[
len
(
splits
)
-
1
]
snippet
:=
""
...
...
@@ -731,7 +720,7 @@ func generatePenpalRemoteMethods(endPoints map[string]*server.EndPoint) string {
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
)
+
").then(function(executeResult) {
\n
"
+
" executeRestfulFunction(
\"
"
+
endPoints
[
url
]
.
HandlerType
+
"
\"
, viamApi, viamApi."
+
packageStr
+
strings
.
Title
(
methodStr
)
+
"
, null
).then(function(executeResult) {
\n
"
+
" result(executeResult);
\n
"
+
" });
\n
"
+
" });
\n
"
+
...
...
@@ -762,7 +751,7 @@ func getWopiAPIPenpalMethods() string {
"status" : "Identity not authenticated"
});
}
if (loadedIdentities[authenticationPublicKey] === null) {
result({
"data" : "",
...
...
@@ -770,7 +759,7 @@ func getWopiAPIPenpalMethods() string {
"status" : "Identity not authenticated"
});
}
const success = extendPinCodeTtl(authenticationPublicKey);
if (success === false) {
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment