Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
A
avatar-handler
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nanahira
avatar-handler
Commits
eb9a946c
Commit
eb9a946c
authored
Nov 10, 2021
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix username loading
parent
9e9f72f0
Pipeline
#6732
passed with stages
in 25 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
5 deletions
+7
-5
src/avatar.ts
src/avatar.ts
+7
-5
No files found.
src/avatar.ts
View file @
eb9a946c
...
...
@@ -3,13 +3,14 @@ import mysql, { ConnectionConfig } from "promise-mysql";
import
axios
from
"
axios
"
;
import
{
Processor
}
from
"
./processor
"
;
import
{
CutData
}
from
"
./utility
"
;
import
_
from
'
underscore
'
;
async
function
getRealUsername
(
originalUsername
:
string
)
{
try
{
const
{
data
:
{
user
:
{
name
,
username
}}
}
=
(
await
axios
.
get
(
`https://ygobbs.com/users/
${
encodeURIComponent
(
originalUsername
)}
.json`
,
{
responseType
:
"
json
"
}));
return
[
name
,
username
]
;
return
_
.
uniq
([
originalUsername
,
username
,
name
])
;
}
catch
(
e
)
{
console
.
error
(
`User
${
originalUsername
}
not found:
${
e
.
toString
()}
`
);
return
[
originalUsername
];
...
...
@@ -19,10 +20,11 @@ async function getRealUsername(originalUsername: string) {
async
function
getAvatarURL
(
usernames
:
string
[]):
Promise
<
string
>
{
for
(
const
username
of
usernames
)
{
try
{
const
{
data
:
{
user
:
{
avatar
}
}
}
=
(
await
axios
.
get
(
`https://api.moecube.com/accounts/users/
${
encodeURIComponent
(
username
)}
.json`
,
{
const
{
data
:
{
user
:
{
avatar
:
_avatar
}
}
}
=
(
await
axios
.
get
(
`https://api.moecube.com/accounts/users/
${
encodeURIComponent
(
username
)}
.json`
,
{
responseType
:
"
json
"
}));
if
(
avatar
?.
match
(
/^http
(
s
)?
:
\/\/
/
))
{
const
avatar
=
_avatar
as
string
;
if
(
avatar
?.
match
(
/^http
(
s
)?
:
\/\/
/
)
&&
!
avatar
.
endsWith
(
'
default_avatar.jpg
'
))
{
return
avatar
;
}
}
catch
(
e
)
{
...
...
@@ -33,8 +35,8 @@ async function getAvatarURL(usernames: string[]): Promise<string> {
}
async
function
getURLFromUsername
(
username
:
string
)
{
//
const possibleNames = await getRealUsername(username);
return
getAvatarURL
(
[
username
]
);
const
possibleNames
=
await
getRealUsername
(
username
);
return
getAvatarURL
(
possibleNames
);
}
interface
QueryResult
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment