Skip to content

Commit

Permalink
chore: remove the hardcoded style
Browse files Browse the repository at this point in the history
Signed-off-by: STRRL <im@strrl.dev>
  • Loading branch information
STRRL committed Jul 6, 2022
1 parent 5bab944 commit 69019da
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/badge.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
export function fetchBadgeURL(
label: string,
message: string,
query: string,
color = "brightgreen"
): string {
return `https://img.shields.io/badge/${label}-${message}-${color}?style=flat-square`;
return `https://img.shields.io/badge/${label}-${message}-${color}${query}`;
}
14 changes: 10 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ export interface Env {
//
// Example binding to R2. Learn more at https://developers.cloudflare.com/workers/runtime-apis/r2/
// MY_BUCKET: R2Bucket;
// There are several required secret environment variables, replace with wrangler secrets put <secret-name> before deploy your own service.

// There are several required secret environment variables, replace with wrangler secrets put <secret-name> before deploy your own service.
GITHUB_APP_ID: string;
GITHUB_APP_PRIVATE_KEY: string;
GITHUB_APP_DEFAULT_INSTALLATION_ID: string;
Expand Down Expand Up @@ -62,8 +62,13 @@ export default {
`github-repo-visit-${githubUsername}-${githubRepoName}`,
env.VISITS_KV
);

return await buildNoCacheResponseAsProxy(fetchBadgeURL("Visits", count.toString()));
let query = "";
if (request.url.includes("?")) {
query = request.url.substring(request.url.indexOf("?"));
}
return await buildNoCacheResponseAsProxy(
fetchBadgeURL("Visits", count.toString(), query)
);
}
return new Response(
`No Permission to Access GitHub Repository: ${githubUsername}/${githubRepoName}. Please Make Sure It Exists, and Installed the Github App “Serverless Github Badges” for the Private Repository.`
Expand All @@ -72,6 +77,7 @@ export default {
return new Response("Serverless Badges Service with Cloudflare Workers.");
} catch (err) {
sentry.captureException(err);
console.log(err);
return new Response("Something went wrong", {
status: 500,
statusText: "Internal Server Error",
Expand Down

0 comments on commit 69019da

Please sign in to comment.