<commit_before>import { Request, Response, Router } from "express";
import * as request from "request";
import * as logger from "winston";

import { Observable } from "rxjs/Rx";
import { ImageFetcher } from "./image-fetcher";
import { SkillsFetcher } from "./skill-fetcher";
import { ISkillDocument } from "./skill-model";

interface ISkillCombinedResult {
    image: GoogleImageResult;
    document: ISkillDocument;
}

export class SkillsRouter {
    public router: Router;
    private skillsFetcher: SkillsFetcher;
    private imageFetcher: ImageFetcher;
    private combinedObservable: Observable<ISkillCombinedResult[]>;

    constructor(config: IConfig) {
        this.router = Router();
        this.skillsFetcher = new SkillsFetcher();
        this.imageFetcher = new ImageFetcher(config.googleSearch);

        this.combinedObservable = this.skillsFetcher.WhenFetchedSkills.flatMap((skills) => {
            const observables: Observable<ISkillCombinedResult>[] = [];
            skills.forEach((skill) => {
                observables.push(this.imageFetcher.findImage(skill.name).map((image) => {
                    return {
                        image: image,
                        document: skill,
                    };
                }));
            });
            return Observable.forkJoin(observables);
        });

        this.init();
    }

    public init(): void {
        this.router.get("/", (req: Request, res: Response) => {
            logger.debug("Getting skills");

            this.combinedObservable.subscribe((data) => {
                res.status(200).send(data);
            }, (err) => {
                logger.error(err);
                const errorResponse: ServerError = {
                    message: "Something went wrong with the server",
                };
                res.status(500).send(errorResponse);
            });
        });

        this.router.get("/:id/image", (req: Request, res: Response) => {
            const skillId = req.params.id as string;

            this.skillsFetcher.WhenFetchedSkills.map((skills) => {
                return skills.find((skill) => skill._id.toString() === skillId).name;
            }).flatMap((skillName) => {
                return this.imageFetcher.findImage(skillName);
            }).flatMap((image) => {
                const getAsObservable = Observable.bindCallback<[Error, request.RequestResponse, Buffer]>(request.get);
                return getAsObservable({
                    url: image.url,
                    encoding: null,
                }).map(([err, response, body]) => {
                    const type = response.headers["content-type"];
                    const prefix = "data:" + type + ";base64,";
                    const base64 = body.toString("base64");
                    return prefix + base64;
                });
            }).subscribe((base64) => {
                res.status(200).send(base64);
            });
        });
    }
}<commit_msg>Made base64 part of the response<commit_after>import { Request, Response, Router } from "express";
import * as request from "request";
import * as logger from "winston";

import { Observable } from "rxjs/Rx";
import { ImageFetcher } from "./image-fetcher";
import { SkillsFetcher } from "./skill-fetcher";

interface ISkillCombinedResult {
    image: string;
    name: string;
}

export class SkillsRouter {
    public router: Router;
    private skillsFetcher: SkillsFetcher;
    private imageFetcher: ImageFetcher;
    private combinedObservable: Observable<ISkillCombinedResult[]>;

    constructor(config: IConfig) {
        this.router = Router();
        this.skillsFetcher = new SkillsFetcher();
        this.imageFetcher = new ImageFetcher(config.googleSearch);

        this.combinedObservable = this.skillsFetcher.WhenFetchedSkills.flatMap((skills) => {
            const observables: Observable<ISkillCombinedResult>[] = [];
            skills.forEach((skill) => {
                observables.push(this.imageFetcher.findImage(skill.name).flatMap((image) => {
                    const getAsObservable = Observable.bindCallback<[Error, request.RequestResponse, Buffer]>(request.get);
                    return getAsObservable({
                        url: image.url,
                        encoding: null,
                    }).map(([err, response, body]) => {
                        const type = response.headers["content-type"];
                        const prefix = "data:" + type + ";base64,";
                        const base64 = body.toString("base64");
                        return prefix + base64;
                    });
                }).map((base64) => {
                    return {
                        image: base64,
                        name: skill.name,
                    };
                }));
            });
            return Observable.forkJoin(observables);
        });

        this.init();
    }

    public init(): void {
        this.router.get("/", (req: Request, res: Response) => {
            logger.debug("Getting skills");

            this.combinedObservable.subscribe((data) => {
                res.status(200).send(data);
            }, (err) => {
                logger.error(err);
                const errorResponse: ServerError = {
                    message: "Something went wrong with the server",
                };
                res.status(500).send(errorResponse);
            });
        });
    }
}
{'fraction_non_alphanumeric': 0.12440454378893367, 'fraction_numerical': 0.007511909124221327, 'mean_word_length': 1.808127572016461, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1516039', 'n_tokens_mistral': 1454, 'n_tokens_neox': 1392, 'n_words': 285}