From 74134b3ff23984a98a0847ddd48e741c4d9e6991 Mon Sep 17 00:00:00 2001 From: ryo-ma Date: Thu, 27 Aug 2020 01:28:51 +0900 Subject: [PATCH] Support to filter by title --- index.ts | 4 ++-- src/card.ts | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/index.ts b/index.ts index 35c161c..be0ae2f 100644 --- a/index.ts +++ b/index.ts @@ -11,6 +11,7 @@ export default async (req: ServerRequest) => { const username = params.get("username"); let row = CONSTANTS.DEFAULT_MAX_ROW; let column = CONSTANTS.DEFAULT_MAX_COLUMN; + let titles: Array = params.getAll("title"); let ranks: Array = params.getAll("rank"); if (params.has("row")) { const param = params.get("row"); @@ -26,12 +27,11 @@ export default async (req: ServerRequest) => { } } - if (username != null) { const userInfo = await client.requestUserInfo(username); req.respond( { - body: new Card(ranks, column, row).render(userInfo), + body: new Card(titles, ranks, column, row).render(userInfo), headers: new Headers( { "Content-Type": "image/svg+xml", diff --git a/src/card.ts b/src/card.ts index 0a64a62..9de4f96 100644 --- a/src/card.ts +++ b/src/card.ts @@ -14,6 +14,7 @@ export class Card { private width = 0; private height = 0; constructor( + private titles: Array, private ranks: Array, private maxColumn = CONSTANTS.DEFAULT_MAX_COLUMN, private maxRow = CONSTANTS.DEFAULT_MAX_ROW, @@ -31,6 +32,11 @@ export class Card { new TotalRepositoryTrophy(userInfo.totalRepositories), ); + // Filter by titles + if (this.titles.length != 0) { + trophyList = trophyList.filter((trophy) => this.titles.includes(trophy.title)) + } + // Filter by ranks if (this.ranks.length != 0) { trophyList = trophyList.filter((trophy) => this.ranks.includes(trophy.rank))