Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F995381
context.js
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
context.js
View Options
"use strict"
;
const
locreq
=
require
(
"locreq"
)(
__dirname
);
const
promisify
=
require
(
"bluebird-events"
);
const
EventEmitter
=
require
(
"events"
);
function
Context
(
timestamp
,
ip
,
user_id
,
session_id
,
anonymous_session_id
,
anon_session_is_new
,
anonymous_user_id
)
{
Object
.
defineProperty
(
this
,
"_cached_user_data"
,
{
value
:
false
,
writable
:
true
,
});
Object
.
defineProperty
(
this
,
"loading_user_data"
,
{
value
:
false
,
writable
:
true
,
});
Object
.
defineProperty
(
this
,
"e"
,
{
value
:
new
EventEmitter
(),
});
this
.
e
.
setMaxListeners
(
20
);
Object
.
defineProperty
(
this
,
"session_id"
,
{
value
:
session_id
,
});
// to make it non-enumerable and non-writeable
Object
.
defineProperty
(
this
,
"anonymous_session_id"
,
{
value
:
anonymous_session_id
||
null
,
});
// to make it non-enumerable and non-writeable
Object
.
defineProperty
(
this
,
"anon_session_is_new"
,
{
value
:
anon_session_is_new
||
false
,
});
// to make it non-enumerable and non-writeable
if
(
user_id
===
undefined
||
user_id
===
false
)
{
user_id
=
null
;
}
if
(
timestamp
===
undefined
)
{
const
d
=
new
Date
();
timestamp
=
d
.
getTime
();
}
this
.
timestamp
=
timestamp
;
this
.
ip
=
ip
||
null
;
this
.
user_id
=
user_id
;
this
.
anonymous_user_id
=
anonymous_user_id
||
null
;
}
module
.
exports
=
Context
;
const
SuperContext
=
locreq
(
"lib/super-context.js"
);
Context
.
prototype
.
get_user_data
=
function
(
app
)
{
const
self
=
this
;
if
(
this
.
user_id
===
null
)
{
return
Promise
.
resolve
(
null
);
}
else
if
(
self
.
loading_user_data
)
{
return
promisify
(
self
.
e
,
{
resolve
:
"loaded_user_data"
,
reject
:
"error"
,
});
}
else
if
(
self
.
_cached_user_data
!==
false
)
{
return
Promise
.
resolve
(
self
.
_cached_user_data
);
}
self
.
loading_user_data
=
true
;
const
c
=
new
SuperContext
(
self
);
return
app
.
run_action
(
c
,
[
"collections"
,
"users"
,
this
.
user_id
],
"show"
)
.
then
(
function
(
user_data
)
{
self
.
_cached_user_data
=
user_data
;
self
.
loading_user_data
=
false
;
self
.
e
.
emit
(
"loaded_user_data"
,
user_data
);
return
user_data
;
})
.
catch
(
function
(
error
)
{
self
.
e
.
emit
(
"error"
);
throw
error
;
});
};
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Dec 23, 02:23 (6 h, 3 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
556800
Default Alt Text
context.js (2 KB)
Attached To
Mode
rS Sealious
Attached
Detach File
Event Timeline
Log In to Comment