"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Response = void 0;
const decorator_1 = require("@midwayjs/decorator");
const db_1 = require("../db");
let Response = class Response {
    /**
     * 返回文件下载
     * @param value 文件内容
     * @param fileName  文件名称
     */
    download(value, fileName) {
        fileName = encodeURIComponent(fileName);
        this.ctx.type = 'application/octet-stream';
        this.ctx.set({
            'Content-Disposition': `attachment; filename="${fileName}"`,
        });
        this.ctx.ignoreFormat = true;
        return value;
    }
    /**
     * 自定义json返回
     * @param json
     */
    json(json) {
        this.ctx.ignoreFormat = true;
        return json;
    }
    /**
     * 自定义分页返回
     * @param total 总数
     * @param array 数据
     */
    page(total, array) {
        return new db_1.PageResult(total, array);
    }
    /**
     * 返回图片
     * @param img 图片数据
     * @param mime 图片类型，如`image/png`、`image/jpeg`、`image/gif`、`image/svg+xml`、`image/bmp`
     */
    image(img, mime) {
        this.ctx.ignoreFormat = true;
        this.ctx.type = mime;
        return img;
    }
    /**
     * 返回文本
     * @param text 文本数据
     */
    text(text) {
        this.ctx.ignoreFormat = true;
        this.ctx.type = 'text';
        return text;
    }
};
__decorate([
    (0, decorator_1.Inject)(),
    __metadata("design:type", Object)
], Response.prototype, "ctx", void 0);
Response = __decorate([
    (0, decorator_1.Provide)()
], Response);
exports.Response = Response;
//# sourceMappingURL=Response.js.map