"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.MagicMiddleware = void 0;
const decorator_1 = require("@midwayjs/decorator");
const magic_1 = require("../magic");
/**
 * magic接口处理器
 */
let MagicMiddleware = class MagicMiddleware {
    resolve() {
        return async (ctx, next) => {
            await this.magicApi.middleware()(ctx, next);
            return ctx.body;
        };
    }
    match(ctx) {
        // 下面的匹配到的路由会执行此中间件
        return (0, magic_1.isNotBlank)(this.magicConfig.prefix)
            ? ctx.path.indexOf(this.magicConfig.prefix) === 0
            : true;
    }
    static getName() {
        return 'magic';
    }
};
__decorate([
    (0, decorator_1.Inject)(),
    __metadata("design:type", magic_1.MagicApi)
], MagicMiddleware.prototype, "magicApi", void 0);
__decorate([
    (0, decorator_1.Config)('magic'),
    __metadata("design:type", Object)
], MagicMiddleware.prototype, "magicConfig", void 0);
MagicMiddleware = __decorate([
    (0, decorator_1.Middleware)()
], MagicMiddleware);
exports.MagicMiddleware = MagicMiddleware;
//# sourceMappingURL=magic.middleware.js.map