mirror of
https://github.com/reiyua/github-profile-trophy-reiyua-mirror.git
synced 2026-11-17 06:02:09 +11:00
Support to filter by title
This commit is contained in:
parent
e45b390a81
commit
74134b3ff2
2 changed files with 8 additions and 2 deletions
4
index.ts
4
index.ts
|
|
@ -11,6 +11,7 @@ export default async (req: ServerRequest) => {
|
||||||
const username = params.get("username");
|
const username = params.get("username");
|
||||||
let row = CONSTANTS.DEFAULT_MAX_ROW;
|
let row = CONSTANTS.DEFAULT_MAX_ROW;
|
||||||
let column = CONSTANTS.DEFAULT_MAX_COLUMN;
|
let column = CONSTANTS.DEFAULT_MAX_COLUMN;
|
||||||
|
let titles: Array<string> = params.getAll("title");
|
||||||
let ranks: Array<string> = params.getAll("rank");
|
let ranks: Array<string> = params.getAll("rank");
|
||||||
if (params.has("row")) {
|
if (params.has("row")) {
|
||||||
const param = params.get("row");
|
const param = params.get("row");
|
||||||
|
|
@ -26,12 +27,11 @@ export default async (req: ServerRequest) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (username != null) {
|
if (username != null) {
|
||||||
const userInfo = await client.requestUserInfo(username);
|
const userInfo = await client.requestUserInfo(username);
|
||||||
req.respond(
|
req.respond(
|
||||||
{
|
{
|
||||||
body: new Card(ranks, column, row).render(userInfo),
|
body: new Card(titles, ranks, column, row).render(userInfo),
|
||||||
headers: new Headers(
|
headers: new Headers(
|
||||||
{
|
{
|
||||||
"Content-Type": "image/svg+xml",
|
"Content-Type": "image/svg+xml",
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ export class Card {
|
||||||
private width = 0;
|
private width = 0;
|
||||||
private height = 0;
|
private height = 0;
|
||||||
constructor(
|
constructor(
|
||||||
|
private titles: Array<string>,
|
||||||
private ranks: Array<string>,
|
private ranks: Array<string>,
|
||||||
private maxColumn = CONSTANTS.DEFAULT_MAX_COLUMN,
|
private maxColumn = CONSTANTS.DEFAULT_MAX_COLUMN,
|
||||||
private maxRow = CONSTANTS.DEFAULT_MAX_ROW,
|
private maxRow = CONSTANTS.DEFAULT_MAX_ROW,
|
||||||
|
|
@ -31,6 +32,11 @@ export class Card {
|
||||||
new TotalRepositoryTrophy(userInfo.totalRepositories),
|
new TotalRepositoryTrophy(userInfo.totalRepositories),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Filter by titles
|
||||||
|
if (this.titles.length != 0) {
|
||||||
|
trophyList = trophyList.filter((trophy) => this.titles.includes(trophy.title))
|
||||||
|
}
|
||||||
|
|
||||||
// Filter by ranks
|
// Filter by ranks
|
||||||
if (this.ranks.length != 0) {
|
if (this.ranks.length != 0) {
|
||||||
trophyList = trophyList.filter((trophy) => this.ranks.includes(trophy.rank))
|
trophyList = trophyList.filter((trophy) => this.ranks.includes(trophy.rank))
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue