mirror of
https://github.com/reiyua/github-profile-trophy-reiyua-mirror.git
synced 2026-11-17 06:02:09 +11:00
Support username query param
This commit is contained in:
parent
e1f637117a
commit
964276d1f8
5 changed files with 158 additions and 62 deletions
20
dev_main.ts
20
dev_main.ts
|
|
@ -1,11 +1,29 @@
|
|||
import { serve } from "https://deno.land/std@0.66.0/http/server.ts";
|
||||
import { GithubAPIClient } from "./src/github_api_client.ts";
|
||||
import { Card } from "./src/card.ts";
|
||||
import "https://deno.land/x/dotenv@v0.5.0/load.ts";
|
||||
|
||||
const s = serve({ port: 8080 });
|
||||
const client = new GithubAPIClient();
|
||||
for await (const req of s) {
|
||||
const username = new URLSearchParams(req.url.split("?")[1]).get("username")
|
||||
|
||||
if (username != null) {
|
||||
const userInfo = await client.requestUserInfo(username);
|
||||
req.respond(
|
||||
{
|
||||
body: new Card().render(),
|
||||
body: new Card().render(userInfo),
|
||||
headers: new Headers({ "Content-Type": "image/svg+xml" }),
|
||||
},
|
||||
);
|
||||
} else {
|
||||
req.respond(
|
||||
{
|
||||
body: "Can not find username",
|
||||
status: 404,
|
||||
headers: new Headers({ "Content-Type": "text" }),
|
||||
},
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
19
index.ts
19
index.ts
|
|
@ -5,12 +5,23 @@ import "https://deno.land/x/dotenv@v0.5.0/load.ts";
|
|||
const client = new GithubAPIClient();
|
||||
|
||||
export default async (req: ServerRequest) => {
|
||||
const userInfo = await client.requestUserInfo("ryo-ma")
|
||||
const cardSize = 110;
|
||||
const username = new URLSearchParams(req.url.split("?")[1]).get("username");
|
||||
|
||||
if (username != null) {
|
||||
const userInfo = await client.requestUserInfo(username);
|
||||
req.respond(
|
||||
{
|
||||
body: new Card(cardSize).render(),
|
||||
body: new Card().render(userInfo),
|
||||
headers: new Headers({ "Content-Type": "image/svg+xml" }),
|
||||
},
|
||||
)
|
||||
);
|
||||
} else {
|
||||
req.respond(
|
||||
{
|
||||
body: "Can not find username",
|
||||
status: 404,
|
||||
headers: new Headers({ "Content-Type": "text" }),
|
||||
},
|
||||
);
|
||||
}
|
||||
};
|
||||
|
|
|
|||
39
src/card.ts
39
src/card.ts
|
|
@ -3,7 +3,11 @@ import {
|
|||
TotalStarTrophy,
|
||||
TotalCommitTrophy,
|
||||
TotalFollowerTrophy,
|
||||
TotalIssueTrophy,
|
||||
TotalPullRequestTrophy,
|
||||
TotalRepositoryTrophy,
|
||||
} from "./trophies.ts";
|
||||
import {UserInfo} from "./github_api_client.ts";
|
||||
|
||||
export class Card {
|
||||
private width = 0;
|
||||
|
|
@ -16,32 +20,15 @@ export class Card {
|
|||
this.width = panelSize * this.maxPanelWidthCount;
|
||||
this.height = panelSize * this.maxPanelHeightCount;
|
||||
}
|
||||
render(): string {
|
||||
const trophy1 = new TotalStarTrophy(0);
|
||||
const trophy2 = new TotalStarTrophy(100);
|
||||
const trophy3 = new TotalStarTrophy(500);
|
||||
const trophy4 = new TotalStarTrophy(1000);
|
||||
const trophy5 = new TotalCommitTrophy(1);
|
||||
const trophy6 = new TotalCommitTrophy(200);
|
||||
const trophy7 = new TotalCommitTrophy(1000);
|
||||
const trophy8 = new TotalCommitTrophy(5000);
|
||||
const trophy9 = new TotalFollowerTrophy(1);
|
||||
const trophy10 = new TotalFollowerTrophy(50);
|
||||
const trophy11 = new TotalFollowerTrophy(200);
|
||||
const trophy12 = new TotalFollowerTrophy(500);
|
||||
const trophyList = new Array<Trophy>();
|
||||
trophyList.push(trophy1);
|
||||
trophyList.push(trophy2);
|
||||
trophyList.push(trophy3);
|
||||
trophyList.push(trophy4);
|
||||
trophyList.push(trophy5);
|
||||
trophyList.push(trophy6);
|
||||
trophyList.push(trophy7);
|
||||
trophyList.push(trophy8);
|
||||
trophyList.push(trophy9);
|
||||
trophyList.push(trophy10);
|
||||
trophyList.push(trophy11);
|
||||
trophyList.push(trophy12);
|
||||
render(userInfo: UserInfo): string {
|
||||
const trophyList = new Array<Trophy>(
|
||||
new TotalStarTrophy(userInfo.totalStargazers),
|
||||
new TotalCommitTrophy(userInfo.totalCommits),
|
||||
new TotalFollowerTrophy(userInfo.totalFollowers),
|
||||
new TotalIssueTrophy(userInfo.totalIssues),
|
||||
new TotalPullRequestTrophy(userInfo.totalPullRequests),
|
||||
new TotalRepositoryTrophy(userInfo.totalRepositories),
|
||||
);
|
||||
const renderdTrophy = trophyList.reduce(
|
||||
(sum: string, trophy: Trophy, i: number) => {
|
||||
let x = (this.panelSize * i);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import {soxa} from "../deps.ts";
|
||||
class UserInfo {
|
||||
export class UserInfo {
|
||||
constructor(
|
||||
public totalCommits: Number,
|
||||
public totalFollowers: Number,
|
||||
|
|
|
|||
122
src/trophies.ts
122
src/trophies.ts
|
|
@ -41,22 +41,22 @@ export abstract class Trophy {
|
|||
export class TotalStarTrophy extends Trophy {
|
||||
constructor(private totalStartgazer: Number) {
|
||||
super();
|
||||
this.title = "STAR";
|
||||
this.title = "Star";
|
||||
this.setRank();
|
||||
}
|
||||
setRank() {
|
||||
if (this.totalStartgazer >= 1000) {
|
||||
if (this.totalStartgazer >= 200) {
|
||||
this.rank = "S";
|
||||
this.topMessage = "Super Star";
|
||||
this.bottomMessage = "+1000";
|
||||
} else if (this.totalStartgazer >= 500) {
|
||||
this.bottomMessage = "+200";
|
||||
} else if (this.totalStartgazer >= 100) {
|
||||
this.rank = "A";
|
||||
this.topMessage = "High Star";
|
||||
this.bottomMessage = "+500";
|
||||
} else if (this.totalStartgazer >= 100) {
|
||||
this.bottomMessage = "+100";
|
||||
} else if (this.totalStartgazer >= 10) {
|
||||
this.rank = "B";
|
||||
this.topMessage = "Middle Star";
|
||||
this.bottomMessage = "+100";
|
||||
this.bottomMessage = "+10";
|
||||
} else if (this.totalStartgazer >= 1) {
|
||||
this.rank = "C";
|
||||
this.topMessage = "First Star";
|
||||
|
|
@ -68,22 +68,22 @@ export class TotalStarTrophy extends Trophy {
|
|||
export class TotalCommitTrophy extends Trophy {
|
||||
constructor(private totalStartgazer: Number) {
|
||||
super();
|
||||
this.title = "COMMIT";
|
||||
this.title = "Commit";
|
||||
this.setRank();
|
||||
}
|
||||
setRank() {
|
||||
if (this.totalStartgazer >= 5000) {
|
||||
if (this.totalStartgazer >= 1000) {
|
||||
this.rank = "S";
|
||||
this.topMessage = "Super Commiter";
|
||||
this.bottomMessage = "+5000";
|
||||
} else if (this.totalStartgazer >= 1000) {
|
||||
this.bottomMessage = "+1000";
|
||||
} else if (this.totalStartgazer >= 500) {
|
||||
this.rank = "A";
|
||||
this.topMessage = "High Commiter";
|
||||
this.bottomMessage = "+1000";
|
||||
} else if (this.totalStartgazer >= 200) {
|
||||
this.bottomMessage = "+500";
|
||||
} else if (this.totalStartgazer >= 100) {
|
||||
this.rank = "B";
|
||||
this.topMessage = "Middle Commiter";
|
||||
this.bottomMessage = "+200";
|
||||
this.bottomMessage = "+100";
|
||||
} else if (this.totalStartgazer >= 1) {
|
||||
this.rank = "C";
|
||||
this.topMessage = "First Commit";
|
||||
|
|
@ -95,22 +95,22 @@ export class TotalCommitTrophy extends Trophy {
|
|||
export class TotalFollowerTrophy extends Trophy {
|
||||
constructor(private totalStartgazer: Number) {
|
||||
super();
|
||||
this.title = "FOLLOWER";
|
||||
this.title = "Follower";
|
||||
this.setRank();
|
||||
}
|
||||
setRank() {
|
||||
if (this.totalStartgazer >= 500) {
|
||||
if (this.totalStartgazer >= 100) {
|
||||
this.rank = "S";
|
||||
this.topMessage = "Celebrity";
|
||||
this.bottomMessage = "+500";
|
||||
} else if (this.totalStartgazer >= 200) {
|
||||
this.bottomMessage = "+100";
|
||||
} else if (this.totalStartgazer >= 20) {
|
||||
this.rank = "A";
|
||||
this.topMessage = "Famous User";
|
||||
this.bottomMessage = "+200";
|
||||
} else if (this.totalStartgazer >= 50) {
|
||||
this.bottomMessage = "+20";
|
||||
} else if (this.totalStartgazer >= 10) {
|
||||
this.rank = "B";
|
||||
this.topMessage = "Many Friends";
|
||||
this.bottomMessage = "+50";
|
||||
this.bottomMessage = "+10";
|
||||
} else if (this.totalStartgazer >= 1) {
|
||||
this.rank = "C";
|
||||
this.topMessage = "First Friend";
|
||||
|
|
@ -118,3 +118,83 @@ export class TotalFollowerTrophy extends Trophy {
|
|||
}
|
||||
}
|
||||
}
|
||||
export class TotalIssueTrophy extends Trophy {
|
||||
constructor(private totalStartgazer: Number) {
|
||||
super();
|
||||
this.title = "Issue";
|
||||
this.setRank();
|
||||
}
|
||||
setRank() {
|
||||
if (this.totalStartgazer >= 100) {
|
||||
this.rank = "S";
|
||||
this.topMessage = "Super Issuer";
|
||||
this.bottomMessage = "+100";
|
||||
} else if (this.totalStartgazer >= 20) {
|
||||
this.rank = "A";
|
||||
this.topMessage = "High Issuer";
|
||||
this.bottomMessage = "+20";
|
||||
} else if (this.totalStartgazer >= 10) {
|
||||
this.rank = "B";
|
||||
this.topMessage = "Middle Issuer";
|
||||
this.bottomMessage = "+10";
|
||||
} else if (this.totalStartgazer >= 1) {
|
||||
this.rank = "C";
|
||||
this.topMessage = "First Issue";
|
||||
this.bottomMessage = "+1";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class TotalPullRequestTrophy extends Trophy {
|
||||
constructor(private totalStartgazer: Number) {
|
||||
super();
|
||||
this.title = "PR";
|
||||
this.setRank();
|
||||
}
|
||||
setRank() {
|
||||
if (this.totalStartgazer >= 100) {
|
||||
this.rank = "S";
|
||||
this.topMessage = "God PR User";
|
||||
this.bottomMessage = "+100";
|
||||
} else if (this.totalStartgazer >= 20) {
|
||||
this.rank = "A";
|
||||
this.topMessage = "High PR User";
|
||||
this.bottomMessage = "+20";
|
||||
} else if (this.totalStartgazer >= 10) {
|
||||
this.rank = "B";
|
||||
this.topMessage = "Many PRs";
|
||||
this.bottomMessage = "+10";
|
||||
} else if (this.totalStartgazer >= 1) {
|
||||
this.rank = "C";
|
||||
this.topMessage = "First PR";
|
||||
this.bottomMessage = "+1";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class TotalRepositoryTrophy extends Trophy {
|
||||
constructor(private totalStartgazer: Number) {
|
||||
super();
|
||||
this.title = "Repo";
|
||||
this.setRank();
|
||||
}
|
||||
setRank() {
|
||||
if (this.totalStartgazer >= 100) {
|
||||
this.rank = "S";
|
||||
this.topMessage = "God Repo Creator";
|
||||
this.bottomMessage = "+100";
|
||||
} else if (this.totalStartgazer >= 20) {
|
||||
this.rank = "A";
|
||||
this.topMessage = "High Repo Creator";
|
||||
this.bottomMessage = "+20";
|
||||
} else if (this.totalStartgazer >= 10) {
|
||||
this.rank = "B";
|
||||
this.topMessage = "Many Repo";
|
||||
this.bottomMessage = "+10";
|
||||
} else if (this.totalStartgazer >= 1) {
|
||||
this.rank = "C";
|
||||
this.topMessage = "First Repository";
|
||||
this.bottomMessage = "+1";
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue