Commit b92a8ba0 authored by nanahira's avatar nanahira

update

parent f3d997d4
FROM node
COPY . /usr/src/app
WORKDIR /usr/src/app
RUN npm ci
RUN npm install
CMD node index.js 443
......@@ -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]));
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