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
30
dev_main.ts
30
dev_main.ts
|
|
@ -1,11 +1,29 @@
|
||||||
import { serve } from "https://deno.land/std@0.66.0/http/server.ts";
|
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 { Card } from "./src/card.ts";
|
||||||
|
import "https://deno.land/x/dotenv@v0.5.0/load.ts";
|
||||||
|
|
||||||
const s = serve({ port: 8080 });
|
const s = serve({ port: 8080 });
|
||||||
|
const client = new GithubAPIClient();
|
||||||
for await (const req of s) {
|
for await (const req of s) {
|
||||||
req.respond(
|
const username = new URLSearchParams(req.url.split("?")[1]).get("username")
|
||||||
{
|
|
||||||
body: new Card().render(),
|
if (username != null) {
|
||||||
headers: new Headers({ "Content-Type": "image/svg+xml" }),
|
const userInfo = await client.requestUserInfo(username);
|
||||||
},
|
req.respond(
|
||||||
);
|
{
|
||||||
|
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" }),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
27
index.ts
27
index.ts
|
|
@ -5,12 +5,23 @@ 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 userInfo = await client.requestUserInfo("ryo-ma")
|
const username = new URLSearchParams(req.url.split("?")[1]).get("username");
|
||||||
const cardSize = 110;
|
|
||||||
req.respond(
|
if (username != null) {
|
||||||
{
|
const userInfo = await client.requestUserInfo(username);
|
||||||
body: new Card(cardSize).render(),
|
req.respond(
|
||||||
headers: new Headers({ "Content-Type": "image/svg+xml" }),
|
{
|
||||||
},
|
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,
|
TotalStarTrophy,
|
||||||
TotalCommitTrophy,
|
TotalCommitTrophy,
|
||||||
TotalFollowerTrophy,
|
TotalFollowerTrophy,
|
||||||
|
TotalIssueTrophy,
|
||||||
|
TotalPullRequestTrophy,
|
||||||
|
TotalRepositoryTrophy,
|
||||||
} from "./trophies.ts";
|
} from "./trophies.ts";
|
||||||
|
import {UserInfo} from "./github_api_client.ts";
|
||||||
|
|
||||||
export class Card {
|
export class Card {
|
||||||
private width = 0;
|
private width = 0;
|
||||||
|
|
@ -16,32 +20,15 @@ export class Card {
|
||||||
this.width = panelSize * this.maxPanelWidthCount;
|
this.width = panelSize * this.maxPanelWidthCount;
|
||||||
this.height = panelSize * this.maxPanelHeightCount;
|
this.height = panelSize * this.maxPanelHeightCount;
|
||||||
}
|
}
|
||||||
render(): string {
|
render(userInfo: UserInfo): string {
|
||||||
const trophy1 = new TotalStarTrophy(0);
|
const trophyList = new Array<Trophy>(
|
||||||
const trophy2 = new TotalStarTrophy(100);
|
new TotalStarTrophy(userInfo.totalStargazers),
|
||||||
const trophy3 = new TotalStarTrophy(500);
|
new TotalCommitTrophy(userInfo.totalCommits),
|
||||||
const trophy4 = new TotalStarTrophy(1000);
|
new TotalFollowerTrophy(userInfo.totalFollowers),
|
||||||
const trophy5 = new TotalCommitTrophy(1);
|
new TotalIssueTrophy(userInfo.totalIssues),
|
||||||
const trophy6 = new TotalCommitTrophy(200);
|
new TotalPullRequestTrophy(userInfo.totalPullRequests),
|
||||||
const trophy7 = new TotalCommitTrophy(1000);
|
new TotalRepositoryTrophy(userInfo.totalRepositories),
|
||||||
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);
|
|
||||||
const renderdTrophy = trophyList.reduce(
|
const renderdTrophy = trophyList.reduce(
|
||||||
(sum: string, trophy: Trophy, i: number) => {
|
(sum: string, trophy: Trophy, i: number) => {
|
||||||
let x = (this.panelSize * i);
|
let x = (this.panelSize * i);
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import {soxa} from "../deps.ts";
|
import {soxa} from "../deps.ts";
|
||||||
class UserInfo {
|
export class UserInfo {
|
||||||
constructor(
|
constructor(
|
||||||
public totalCommits: Number,
|
public totalCommits: Number,
|
||||||
public totalFollowers: 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 {
|
export class TotalStarTrophy extends Trophy {
|
||||||
constructor(private totalStartgazer: Number) {
|
constructor(private totalStartgazer: Number) {
|
||||||
super();
|
super();
|
||||||
this.title = "STAR";
|
this.title = "Star";
|
||||||
this.setRank();
|
this.setRank();
|
||||||
}
|
}
|
||||||
setRank() {
|
setRank() {
|
||||||
if (this.totalStartgazer >= 1000) {
|
if (this.totalStartgazer >= 200) {
|
||||||
this.rank = "S";
|
this.rank = "S";
|
||||||
this.topMessage = "Super Star";
|
this.topMessage = "Super Star";
|
||||||
this.bottomMessage = "+1000";
|
this.bottomMessage = "+200";
|
||||||
} else if (this.totalStartgazer >= 500) {
|
} else if (this.totalStartgazer >= 100) {
|
||||||
this.rank = "A";
|
this.rank = "A";
|
||||||
this.topMessage = "High Star";
|
this.topMessage = "High Star";
|
||||||
this.bottomMessage = "+500";
|
this.bottomMessage = "+100";
|
||||||
} else if (this.totalStartgazer >= 100) {
|
} else if (this.totalStartgazer >= 10) {
|
||||||
this.rank = "B";
|
this.rank = "B";
|
||||||
this.topMessage = "Middle Star";
|
this.topMessage = "Middle Star";
|
||||||
this.bottomMessage = "+100";
|
this.bottomMessage = "+10";
|
||||||
} else if (this.totalStartgazer >= 1) {
|
} else if (this.totalStartgazer >= 1) {
|
||||||
this.rank = "C";
|
this.rank = "C";
|
||||||
this.topMessage = "First Star";
|
this.topMessage = "First Star";
|
||||||
|
|
@ -68,22 +68,22 @@ export class TotalStarTrophy extends Trophy {
|
||||||
export class TotalCommitTrophy extends Trophy {
|
export class TotalCommitTrophy extends Trophy {
|
||||||
constructor(private totalStartgazer: Number) {
|
constructor(private totalStartgazer: Number) {
|
||||||
super();
|
super();
|
||||||
this.title = "COMMIT";
|
this.title = "Commit";
|
||||||
this.setRank();
|
this.setRank();
|
||||||
}
|
}
|
||||||
setRank() {
|
setRank() {
|
||||||
if (this.totalStartgazer >= 5000) {
|
if (this.totalStartgazer >= 1000) {
|
||||||
this.rank = "S";
|
this.rank = "S";
|
||||||
this.topMessage = "Super Commiter";
|
this.topMessage = "Super Commiter";
|
||||||
this.bottomMessage = "+5000";
|
this.bottomMessage = "+1000";
|
||||||
} else if (this.totalStartgazer >= 1000) {
|
} else if (this.totalStartgazer >= 500) {
|
||||||
this.rank = "A";
|
this.rank = "A";
|
||||||
this.topMessage = "High Commiter";
|
this.topMessage = "High Commiter";
|
||||||
this.bottomMessage = "+1000";
|
this.bottomMessage = "+500";
|
||||||
} else if (this.totalStartgazer >= 200) {
|
} else if (this.totalStartgazer >= 100) {
|
||||||
this.rank = "B";
|
this.rank = "B";
|
||||||
this.topMessage = "Middle Commiter";
|
this.topMessage = "Middle Commiter";
|
||||||
this.bottomMessage = "+200";
|
this.bottomMessage = "+100";
|
||||||
} else if (this.totalStartgazer >= 1) {
|
} else if (this.totalStartgazer >= 1) {
|
||||||
this.rank = "C";
|
this.rank = "C";
|
||||||
this.topMessage = "First Commit";
|
this.topMessage = "First Commit";
|
||||||
|
|
@ -95,22 +95,22 @@ export class TotalCommitTrophy extends Trophy {
|
||||||
export class TotalFollowerTrophy extends Trophy {
|
export class TotalFollowerTrophy extends Trophy {
|
||||||
constructor(private totalStartgazer: Number) {
|
constructor(private totalStartgazer: Number) {
|
||||||
super();
|
super();
|
||||||
this.title = "FOLLOWER";
|
this.title = "Follower";
|
||||||
this.setRank();
|
this.setRank();
|
||||||
}
|
}
|
||||||
setRank() {
|
setRank() {
|
||||||
if (this.totalStartgazer >= 500) {
|
if (this.totalStartgazer >= 100) {
|
||||||
this.rank = "S";
|
this.rank = "S";
|
||||||
this.topMessage = "Celebrity";
|
this.topMessage = "Celebrity";
|
||||||
this.bottomMessage = "+500";
|
this.bottomMessage = "+100";
|
||||||
} else if (this.totalStartgazer >= 200) {
|
} else if (this.totalStartgazer >= 20) {
|
||||||
this.rank = "A";
|
this.rank = "A";
|
||||||
this.topMessage = "Famous User";
|
this.topMessage = "Famous User";
|
||||||
this.bottomMessage = "+200";
|
this.bottomMessage = "+20";
|
||||||
} else if (this.totalStartgazer >= 50) {
|
} else if (this.totalStartgazer >= 10) {
|
||||||
this.rank = "B";
|
this.rank = "B";
|
||||||
this.topMessage = "Many Friends";
|
this.topMessage = "Many Friends";
|
||||||
this.bottomMessage = "+50";
|
this.bottomMessage = "+10";
|
||||||
} else if (this.totalStartgazer >= 1) {
|
} else if (this.totalStartgazer >= 1) {
|
||||||
this.rank = "C";
|
this.rank = "C";
|
||||||
this.topMessage = "First Friend";
|
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