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
12fd418e
Commit
12fd418e
authored
6 years ago
by
Alexey Lunin
Browse files
Options
Downloads
Plain Diff
Merge branch 'master' into 469-fix-pull-gravatar-refactoring
parents
56ede58d
82515813
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!33
Make identityPullAvatarFromGravatar automatically generated
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
javascript/src/iframe/viamapi-iframe.js
+93
-109
93 additions, 109 deletions
javascript/src/iframe/viamapi-iframe.js
javascript/src/iframe/wopiapi-iframe.js
+2
-1
2 additions, 1 deletion
javascript/src/iframe/wopiapi-iframe.js
with
95 additions
and
110 deletions
javascript/src/iframe/viamapi-iframe.js
+
93
−
109
View file @
12fd418e
...
@@ -246,43 +246,34 @@ const handleIdentityLogin = (identity, uuid, token) => {
...
@@ -246,43 +246,34 @@ const handleIdentityLogin = (identity, uuid, token) => {
setKeyForUUID
(
uuid
,
publicKey
);
setKeyForUUID
(
uuid
,
publicKey
);
};
};
function
executeRestfulFunction
(
type
,
that
,
fn
,
config
,
...
args
)
{
async
function
executeRestfulFunction
(
type
,
that
,
fn
,
config
,
...
args
)
{
const
{
currentlyAuthenticatedIdentity
,
viamApi
,
currentlyLoadedIdentity
}
=
window
;
const
{
currentlyAuthenticatedIdentity
,
viamApi
,
currentlyLoadedIdentity
}
=
window
;
const
response
=
await
fn
.
apply
(
that
,
[
config
,
...
args
]);
return
new
Penpal
.
Promise
(
executeResult
=>
{
const
identity
=
currentlyAuthenticatedIdentity
||
currentlyLoadedIdentity
;
fn
.
apply
(
that
,
[
config
,
...
args
]).
then
(
async
(
response
)
=>
{
const
{
code
,
status
}
=
response
.
data
;
const
identity
=
currentlyAuthenticatedIdentity
||
currentlyLoadedIdentity
;
const
{
code
,
status
}
=
response
.
data
;
const
deviceRevoked
=
type
===
"
private
"
&&
code
===
"
401
"
&&
status
===
STATUS_DEVICE_REVOKED
;
if
(
deviceRevoked
)
{
destroyIdentity
();
// Destroy local storage in case device was revoked
const
event
=
createEvent
(
""
,
"
DeviceRevoked
"
);
if
(
type
===
"
private
"
&&
code
===
"
401
"
&&
status
===
STATUS_DEVICE_REVOKED
)
{
iframeParent
.
onEvent
(
event
);
destroyIdentity
();
const
event
=
createEvent
(
""
,
"
DeviceRevoked
"
)
;
return
response
.
data
;
iframeParent
.
onEvent
(
event
);
}
return
executeResult
(
response
.
data
)
;
const
badSession
=
type
===
"
private
"
&&
identity
&&
code
===
"
400
"
&&
status
===
"
Bad session
"
;
}
if
(
!
badSession
)
return
response
.
data
;
if
(
type
===
"
private
"
&&
identity
&&
code
===
"
400
"
&&
status
===
"
Bad session
"
)
{
const
loginResponse
=
await
viamApi
.
identityLogin
(
"
previousaddeddevice
"
);
viamApi
.
identityLogin
(
null
,
"
previousaddeddevice
"
)
if
(
loginResponse
.
data
.
code
!==
"
200
"
)
return
loginResponse
.
data
;
.
then
((
response
)
=>
{
if
(
response
.
data
.
code
===
"
200
"
)
{
const
uuid
=
loginResponse
.
data
.
data
[
"
Uuid
"
];
const
uuid
=
response
.
data
.
data
[
"
Uuid
"
];
const
token
=
loginResponse
.
data
.
data
[
"
Session
"
];
const
token
=
response
.
data
.
data
[
"
Session
"
];
handleIdentityLogin
(
identity
,
uuid
,
token
);
handleIdentityLogin
(
identity
,
uuid
,
token
);
const
{
data
}
=
await
fn
.
apply
(
that
,
[
config
,
...
args
]);
fn
.
apply
(
that
,
[
config
,
...
args
]).
then
(({
data
})
=>
executeResult
(
data
));
return
data
;
}
else
{
executeResult
(
response
.
data
);
}
})
.
catch
(
console
.
warn
);
}
else
{
executeResult
(
response
.
data
);
}
});
});
}
}
window
.
executeRestfulFunction
=
executeRestfulFunction
;
window
.
executeRestfulFunction
=
executeRestfulFunction
;
...
@@ -1215,17 +1206,17 @@ connection.promise.then(parent => {
...
@@ -1215,17 +1206,17 @@ connection.promise.then(parent => {
}
}
}
}
var
anynomousDeviceKeyEventsProcessing
=
false
;
let
anynomousDeviceKeyEventsProcessing
=
false
;
var
maxDeviceKeyAnonymousEventTime
=
0
;
let
maxDeviceKeyAnonymousEventTime
=
0
;
var
eventsDeviceEventsProcessing
=
false
;
let
eventsDeviceEventsProcessing
=
false
;
var
maxDeviceKeyEventTime
=
0
;
let
maxDeviceKeyEventTime
=
0
;
var
eventsEntityEventsProcessing
=
false
;
let
eventsEntityEventsProcessing
=
false
;
var
maxEntityEventTime
=
0
;
let
maxEntityEventTime
=
0
;
var
identityLoadedEvent
=
false
;
let
identityLoadedEvent
=
false
;
var
identityAuthenticatedEvent
=
false
;
let
identityAuthenticatedEvent
=
false
;
setInterval
(
async
function
()
{
setInterval
(
async
function
()
{
if
(
window
.
currentlyAuthenticatedIdentity
)
{
if
(
window
.
currentlyAuthenticatedIdentity
)
{
...
@@ -1264,7 +1255,7 @@ connection.promise.then(parent => {
...
@@ -1264,7 +1255,7 @@ connection.promise.then(parent => {
if
(
!
pinCode
)
{
if
(
!
pinCode
)
{
if
(
!
identityLoadedEvent
)
{
if
(
!
identityLoadedEvent
)
{
const
result
=
await
loadIdentityInternal
(
window
.
currentlyLoadedIdentity
.
authentication
.
publicKey
,
"
00000000
"
);
const
result
=
await
loadIdentityInternal
(
window
.
currentlyLoadedIdentity
.
authentication
.
publicKey
,
"
00000000
"
);
if
(
result
.
code
!==
"
200
"
)
{
if
(
window
.
currentlyLoadedIdentity
&&
result
.
code
!==
"
200
"
)
{
const
event
=
createEvent
(
"
CanNotLoadPincodeForLoadedIdentity
"
,
"
IdentityNotLoaded
"
,
[
window
.
currentlyLoadedIdentity
.
authentication
.
publicKey
]);
const
event
=
createEvent
(
"
CanNotLoadPincodeForLoadedIdentity
"
,
"
IdentityNotLoaded
"
,
[
window
.
currentlyLoadedIdentity
.
authentication
.
publicKey
]);
parent
.
onEvent
(
event
);
parent
.
onEvent
(
event
);
identityLoadedEvent
=
true
;
identityLoadedEvent
=
true
;
...
@@ -1284,15 +1275,16 @@ connection.promise.then(parent => {
...
@@ -1284,15 +1275,16 @@ connection.promise.then(parent => {
}
}
},
50
);
},
50
);
setInterval
(
function
()
{
setInterval
(
async
()
=>
{
if
(
window
.
currentlyLoadedIdentity
&&
!
anynomousDeviceKeyEventsProcessing
&&
!
window
.
currentlyAuthenticatedIdentity
)
{
if
(
window
.
currentlyLoadedIdentity
&&
!
anynomousDeviceKeyEventsProcessing
&&
!
window
.
currentlyAuthenticatedIdentity
)
{
anynomousDeviceKeyEventsProcessing
=
true
;
anynomousDeviceKeyEventsProcessing
=
true
;
executeRestfulFunction
(
"
public
"
,
viamAnonymousApi
,
viamAnonymousApi
.
eventGetNewEventsWithoutSession
,
null
,
"
devicekey
"
).
then
(
async
executeResult
=>
{
try
{
const
executeResult
=
await
executeRestfulFunction
(
"
public
"
,
viamAnonymousApi
,
viamAnonymousApi
.
eventGetNewEventsWithoutSession
,
null
,
"
devicekey
"
);
if
(
executeResult
.
code
===
"
200
"
)
{
if
(
executeResult
.
code
===
"
200
"
)
{
var
eventsLen
=
executeResult
.
data
.
length
;
const
eventsLen
=
executeResult
.
data
.
length
;
let
changedMaxDeviceKeyAnonymousEventTime
=
false
;
let
changedMaxDeviceKeyAnonymousEventTime
=
false
;
for
(
var
i
=
0
;
i
<
eventsLen
;
i
++
)
{
for
(
let
i
=
0
;
i
<
eventsLen
;
i
++
)
{
var
event
=
executeResult
.
data
[
i
];
const
event
=
executeResult
.
data
[
i
];
switch
(
event
.
type
)
{
switch
(
event
.
type
)
{
case
"
Authenticated
"
:
{
case
"
Authenticated
"
:
{
const
uuid
=
event
.
payloads
[
0
];
const
uuid
=
event
.
payloads
[
0
];
...
@@ -1300,25 +1292,23 @@ connection.promise.then(parent => {
...
@@ -1300,25 +1292,23 @@ connection.promise.then(parent => {
handleIdentityLogin
(
window
.
currentlyLoadedIdentity
,
uuid
,
token
);
handleIdentityLogin
(
window
.
currentlyLoadedIdentity
,
uuid
,
token
);
const
identityToStore
=
window
.
currentlyAuthenticatedIdentity
;
const
identityToStore
=
window
.
currentlyAuthenticatedIdentity
;
event
.
payloads
=
[{
fromQRCode
:
true
}];
event
.
payloads
=
[{
fromQRCode
:
true
}];
setIdentityInLocalStorage
(
identityToStore
).
then
(()
=>
{
await
setIdentityInLocalStorage
(
identityToStore
);
getProfileData
(
identityToStore
).
then
(()
=>
{
await
getProfileData
(
identityToStore
);
parent
.
onEvent
(
event
);
parent
.
onEvent
(
event
);
});
});
break
;
break
;
}
}
case
"
QRCodeUpdated
"
:
{
case
"
QRCodeUpdated
"
:
{
var
actionID
=
event
[
"
actionID
"
];
const
actionID
=
event
[
"
actionID
"
];
var
QrCode
=
event
[
"
payloads
"
][
1
];
const
QrCode
=
event
[
"
payloads
"
][
1
];
var
eventCopy
=
JSON
.
parse
(
JSON
.
stringify
(
event
));
const
eventCopy
=
JSON
.
parse
(
JSON
.
stringify
(
event
));
QRCode
.
toDataURL
(
actionID
+
"
,
"
+
QrCode
,
function
(
err
,
url
)
{
QRCode
.
toDataURL
(
actionID
+
"
,
"
+
QrCode
,
function
(
err
,
url
)
{
eventCopy
[
"
payloads
"
].
push
(
url
);
eventCopy
[
"
payloads
"
].
push
(
url
);
parent
.
onEvent
(
eventCopy
)
parent
.
onEvent
(
eventCopy
)
;
});
});
break
break
;
}
}
case
"
KeyDeleted
"
:
{
case
"
KeyDeleted
"
:
{
...
@@ -1333,106 +1323,100 @@ connection.promise.then(parent => {
...
@@ -1333,106 +1323,100 @@ connection.promise.then(parent => {
window
.
lastTimeGetProfile
=
0
;
window
.
lastTimeGetProfile
=
0
;
destroyIdentityFromLocalStorage
(
authenticationPublicKey
);
destroyIdentityFromLocalStorage
(
authenticationPublicKey
);
break
break
;
}
}
default
:
{
default
:
{
parent
.
onEvent
(
event
)
parent
.
onEvent
(
event
)
;
}
}
}
}
changedMaxDeviceKeyAnonymousEventTime
=
true
;
changedMaxDeviceKeyAnonymousEventTime
=
true
;
maxDeviceKeyAnonymousEventTime
=
Math
.
max
(
maxDeviceKeyAnonymousEventTime
,
event
.
stamp
)
maxDeviceKeyAnonymousEventTime
=
Math
.
max
(
maxDeviceKeyAnonymousEventTime
,
event
.
stamp
)
;
}
}
if
(
changedMaxDeviceKeyAnonymousEventTime
)
{
if
(
changedMaxDeviceKeyAnonymousEventTime
)
{
executeRestfulFunction
(
"
public
"
,
viamAnonymousApi
,
viamAnonymousApi
.
eventUpdateLastViewedWithoutSession
,
await
executeRestfulFunction
(
"
public
"
,
viamAnonymousApi
,
viamAnonymousApi
.
eventUpdateLastViewedWithoutSession
,
null
,
"
devicekey
"
,
maxDeviceKeyAnonymousEventTime
.
toString
()).
then
(()
=>
{
null
,
"
devicekey
"
,
maxDeviceKeyAnonymousEventTime
.
toString
());
anynomousDeviceKeyEventsProcessing
=
false
;
});
}
else
{
anynomousDeviceKeyEventsProcessing
=
false
;
}
}
}
else
{
anynomousDeviceKeyEventsProcessing
=
false
;
}
}
});
}
catch
(
e
)
{
console
.
warn
(
e
);
}
anynomousDeviceKeyEventsProcessing
=
false
;
}
}
if
(
window
.
currentlyAuthenticatedIdentity
!=
null
&&
eventsDeviceEventsProcessing
===
false
)
{
if
(
window
.
currentlyAuthenticatedIdentity
!=
null
&&
eventsDeviceEventsProcessing
===
false
)
{
eventsDeviceEventsProcessing
=
true
;
eventsDeviceEventsProcessing
=
true
;
executeRestfulFunction
(
"
private
"
,
viamApi
,
viamApi
.
eventGetNewEvents
,
null
,
"
devicekey
"
).
then
(
executeResult
=>
{
try
{
if
(
executeResult
.
code
===
"
200
"
)
{
const
executeResult
=
await
executeRestfulFunction
(
"
private
"
,
viamApi
,
viamApi
.
eventGetNewEvents
,
null
,
"
devicekey
"
);
var
eventsLen
=
executeResult
.
data
.
length
;
if
(
executeResult
.
code
===
"
200
"
)
{
const
eventsLen
=
executeResult
.
data
.
length
;
const
changedMaxDeviceKeyEventTime
=
false
;
const
changedMaxDeviceKeyEventTime
=
false
;
for
(
var
i
=
0
;
i
<
eventsLen
;
i
++
)
{
for
(
let
i
=
0
;
i
<
eventsLen
;
i
++
)
{
var
event
=
executeResult
.
data
[
i
];
const
event
=
executeResult
.
data
[
i
];
if
(
event
.
type
===
"
QRCodeUpdated
"
)
{
if
(
event
.
type
===
"
QRCodeUpdated
"
)
{
var
actionID
=
event
[
"
actionID
"
];
const
actionID
=
event
[
"
actionID
"
];
var
QrCode
=
event
[
"
payloads
"
][
1
];
const
QrCode
=
event
[
"
payloads
"
][
1
];
var
eventCopy
=
JSON
.
parse
(
JSON
.
stringify
(
event
));
const
eventCopy
=
JSON
.
parse
(
JSON
.
stringify
(
event
));
QRCode
.
toDataURL
(
actionID
+
"
,
"
+
QrCode
,
function
(
err
,
url
)
{
QRCode
.
toDataURL
(
actionID
+
"
,
"
+
QrCode
,
function
(
err
,
url
)
{
eventCopy
[
"
payloads
"
].
push
(
url
);
eventCopy
[
"
payloads
"
].
push
(
url
);
parent
.
onEvent
(
eventCopy
)
parent
.
onEvent
(
eventCopy
)
;
})
})
;
}
else
{
}
else
{
parent
.
onEvent
(
event
)
parent
.
onEvent
(
event
)
;
}
}
maxDeviceKeyEventTime
=
Math
.
max
(
maxDeviceKeyEventTime
,
event
.
stamp
)
maxDeviceKeyEventTime
=
Math
.
max
(
maxDeviceKeyEventTime
,
event
.
stamp
)
;
}
}
if
(
changedMaxDeviceKeyEventTime
)
{
if
(
changedMaxDeviceKeyEventTime
)
{
executeRestfulFunction
(
"
private
"
,
viamApi
,
viamApi
.
eventUpdateLastViewed
,
null
,
"
devicekey
"
,
await
executeRestfulFunction
(
"
private
"
,
viamApi
,
viamApi
.
eventUpdateLastViewed
,
null
,
"
devicekey
"
,
maxDeviceKeyEventTime
.
toString
()).
then
(
executeResult1
=>
{
maxDeviceKeyEventTime
.
toString
());
eventsDeviceEventsProcessing
=
false
})
}
else
{
eventsDeviceEventsProcessing
=
false
}
}
}
else
{
eventsDeviceEventsProcessing
=
false
}
}
});
}
catch
(
e
)
{
console
.
warn
(
e
);
}
eventsDeviceEventsProcessing
=
false
;
}
}
if
(
window
.
currentlyAuthenticatedIdentity
!=
null
&&
eventsEntityEventsProcessing
===
false
)
{
if
(
window
.
currentlyAuthenticatedIdentity
!=
null
&&
eventsEntityEventsProcessing
===
false
)
{
eventsEntityEventsProcessing
=
true
;
eventsEntityEventsProcessing
=
true
;
executeRestfulFunction
(
"
private
"
,
viamApi
,
viamApi
.
eventGetNewEvents
,
null
,
"
entity
"
).
then
(
executeResult
=>
{
try
{
if
(
executeResult
.
code
===
"
200
"
)
{
const
executeResult
=
await
executeRestfulFunction
(
"
private
"
,
viamApi
,
viamApi
.
eventGetNewEvents
,
null
,
"
entity
"
);
var
eventsLen
=
executeResult
.
data
.
length
;
if
(
executeResult
.
code
===
"
200
"
)
{
const
eventsLen
=
executeResult
.
data
.
length
;
let
changedMaxEntityEventTime
=
false
;
let
changedMaxEntityEventTime
=
false
;
for
(
var
i
=
0
;
i
<
eventsLen
;
i
++
)
{
for
(
let
i
=
0
;
i
<
eventsLen
;
i
++
)
{
event
=
executeResult
.
data
[
i
];
const
event
=
executeResult
.
data
[
i
];
if
(
event
.
type
===
"
QRCodeUpdated
"
)
{
if
(
event
.
type
===
"
QRCodeUpdated
"
)
{
var
actionID
=
event
[
"
actionID
"
];
const
actionID
=
event
[
"
actionID
"
];
var
QrCode
=
event
[
"
payloads
"
][
1
];
const
QrCode
=
event
[
"
payloads
"
][
1
];
var
eventCopy
=
JSON
.
parse
(
JSON
.
stringify
(
event
));
const
eventCopy
=
JSON
.
parse
(
JSON
.
stringify
(
event
));
QRCode
.
toDataURL
(
actionID
+
"
,
"
+
QrCode
,
function
(
err
,
url
)
{
QRCode
.
toDataURL
(
actionID
+
"
,
"
+
QrCode
,
function
(
err
,
url
)
{
eventCopy
[
"
payloads
"
].
push
(
url
);
eventCopy
[
"
payloads
"
].
push
(
url
);
parent
.
onEvent
(
eventCopy
)
parent
.
onEvent
(
eventCopy
)
;
});
});
continue
continue
;
}
}
parent
.
onEvent
(
event
);
parent
.
onEvent
(
event
);
changedMaxEntityEventTime
=
true
;
changedMaxEntityEventTime
=
true
;
maxEntityEventTime
=
Math
.
max
(
maxEntityEventTime
,
event
.
stamp
)
maxEntityEventTime
=
Math
.
max
(
maxEntityEventTime
,
event
.
stamp
)
;
}
}
if
(
changedMaxEntityEventTime
)
{
if
(
changedMaxEntityEventTime
)
{
executeRestfulFunction
(
"
private
"
,
viamApi
,
viamApi
.
eventUpdateLastViewed
,
null
,
"
entity
"
,
await
executeRestfulFunction
(
"
private
"
,
viamApi
,
viamApi
.
eventUpdateLastViewed
,
null
,
"
entity
"
,
maxEntityEventTime
.
toString
()).
then
(
executeResult1
=>
{
maxEntityEventTime
.
toString
());
eventsEntityEventsProcessing
=
false
})
}
else
{
eventsEntityEventsProcessing
=
false
}
}
}
else
{
eventsEntityEventsProcessing
=
false
}
}
});
}
catch
(
e
)
{
console
.
warn
(
e
);
}
eventsEntityEventsProcessing
=
false
;
}
}
},
1000
);
},
1000
);
});
});
This diff is collapsed.
Click to expand it.
javascript/src/iframe/wopiapi-iframe.js
+
2
−
1
View file @
12fd418e
...
@@ -12,7 +12,7 @@ WopiAPI.prototype.getPassports = function (fileID) {
...
@@ -12,7 +12,7 @@ WopiAPI.prototype.getPassports = function (fileID) {
uuid
,
uuid
,
token
,
token
,
deviceHash
,
deviceHash
,
fileID
fileID
:
encodeURI
(
fileID
)
}
}
};
};
...
@@ -22,6 +22,7 @@ WopiAPI.prototype.getPassports = function (fileID) {
...
@@ -22,6 +22,7 @@ WopiAPI.prototype.getPassports = function (fileID) {
WopiAPI
.
prototype
.
putDocument
=
function
(
path
,
accessToken
,
file
)
{
WopiAPI
.
prototype
.
putDocument
=
function
(
path
,
accessToken
,
file
)
{
const
{
publicKey
,
uuid
,
token
,
deviceHash
}
=
window
.
viamApi
.
getConfig
().
headers
;
const
{
publicKey
,
uuid
,
token
,
deviceHash
}
=
window
.
viamApi
.
getConfig
().
headers
;
path
=
path
[
0
]
===
"
/
"
?
path
:
`/
${
path
}
`
;
path
=
path
[
0
]
===
"
/
"
?
path
:
`/
${
path
}
`
;
path
=
encodeURI
(
path
);
const
requestConfig
=
{
const
requestConfig
=
{
url
:
`
${
window
.
WOPI_URL
}
files
${
path
}
/contents`
,
url
:
`
${
window
.
WOPI_URL
}
files
${
path
}
/contents`
,
method
:
'
POST
'
,
method
:
'
POST
'
,
...
...
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