Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
A
avatar-helper
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
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
MyCard
avatar-helper
Commits
b92a8ba0
Commit
b92a8ba0
authored
Oct 20, 2019
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
f3d997d4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
32 deletions
+35
-32
Dockerfile
Dockerfile
+1
-1
index.js
index.js
+34
-31
No files found.
Dockerfile
View file @
b92a8ba0
FROM
node
COPY
. /usr/src/app
WORKDIR
/usr/src/app
RUN
npm
ci
RUN
npm
install
CMD
node index.js 443
index.js
View file @
b92a8ba0
...
...
@@ -19,7 +19,7 @@ const https_server = https.createServer(https_options, (request, response) => {
}
const
username
=
path_match
[
1
];
_request
({
url
:
"
https://ygobbs.com/users/
"
+
username
+
"
.json
"
,
url
:
"
https://ygobbs.com/users/
"
+
encodeURIComponent
(
username
)
+
"
.json
"
,
json
:
true
},
(
error
,
res
,
body
)
=>
{
if
(
error
)
{
...
...
@@ -31,41 +31,44 @@ const https_server = https.createServer(https_options, (request, response) => {
response
.
end
(
"
Bad username JSON.
"
);
console
.
log
(
"
BAD USERNAME JSON
"
,
body
);
}
else
if
(
!
body
.
users
)
{
response
.
writeHead
(
404
);
response
.
end
(
"
User not found.
"
);
request_avatar
(
username
);
}
else
{
const
real_username
=
encodeURIComponent
(
body
.
users
[
0
].
username
);
const
real_username
=
body
.
users
[
0
].
username
;
request_avatar
(
real_username
);
}
});
});
function
request_avatar
(
response
,
username
)
{
_request
({
url
:
"
https://api.moecube.com/accounts/users/
"
+
encodeURIComponent
(
username
)
+
"
.avatar
"
},
(
error
,
res
,
body
)
=>
{
if
(
error
)
{
response
.
writeHead
(
500
);
response
.
end
(
"
Request error.
"
);
console
.
error
(
"
REQUEST ERROR
"
,
error
);
}
else
if
(
body
==
"
{
\"
message
\"
:
\"
Not Found
\"
}
"
)
{
response
.
writeHead
(
404
);
response
.
end
(
"
Avatar not found.
"
);
}
else
{
//console.log(body);
_request
({
url
:
"
https://api.moecube.com/accounts/users/
"
+
real_username
+
"
.avatar
"
},
(
error
,
res
,
body
)
=>
{
url
:
body
,
encoding
:
null
},
(
error
,
res
,
body
)
=>
{
if
(
error
)
{
response
.
writeHead
(
500
);
response
.
end
(
"
Request error.
"
);
console
.
error
(
"
REQUEST ERROR
"
,
error
);
}
else
if
(
body
==
"
{
\"
message
\"
:
\"
Not Found
\"
}
"
)
{
response
.
writeHead
(
404
);
response
.
end
(
"
Avatar not found.
"
);
}
else
{
//console.log(body);
_request
({
url
:
body
,
encoding
:
null
},
(
error
,
res
,
body
)
=>
{
if
(
error
)
{
response
.
writeHead
(
500
);
response
.
end
(
"
Avatar error.
"
);
console
.
error
(
"
AVATAR ERROR
"
,
error
);
}
else
{
var
recv_buf
=
Buffer
.
from
(
body
,
'
binary
'
);
response
.
writeHead
(
200
,
{
"
Content-Type
"
:
"
image/png
"
});
fs
.
writeFileSync
(
"
./test.png
"
,
recv_buf
);
response
.
end
(
recv_buf
);
}
});
response
.
end
(
"
Avatar error.
"
);
console
.
error
(
"
AVATAR ERROR
"
,
error
);
}
else
{
var
recv_buf
=
Buffer
.
from
(
body
,
'
binary
'
);
response
.
writeHead
(
200
,
{
"
Content-Type
"
:
"
image/png
"
});
fs
.
writeFileSync
(
"
./test.png
"
,
recv_buf
);
response
.
end
(
recv_buf
);
}
});
});
}
});
}
);
});
}
https_server
.
listen
(
parseInt
(
process
.
argv
[
2
]));
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