mirror of
https://github.com/reiyua/github-profile-trophy-reiyua-mirror.git
synced 2026-11-17 06:02:09 +11:00
Add params that are column row and rakns
This commit is contained in:
parent
95a0b56fa4
commit
ba1d95cb4f
4 changed files with 35 additions and 11 deletions
22
index.ts
22
index.ts
|
|
@ -7,13 +7,31 @@ import "https://deno.land/x/dotenv@v0.5.0/load.ts";
|
||||||
const client = new GithubAPIClient();
|
const client = new GithubAPIClient();
|
||||||
|
|
||||||
export default async (req: ServerRequest) => {
|
export default async (req: ServerRequest) => {
|
||||||
const username = parseParams(req).get("username");
|
const params = parseParams(req);
|
||||||
|
const username = params.get("username");
|
||||||
|
let row = CONSTANTS.DEFAULT_MAX_ROW;
|
||||||
|
let column = CONSTANTS.DEFAULT_MAX_COLUMN;
|
||||||
|
let ranks: Array<string> = params.getAll("rank");
|
||||||
|
if (params.has("row")) {
|
||||||
|
const param = params.get("row");
|
||||||
|
if (param != null) {
|
||||||
|
row = parseInt(param);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (params.has("column")) {
|
||||||
|
const param = params.get("column");
|
||||||
|
if (param != null) {
|
||||||
|
column = parseInt(param);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
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().render(userInfo),
|
body: new Card(ranks, column, row).render(userInfo),
|
||||||
headers: new Headers(
|
headers: new Headers(
|
||||||
{
|
{
|
||||||
"Content-Type": "image/svg+xml",
|
"Content-Type": "image/svg+xml",
|
||||||
|
|
|
||||||
12
src/card.ts
12
src/card.ts
|
|
@ -14,9 +14,10 @@ export class Card {
|
||||||
private width = 0;
|
private width = 0;
|
||||||
private height = 0;
|
private height = 0;
|
||||||
constructor(
|
constructor(
|
||||||
private panelSize = CONSTANTS.DEFALT_PANEL_SIZE,
|
private ranks: Array<string>,
|
||||||
private maxColumn = CONSTANTS.DEFALT_MAX_COLUMN,
|
private maxColumn = CONSTANTS.DEFAULT_MAX_COLUMN,
|
||||||
private maxRow = CONSTANTS.DEFALT_MAX_ROW,
|
private maxRow = CONSTANTS.DEFAULT_MAX_ROW,
|
||||||
|
private panelSize = CONSTANTS.DEFAULT_PANEL_SIZE,
|
||||||
) {
|
) {
|
||||||
this.width = panelSize * this.maxColumn;
|
this.width = panelSize * this.maxColumn;
|
||||||
}
|
}
|
||||||
|
|
@ -30,6 +31,11 @@ export class Card {
|
||||||
new TotalRepositoryTrophy(userInfo.totalRepositories),
|
new TotalRepositoryTrophy(userInfo.totalRepositories),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Filter by ranks
|
||||||
|
if (this.ranks.length != 0) {
|
||||||
|
trophyList = trophyList.filter((trophy) => this.ranks.includes(trophy.rank))
|
||||||
|
}
|
||||||
|
|
||||||
// Sort by rank
|
// Sort by rank
|
||||||
trophyList = trophyList.sort((a: Trophy, b: Trophy) =>
|
trophyList = trophyList.sort((a: Trophy, b: Trophy) =>
|
||||||
RANK_ORDER.indexOf(a.rank) - RANK_ORDER.indexOf(b.rank)
|
RANK_ORDER.indexOf(a.rank) - RANK_ORDER.indexOf(b.rank)
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ export class Trophy {
|
||||||
this.topMessage = rankCondition.message;
|
this.topMessage = rankCondition.message;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
render(x = 0, y = 0, panelSize = CONSTANTS.DEFALT_PANEL_SIZE): string {
|
render(x = 0, y = 0, panelSize = CONSTANTS.DEFAULT_PANEL_SIZE): string {
|
||||||
return `
|
return `
|
||||||
<svg
|
<svg
|
||||||
x="${x}"
|
x="${x}"
|
||||||
|
|
|
||||||
10
src/utils.ts
10
src/utils.ts
|
|
@ -9,10 +9,10 @@ export function parseParams(req: ServerRequest): URLSearchParams {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function abridgeScore(score: number): string {
|
export function abridgeScore(score: number): string {
|
||||||
if (score < 1) {
|
if (Math.abs(score) < 1) {
|
||||||
return "unknown";
|
return "unknown";
|
||||||
}
|
}
|
||||||
if (score < 10) {
|
if (Math.abs(score) < 10) {
|
||||||
return score.toString() + "+"
|
return score.toString() + "+"
|
||||||
}
|
}
|
||||||
if (Math.abs(score) > 999){
|
if (Math.abs(score) > 999){
|
||||||
|
|
@ -25,9 +25,9 @@ export function abridgeScore(score: number): string {
|
||||||
|
|
||||||
export const CONSTANTS = {
|
export const CONSTANTS = {
|
||||||
CACHE_MAX_AGE: 7200,
|
CACHE_MAX_AGE: 7200,
|
||||||
DEFALT_PANEL_SIZE: 110,
|
DEFAULT_PANEL_SIZE: 110,
|
||||||
DEFALT_MAX_COLUMN: 6,
|
DEFAULT_MAX_COLUMN: 6,
|
||||||
DEFALT_MAX_ROW: 3,
|
DEFAULT_MAX_ROW: 3,
|
||||||
};
|
};
|
||||||
|
|
||||||
export enum RANK {
|
export enum RANK {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue