Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Synchronet
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
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Main
Synchronet
Commits
55089ece
Commit
55089ece
authored
4 years ago
by
echicken
Browse files
Options
Downloads
Patches
Plain Diff
New client-side avatar fetching/caching thing. Formatting changes.
parent
a53a74e3
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
webv4/lib/avatars.js
+2
-4
2 additions, 4 deletions
webv4/lib/avatars.js
webv4/root/api/system.ssjs
+91
-69
91 additions, 69 deletions
webv4/root/api/system.ssjs
webv4/root/js/avatars.js
+46
-0
46 additions, 0 deletions
webv4/root/js/avatars.js
with
139 additions
and
73 deletions
webv4/lib/avatars.js
+
2
−
4
View file @
55089ece
...
...
@@ -14,9 +14,8 @@ function Avatars() {
}
else
{
cache
.
local
[
usernumber
]
=
data
.
data
;
}
}
else
{
return
cache
.
local
[
usernumber
];
}
return
cache
.
local
[
usernumber
];
}
this
.
get_netuser
=
function
(
username
,
netaddr
)
{
...
...
@@ -30,9 +29,8 @@ function Avatars() {
}
else
{
cache
.
network
[
netaddr
][
username
]
=
data
.
data
;
}
}
else
{
return
cache
.
network
[
netaddr
][
username
];
}
return
cache
.
network
[
netaddr
][
username
];
}
}
This diff is collapsed.
Click to expand it.
webv4/root/api/system.ssjs
+
91
−
69
View file @
55089ece
...
...
@@ -5,87 +5,109 @@ var settings = load('modopts.js', 'web') || { web_directory: '../webv4' };
load
(
settings
.
web_directory
+
'
/lib/init.js
'
);
load
(
settings
.
web_lib
+
'
auth.js
'
);
var
handled
=
false
;
var
reply
=
{};
if
((
http_request
.
method
===
'
GET
'
||
http_request
.
method
===
'
POST
'
)
&&
typeof
http_request
.
query
.
call
!==
'
undefined
'
&&
user
.
number
>
0
)
{
if
((
http_request
.
method
===
'
GET
'
||
http_request
.
method
===
'
POST
'
)
&&
http_request
.
query
.
call
!==
undefined
)
{
switch
(
http_request
.
query
.
call
[
0
])
{
case
'
node-list
'
:
var
usr
=
new
User
(
1
);
reply
=
system
.
node_list
.
reduce
(
function
(
a
,
c
,
i
)
{
if
(
c
.
status
!==
3
)
return
a
;
usr
.
number
=
c
.
useron
;
a
.
push
({
node
:
i
,
status
:
format
(
NodeStatus
[
c
.
status
],
c
.
aux
,
c
.
extaux
),
action
:
format
(
NodeAction
[
c
.
action
],
c
.
aux
,
c
.
extaux
),
user
:
usr
.
alias
,
connection
:
usr
.
connection
});
return
a
;
},
[]);
for
(
var
un
=
1
;
un
<
system
.
lastuser
;
un
++
)
{
usr
.
number
=
un
;
if
(
usr
.
connection
!==
'
HTTP
'
)
continue
;
if
(
usr
.
alias
===
settings
.
guest
)
continue
;
if
(
usr
.
settings
&
USER_QUIET
)
continue
;
if
(
usr
.
logontime
<
time
()
-
settings
.
inactivity
)
continue
;
var
webAction
=
getSessionValue
(
usr
.
number
,
'
action
'
);
if
(
webAction
===
null
)
continue
;
reply
.
push
({
status
:
''
,
action
:
locale
.
strings
.
api_system
.
nodelist_action_prefix
+
'
'
+
webAction
,
user
:
usr
.
alias
,
connection
:
'
W
'
});
}
usr
=
undefined
;
case
'
get-avatar
'
:
var
avatar_lib
=
load
({},
'
avatar_lib.js
'
);
reply
=
http_request
.
query
.
user
.
map
(
function
(
e
)
{
const
u
=
e
.
split
(
'
@
'
);
var
ret
;
if
(
u
.
length
===
1
)
{
ret
=
avatar_lib
.
read_localuser
(
u
[
0
])
||
{};
}
else
{
ret
=
avatar_lib
.
read_netuser
(
u
[
0
],
u
[
1
])
||
{};
}
ret
.
user
=
e
;
return
ret
;
});
handled
=
true
;
break
;
default
:
break
;
}
case
'
send-telegram
'
:
if
(
user
.
alias
===
settings
.
guest
)
break
;
if
(
typeof
http_request
.
query
.
user
===
'
undefined
'
)
break
;
if
(
typeof
http_request
.
query
.
telegram
===
'
undefined
'
||
http_request
.
query
.
telegram
[
0
]
===
''
)
{
if
(
!
handled
&&
user
.
number
>
0
)
{
switch
(
http_request
.
query
.
call
[
0
])
{
case
'
node-list
'
:
var
usr
=
new
User
(
1
);
reply
=
system
.
node_list
.
reduce
(
function
(
a
,
c
,
i
)
{
if
(
c
.
status
!==
3
)
return
a
;
usr
.
number
=
c
.
useron
;
a
.
push
({
node
:
i
,
status
:
format
(
NodeStatus
[
c
.
status
],
c
.
aux
,
c
.
extaux
),
action
:
format
(
NodeAction
[
c
.
action
],
c
.
aux
,
c
.
extaux
),
user
:
usr
.
alias
,
connection
:
usr
.
connection
});
return
a
;
},
[]);
for
(
var
un
=
1
;
un
<
system
.
lastuser
;
un
++
)
{
usr
.
number
=
un
;
if
(
usr
.
connection
!==
'
HTTP
'
)
continue
;
if
(
usr
.
alias
===
settings
.
guest
)
continue
;
if
(
usr
.
settings
&
USER_QUIET
)
continue
;
if
(
usr
.
logontime
<
time
()
-
settings
.
inactivity
)
continue
;
var
webAction
=
getSessionValue
(
usr
.
number
,
'
action
'
);
if
(
webAction
===
null
)
continue
;
reply
.
push
({
status
:
''
,
action
:
locale
.
strings
.
api_system
.
nodelist_action_prefix
+
'
'
+
webAction
,
user
:
usr
.
alias
,
connection
:
'
W
'
});
}
usr
=
undefined
;
break
;
}
if
(
http_request
.
query
.
telegram
[
0
].
length
>
settings
.
maximum_telegram_length
)
{
case
'
send-telegram
'
:
if
(
user
.
alias
===
settings
.
guest
)
break
;
if
(
typeof
http_request
.
query
.
user
===
'
undefined
'
)
break
;
if
(
typeof
http_request
.
query
.
telegram
===
'
undefined
'
||
http_request
.
query
.
telegram
[
0
]
===
''
)
{
break
;
}
if
(
http_request
.
query
.
telegram
[
0
].
length
>
settings
.
maximum_telegram_length
)
{
break
;
}
var
un
=
system
.
matchuser
(
http_request
.
query
.
user
[
0
]);
if
(
un
<
1
)
break
;
system
.
put_telegram
(
un
,
format
(
locale
.
strings
.
api_system
.
telegram_header_format
,
user
.
alias
,
(
new
Date
()).
toLocaleString
()
)
+
'
\r\n
'
+
utf8_decode
(
http_request
.
query
.
telegram
[
0
])
+
'
\r\n
'
);
break
;
}
var
un
=
system
.
matchuser
(
http_request
.
query
.
user
[
0
]);
if
(
un
<
1
)
break
;
system
.
put_telegram
(
un
,
format
(
locale
.
strings
.
api_system
.
telegram_header_format
,
user
.
alias
,
(
new
Date
()).
toLocaleString
()
)
+
'
\r\n
'
+
utf8_decode
(
http_request
.
query
.
telegram
[
0
])
+
'
\r\n
'
);
break
;
case
'
get-telegram
'
:
if
(
user
.
alias
===
settings
.
guest
)
break
;
reply
.
telegram
=
system
.
get_telegram
(
user
.
number
);
break
;
case
'
get-telegram
'
:
if
(
user
.
alias
===
settings
.
guest
)
break
;
reply
.
telegram
=
system
.
get_telegram
(
user
.
number
);
break
;
case
'
set-xtrn-intent
'
:
if
(
user
.
alias
===
settings
.
guest
)
break
;
if
(
typeof
http_request
.
query
.
code
===
'
undefined
'
)
break
;
if
(
http_request
.
query
.
code
[
0
].
length
>
8
)
break
;
if
(
typeof
xtrn_area
.
prog
[
http_request
.
query
.
code
[
0
]]
===
'
undefined
'
)
{
case
'
set-xtrn-intent
'
:
if
(
user
.
alias
===
settings
.
guest
)
break
;
if
(
typeof
http_request
.
query
.
code
===
'
undefined
'
)
break
;
if
(
http_request
.
query
.
code
[
0
].
length
>
8
)
break
;
if
(
typeof
xtrn_area
.
prog
[
http_request
.
query
.
code
[
0
]]
===
'
undefined
'
)
{
break
;
}
setSessionValue
(
user
.
number
,
'
xtrn
'
,
http_request
.
query
.
code
[
0
]);
break
;
}
setSessionValue
(
user
.
number
,
'
xtrn
'
,
http_request
.
query
.
code
[
0
]);
break
;
default
:
break
;
default
:
break
;
}
}
...
...
This diff is collapsed.
Click to expand it.
webv4/root/js/avatars.js
+
46
−
0
View file @
55089ece
...
...
@@ -37,3 +37,49 @@ function Avatarizer() {
}
}
const
Avatars
=
new
(
function
()
{
const
gc
=
new
GraphicsConverter
(
'
./images/cp437-ibm-vga8.png
'
,
8
,
16
,
64
,
4
);
function
draw
(
data
)
{
const
img
=
new
Image
();
img
.
addEventListener
(
'
load
'
,
()
=>
document
.
querySelectorAll
(
`div[data-avatar="
${
data
.
user
}
"]:empty`
).
forEach
(
e
=>
e
.
appendChild
(
img
.
cloneNode
(
true
))));
img
.
src
=
data
.
dataURL
||
'
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFAAAABgCAYAAACKa/UAAAABiUlEQVR4Xu3c0YqCUBiFUXtKX1Gfcga6TPBgn6LDrG5zSy3377EQX8uy/ExeXwu8AH5t9w4CbH4Aox9AgFUg5p0Dnw44z3P8iC2+rmvbwSB9eQMBxuMHEOCugBGOBQEIcF/AKhwbAvC/Ad592TLyPruRpy8iAEeHcPA+QICHBIzwIa7txgABHhOwCh/z2mwNEGAUiHENBBgFYlwDAUaBGNdAgFEgxjUQYBSIcQ0EGAViXAMBRoEY10CAUSDGNRBgFIhxDQQYBWJcAwFGgRjXQIBRIMYf38DP73f33Vpng31+v9PvjQEYRwQgwEMCRvgQ13ZjgAD3BR6/Ct99mRILNFXgPMIA44N3AAJMZwEjHJ+pABBgmkCrcOObAD4e8K9fplwNPFxEAO4/+QjgoKKjn3oAAdazXPs3RwM1UAOvFYh7t4gAjAIxroEAo0CMayDAKBDjGggwCsS4BgKMAjGugQCjQIxrIMAoEOMaCDAKxLgGAowCMa6BAKNAjGsgwCgQ4xoIMArE+KiBv6PnKB+V8OyaAAAAAElFTkSuQmCC
'
;
}
function
cacheAvatar
(
data
)
{
if
(
data
.
data
)
{
gc
.
from_bin
(
atob
(
data
.
data
),
10
,
6
,
dataURL
=>
{
data
.
dataURL
=
dataURL
;
localStorage
.
setItem
(
`avatar-
${
data
.
user
}
`
,
JSON
.
stringify
(
data
));
draw
(
data
);
},
true
);
}
else
{
data
.
data
=
null
;
localStorage
.
setItem
(
`avatar-
${
data
.
user
}
`
,
JSON
.
stringify
(
data
));
draw
(
data
);
}
}
function
fromCache
(
user
)
{
return
JSON
.
parse
(
localStorage
.
getItem
(
`avatar-
${
user
}
`
));
// should return null if local copy is aged; as it is, avatars will remain in local storage until user clears it
}
async
function
fetchAvatar
(
user
)
{
const
u
=
[].
concat
(
user
);
const
data
=
await
v4_get
(
`./api/system.ssjs?call=get-avatar&user=
${
u
.
join
(
'
&user=
'
)}
`
);
[].
concat
(
data
).
forEach
(
cacheAvatar
);
}
this
.
draw
=
async
function
(
user
)
{
const
u
=
[].
concat
(
user
).
filter
(
e
=>
{
const
a
=
fromCache
(
e
);
if
(
a
===
null
)
return
true
;
// Not cached
if
(
a
)
draw
(
a
);
});
if
(
u
.
length
)
fetchAvatar
(
u
);
}
})();
\ No newline at end of file
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