Commit b92a8ba0 authored by nanahira's avatar nanahira

update

parent f3d997d4
FROM node FROM node
COPY . /usr/src/app COPY . /usr/src/app
WORKDIR /usr/src/app WORKDIR /usr/src/app
RUN npm ci RUN npm install
CMD node index.js 443 CMD node index.js 443
...@@ -19,7 +19,7 @@ const https_server = https.createServer(https_options, (request, response) => { ...@@ -19,7 +19,7 @@ const https_server = https.createServer(https_options, (request, response) => {
} }
const username = path_match[1]; const username = path_match[1];
_request({ _request({
url: "https://ygobbs.com/users/" + username + ".json", url: "https://ygobbs.com/users/" + encodeURIComponent(username) + ".json",
json: true json: true
}, (error, res, body) => { }, (error, res, body) => {
if (error) { if (error) {
...@@ -31,12 +31,17 @@ const https_server = https.createServer(https_options, (request, response) => { ...@@ -31,12 +31,17 @@ const https_server = https.createServer(https_options, (request, response) => {
response.end("Bad username JSON."); response.end("Bad username JSON.");
console.log("BAD USERNAME JSON", body); console.log("BAD USERNAME JSON", body);
} else if (!body.users) { } else if (!body.users) {
response.writeHead(404); request_avatar(username);
response.end("User not found.");
} else { } 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({ _request({
url: "https://api.moecube.com/accounts/users/" + real_username + ".avatar" url: "https://api.moecube.com/accounts/users/" + encodeURIComponent(username) + ".avatar"
}, (error, res, body) => { }, (error, res, body) => {
if (error) { if (error) {
response.writeHead(500); response.writeHead(500);
...@@ -64,8 +69,6 @@ const https_server = https.createServer(https_options, (request, response) => { ...@@ -64,8 +69,6 @@ const https_server = https.createServer(https_options, (request, response) => {
}); });
} }
}); });
} }
});
});
https_server.listen(parseInt(process.argv[2])); https_server.listen(parseInt(process.argv[2]));
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment