mirror of
https://github.com/reiyua/github-profile-trophy-reiyua-mirror.git
synced 2026-11-17 06:02:09 +11:00
Refactor index.ts
This commit is contained in:
parent
703a3ac34f
commit
071eaccacc
1 changed files with 44 additions and 28 deletions
68
index.ts
68
index.ts
|
|
@ -11,20 +11,54 @@ export default async (req: ServerRequest) => {
|
||||||
const username = params.get("username");
|
const username = params.get("username");
|
||||||
const row = params.getNumberValue("row", CONSTANTS.DEFAULT_MAX_ROW);
|
const row = params.getNumberValue("row", CONSTANTS.DEFAULT_MAX_ROW);
|
||||||
const column = params.getNumberValue("column", CONSTANTS.DEFAULT_MAX_COLUMN);
|
const column = params.getNumberValue("column", CONSTANTS.DEFAULT_MAX_COLUMN);
|
||||||
const paddingWidth = params.getNumberValue("padding-w", CONSTANTS.DEFAULT_PADDING_W);
|
const paddingWidth = params.getNumberValue(
|
||||||
const paddingHeight = params.getNumberValue("padding-h", CONSTANTS.DEFAULT_PADDING_H);
|
"padding-w",
|
||||||
|
CONSTANTS.DEFAULT_PADDING_W,
|
||||||
|
);
|
||||||
|
const paddingHeight = params.getNumberValue(
|
||||||
|
"padding-h",
|
||||||
|
CONSTANTS.DEFAULT_PADDING_H,
|
||||||
|
);
|
||||||
const titles: Array<string> = params.getAll("title").flatMap((r) =>
|
const titles: Array<string> = params.getAll("title").flatMap((r) =>
|
||||||
r.split(",")
|
r.split(",")
|
||||||
).map((r) => r.trim());
|
).map((r) => r.trim());
|
||||||
const ranks: Array<string> = params.getAll("rank").flatMap((r) => r.split(","))
|
const ranks: Array<string> = params.getAll("rank").flatMap((r) =>
|
||||||
.map((r) => r.trim());
|
r.split(",")
|
||||||
|
).map((r) => r.trim());
|
||||||
|
|
||||||
if (username != null) {
|
if (username === null) {
|
||||||
const userInfo = await client.requestUserInfo(username);
|
|
||||||
if (userInfo !== null) {
|
|
||||||
req.respond(
|
req.respond(
|
||||||
{
|
{
|
||||||
body: new Card(titles, ranks, column, row, CONSTANTS.DEFAULT_PANEL_SIZE, paddingWidth, paddingHeight).render(userInfo),
|
body: "Can not find a query parameter: username",
|
||||||
|
status: 404,
|
||||||
|
headers: new Headers({ "Content-Type": "text" }),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const userInfo = await client.requestUserInfo(username);
|
||||||
|
if (userInfo === null) {
|
||||||
|
req.respond(
|
||||||
|
{
|
||||||
|
body: "Can not find a user",
|
||||||
|
status: 404,
|
||||||
|
headers: new Headers({ "Content-Type": "text" }),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Success Response
|
||||||
|
req.respond(
|
||||||
|
{
|
||||||
|
body: new Card(
|
||||||
|
titles,
|
||||||
|
ranks,
|
||||||
|
column,
|
||||||
|
row,
|
||||||
|
CONSTANTS.DEFAULT_PANEL_SIZE,
|
||||||
|
paddingWidth,
|
||||||
|
paddingHeight,
|
||||||
|
).render(userInfo),
|
||||||
headers: new Headers(
|
headers: new Headers(
|
||||||
{
|
{
|
||||||
"Content-Type": "image/svg+xml",
|
"Content-Type": "image/svg+xml",
|
||||||
|
|
@ -33,22 +67,4 @@ export default async (req: ServerRequest) => {
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
} else {
|
|
||||||
req.respond(
|
|
||||||
{
|
|
||||||
body: "Can not find a user",
|
|
||||||
status: 404,
|
|
||||||
headers: new Headers({ "Content-Type": "text" }),
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
req.respond(
|
|
||||||
{
|
|
||||||
body: "Can not find a query parameter: username",
|
|
||||||
status: 404,
|
|
||||||
headers: new Headers({ "Content-Type": "text" }),
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue