"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ImageController = void 0;
const FOLDER_TO_ENTITY_TYPE = {
    networks: 'network',
    tokens: 'token',
};
const parseFilename = (filename) => {
    const id = filename.replace(/\.[^.]+$/, '');
    return { id };
};
class ImageController {
    getImageUseCase;
    constructor(getImageUseCase) {
        this.getImageUseCase = getImageUseCase;
    }
    getImage = async (req, res, next) => {
        try {
            const type = FOLDER_TO_ENTITY_TYPE[req.params.type];
            if (!type) {
                res.status(404).json({ success: false, message: 'Invalid image type' });
                return;
            }
            const { id } = parseFilename(req.params.filename);
            const image = await this.getImageUseCase.execute(type, id);
            res.set('Content-Type', image.contentType);
            res.set('Cache-Control', 'public, max-age=86400');
            res.status(200).send(image.buffer);
        }
        catch (error) {
            next(error);
        }
    };
}
exports.ImageController = ImageController;
//# sourceMappingURL=image.controller.js.map