Last active
February 23, 2019 20:44
-
-
Save uditalias/f524fc704a4b60e4d07abedfafaef426 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { controller, Controller, inject, get, IRequest, IResponse, validation } from "appolo"; | |
import { LangaugeModel } from "./langaugeModel"; | |
import { LangaugeManager } from "../../managers/langaugeManager"; | |
import { OutputFormatContentType } from "../../common/enums"; | |
import { promisify } from "util"; | |
import * as zlib from "zlib"; | |
const gzip = promisify<Buffer, Buffer>(zlib.gzip); | |
@controller() | |
export class LangaugeController extends Controller { | |
@inject() private langaugeManager: LangaugeManager; | |
@get("/:owner/:repo") | |
@validation(LangaugeModel) | |
public async langauge(req: IRequest, res: IResponse, model: LangaugeModel) { | |
const { owner, repo, maxAge, ...rest } = model; | |
res.setHeader("Content-Type", OutputFormatContentType[model.output]); | |
res.setHeader("Content-Encoding", "gzip"); | |
res.setHeader("Cache-Control", `max-age=${maxAge}`); | |
const bitmapBuffer = await this.langaugeManager.generate(owner, repo, rest); | |
return gzip(bitmapBuffer); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment