Added color calculator and fixed badges so they no longer 404
parent
82e2168fc6
commit
7e6e1dd06a
|
@ -1,6 +1,7 @@
|
|||
import { Request, Response, Router } from "express";
|
||||
import * as request from "request";
|
||||
import { ReferenceRepo, RepoFileFetcher } from "../../github";
|
||||
import { ColorConverter } from "../color-converter";
|
||||
|
||||
export class AwardsRouter {
|
||||
public router: Router;
|
||||
|
@ -24,7 +25,8 @@ export class AwardsRouter {
|
|||
const repo = req.params.repo as string;
|
||||
|
||||
this.fetchDetails(owner, repo).then((result) => {
|
||||
request(`https://img.shields.io/badgea/wards%20mod%20completion-${result.percentage}%25-green.svg`).pipe(res);
|
||||
const color = ColorConverter.percentageToHexColor(result.percentage);
|
||||
request(`https://img.shields.io/badge/wards%20mod%20completion-${result.percentage}%25-${color}.svg`).pipe(res);
|
||||
}).catch((error) => {
|
||||
res.status(400).json({ message: `${repo} is not a mod!` });
|
||||
});
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
export class ColorConverter {
|
||||
public static percentageToHexColor(percentage: number): string {
|
||||
const green = Math.floor((255 / 100) * percentage);
|
||||
const hex = this.componentToHex(255 - green) + this.componentToHex(green) + this.componentToHex(0);
|
||||
return hex;
|
||||
}
|
||||
|
||||
private static componentToHex(c: number): string {
|
||||
const hex = c.toString(16);
|
||||
return hex.length === 1 ? "0" + hex : hex;
|
||||
}
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
import { Request, Response, Router } from "express";
|
||||
import * as request from "request";
|
||||
import { ReferenceRepo, RepoFileFetcher } from "../../github";
|
||||
import { ColorConverter } from "../color-converter";
|
||||
|
||||
export class FarmingRouter {
|
||||
public router: Router;
|
||||
|
@ -24,7 +25,8 @@ export class FarmingRouter {
|
|||
const repo = req.params.repo as string;
|
||||
|
||||
this.fetchDetails(owner, repo).then((result) => {
|
||||
request(`https://img.shields.io/badge/farming%20mod%20completion-${result.percentage}%25-green.svg`).pipe(res);
|
||||
const color = ColorConverter.percentageToHexColor(result.percentage);
|
||||
request(`https://img.shields.io/badge/farming%20mod%20completion-${result.percentage}%25-${color}.svg`).pipe(res);
|
||||
}).catch((error) => {
|
||||
res.status(400).json({ message: `${repo} is not a mod!` });
|
||||
});
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { Request, Response, Router } from "express";
|
||||
import * as request from "request";
|
||||
import { ReferenceRepo, RepoFileFetcher } from "../../github";
|
||||
import { ColorConverter } from "../color-converter";
|
||||
|
||||
export class ModRouter {
|
||||
public router: Router;
|
||||
|
@ -18,7 +19,9 @@ export class ModRouter {
|
|||
const repo = req.params.repo as string;
|
||||
|
||||
this.fetchDetails(modOwner, modRepo, owner, repo).then((result) => {
|
||||
request(`https://img.shields.io/badgea/wards%20mod%20completion-${result.percentage}%25-green.svg`).pipe(res);
|
||||
const displayName = modRepo.replace("minetest-", "");
|
||||
const color = ColorConverter.percentageToHexColor(result.percentage);
|
||||
request(`https://img.shields.io/badge/${displayName}-${result.percentage}%25-${color}.svg`).pipe(res);
|
||||
}).catch((error) => {
|
||||
res.status(400).json({ message: `${repo} is not a mod!` });
|
||||
});
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { Request, Response, Router } from "express";
|
||||
import * as request from "request";
|
||||
import { ReferenceRepo, RepoFileFetcher } from "../../github";
|
||||
import { ColorConverter } from "../color-converter";
|
||||
|
||||
export class NetherRouter {
|
||||
public router: Router;
|
||||
|
@ -24,7 +25,8 @@ export class NetherRouter {
|
|||
const repo = req.params.repo as string;
|
||||
|
||||
this.fetchDetails(owner, repo).then((result) => {
|
||||
request(`https://img.shields.io/badge/farming%20mod%20completion-${result.percentage}%25-green.svg`).pipe(res);
|
||||
const color = ColorConverter.percentageToHexColor(result.percentage);
|
||||
request(`https://img.shields.io/badge/nether%20completion-${result.percentage}%25-${color}.svg`).pipe(res);
|
||||
}).catch((error) => {
|
||||
res.status(400).json({ message: `${repo} is not a mod!` });
|
||||
});
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { Request, Response, Router } from "express";
|
||||
import * as request from "request";
|
||||
import { ReferenceRepo, RepoFileFetcher } from "../../github";
|
||||
import { ColorConverter } from "../color-converter";
|
||||
|
||||
export class TexturePackRouter {
|
||||
public router: Router;
|
||||
|
@ -24,7 +25,8 @@ export class TexturePackRouter {
|
|||
const repo = req.params.repo as string;
|
||||
|
||||
this.fetchDetails(owner, repo).then((result) => {
|
||||
request(`https://img.shields.io/badge/texture%20pack%20completion-${result.percentage}%25-green.svg`).pipe(res);
|
||||
const color = ColorConverter.percentageToHexColor(result.percentage);
|
||||
request(`https://img.shields.io/badge/texture%20pack%20completion-${result.percentage}%25-${color}.svg`).pipe(res);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue