"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __generator = (this && this.__generator) || function (thisArg, body) {
    var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
    return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
    function verb(n) { return function (v) { return step([n, v]); }; }
    function step(op) {
        if (f) throw new TypeError("Generator is already executing.");
        while (g && (g = 0, op[0] && (_ = 0)), _) try {
            if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
            if (y = 0, t) op = [op[0] & 2, t.value];
            switch (op[0]) {
                case 0: case 1: t = op; break;
                case 4: _.label++; return { value: op[1], done: false };
                case 5: _.label++; y = op[1]; op = [0]; continue;
                case 7: op = _.ops.pop(); _.trys.pop(); continue;
                default:
                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                    if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
                    if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                    if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                    if (t[2]) _.ops.pop();
                    _.trys.pop(); continue;
            }
            op = body.call(thisArg, _);
        } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
    }
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.createServer = void 0;
var fs = require("fs");
var path = require("path");
var Koa = require("koa");
var Router = require("koa-router");
var koaBody = require("koa-body");
var statics = require("koa-static");
var urlencode = require("urlencode");
var file_service_1 = require("./file.service");
var git_service_1 = require("./git.service");
var mysql_service_1 = require("./mysql.service");
var redis_service_1 = require("./redis.service");
var ssh_service_1 = require("./ssh.service");
var socket_service_1 = require("./socket.service");
var http_service_1 = require("./http.service");
var mongo_service_1 = require("./mongo.service");
// import { LoggerService } from './logger.service'
// import { MySqlService } from '../util/mysql.service'
var mySqlService = new mysql_service_1.MySqlService();
var redisService = new redis_service_1.RedisService();
var gitService = new git_service_1.GitService();
var fileService = new file_service_1.FileService();
var sshService = new ssh_service_1.SshService();
var socketService = new socket_service_1.SocketService();
var httpService = new http_service_1.HttpService();
var mongoService = new mongo_service_1.MongoService();
// const loggerService = new LoggerService()
// const staticPath = '../static'
var staticPath = '../view/dist';
var app = new Koa();
var router = new Router();
function createServer(_a) {
    var _this = this;
    var port = _a.port, rootPath = _a.rootPath;
    router.get("/", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        return __generator(this, function (_a) {
            // console.log('home')
            // ctx.body = 'home';
            ctx.body = fs.readFileSync(path.resolve(__dirname, '../view/dist/index.html'), 'utf8');
            return [2 /*return*/];
        });
    }); });
    // router.post(`/`, async (ctx) => {
    //     // console.log('home2', ctx.request.body)
    //     // ctx.body = 'home';
    //     const { text } = ctx.request.body
    //     // if (text) {
    //     //     // console.log('receive text:')
    //     //     console.log(text)
    //     // }
    //     console.log('home')
    //     // ctx.body = fs.readFileSync('index.html', 'utf8')
    //     // ctx.body = fs.readFileSync('view/dist/.html', 'utf8')
    //     ctx.response.body = 'linxot push demo'
    // })
    router.get("/api", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        return __generator(this, function (_a) {
            ctx.body = 'api home';
            return [2 /*return*/];
        });
    }); });
    router.post("/version", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var pkgContent, pkg;
        return __generator(this, function (_a) {
            pkgContent = fs.readFileSync(path.join(__dirname, '../package.json'), 'utf-8');
            pkg = JSON.parse(pkgContent);
            ctx.body = {
                version: pkg.version,
            };
            return [2 /*return*/];
        });
    }); });
    router.get("/redis", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, redisService.index()];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/redis/execCommands", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, redisService.execCommands(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/redis/clone", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, redisService.clone(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/redis/ping", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, redisService.ping(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/redis/expire", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, redisService.expire(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/redis/info", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, redisService.getInfo(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/redis/config", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, redisService.getConfig(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/redis/get", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, redisService.get(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/redis/lindex", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, redisService.lindex(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/redis/rpush", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, redisService.rpush(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/redis/zadd", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, redisService.zadd(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/redis/zrem", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, redisService.zrem(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/redis/sadd", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, redisService.sadd(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/redis/sreplace", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, redisService.sreplace(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/redis/hreplace", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, redisService.hreplace(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/redis/zreplace", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, redisService.zreplace(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/redis/srem", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, redisService.srem(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/redis/hset", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, redisService.hset(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/redis/hdel", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, redisService.hdel(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/redis/lset", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, redisService.lset(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/redis/lremove", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, redisService.lremove(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/redis/lremIndex", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, redisService.lremIndex(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/redis/set", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, redisService.set(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/redis/delete", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, redisService.delete(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    // router.post(`/redis/deleteKeys`, async (ctx) => {
    //     ctx.body = await redisService.deleteKeys(ctx.request.body)
    // })
    router.post("/redis/connect", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, redisService.connect(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/redis/keys", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, redisService.keys(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/redis/history/list", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, redisService.historyList(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/redis/history/clear", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, redisService.historyClear(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/redis/key/list", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, redisService.keyList(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/redis/key/create", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, redisService.keyCreate(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/redis/key/remove", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, redisService.keyRemove(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/redis/rename", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, redisService.rename(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/redis/connection/list", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, redisService.connectionList(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/redis/connection/update", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, redisService.connectionEdit(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/redis/connection/create", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, redisService.connectionCreate(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/redis/connection/delete", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, redisService.connectionDelete(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.get("/mysql", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, mySqlService.index()];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/mysql/connect", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, mySqlService.connect(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/mysql/reconnect", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, mySqlService.reconnect(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/mysql/databases", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, mySqlService.databases(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/mysql/schemas", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, mySqlService.schemas(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/mysql/tables", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, mySqlService.tables(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/mysql/execSqlSimple", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, mySqlService.execSqlSimple(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/mysql/execSql", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, mySqlService.execSql(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/mysql/tableDetail", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, mySqlService.tableDetail(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/mysql/tableInfo", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, mySqlService.tableDetailOld(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/mysql/history/list", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, mySqlService.historyList(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/mysql/history/clear", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, mySqlService.historyClear(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/mysql/sql/list", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, mySqlService.sqlList(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/mysql/sql/create", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, mySqlService.sqlCreate(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/mysql/sql/remove", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, mySqlService.sqlRemove(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/mysql/connection/list", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, mySqlService.connectionList(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/mysql/connection/update", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, mySqlService.connectionEdit(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/mysql/connection/create", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, mySqlService.connectionCreate(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/mysql/connection/delete", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, mySqlService.connectionDelete(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/mysql/compare", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, mySqlService.compare(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/mysql/connectionTables", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, mySqlService.connectionDatabases(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/mysql/connectionCompareData", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, mySqlService.connectionCompareData(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.get("/git", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, gitService.home(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/git/project", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, gitService.projectInfo(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/git/add", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, gitService.add(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/git/diff", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, gitService.diff(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/git/remote/list", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, gitService.remote(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/git/reset", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, gitService.reset(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/git/commit/list", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, gitService.commitList(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/git/tag/list", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, gitService.tagList(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/git/tag/create", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, gitService.tagCreate(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/git/tag/delete", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, gitService.tagDelete(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/git/branch", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, gitService.branchList(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/git/branch/create", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, gitService.branchCreate(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/git/branch/delete", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, gitService.branchDelete(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/git/status", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, gitService.status(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/git/commit", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, gitService.commit(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/git/project/list", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, gitService.projectList(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/git/project/create", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, gitService.projectCreate(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/git/project/delete", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, gitService.projectDelete(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/git/project/update", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, gitService.projectUpdate(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/git/remote/create", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, gitService.remoteCreate(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/git/push", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, gitService.push(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/git/fetch", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, gitService.fetch(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/git/pull", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, gitService.pull(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/git/checkout", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, gitService.checkout(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/git/cherryPick", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, gitService.cherryPick(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/git/show", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, gitService.show(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/git/commitFileChanged", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, gitService.commitFileChanged(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/git/cat", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, gitService.cat(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/git/getConfig", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, gitService.getConfig(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/git/checkoutFile", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, gitService.checkoutFile(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/git/merge", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, gitService.merge(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/git/command", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, gitService.command(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/git/deleteFile", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, gitService.deleteFile(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/git/userConfig", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, gitService.userConfig(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/git/userConfig/update", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, gitService.userConfigUpdate(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.get("/file", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, fileService.home(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/file/info", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, fileService.info(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/file/stat", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, fileService.stat(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/file/list", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, fileService.fileList(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/file/read", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, fileService.read(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/file/write", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, fileService.write(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/file/create", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, fileService.create(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/file/delete", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, fileService.delete(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/file/rename", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, fileService.rename(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.get("/file/imagePreview", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var sourceType, path, _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    sourceType = ctx.request.query.sourceType;
                    path = ctx.request.query.path;
                    if (path.endsWith('.svg')) {
                        ctx.set('Content-Type', 'image/svg+xml');
                    }
                    if (path.endsWith('.pdf')) {
                        ctx.set('Content-Type', 'application/pdf');
                    }
                    _a = ctx;
                    return [4 /*yield*/, fileService.imagePreview(ctx.request.query)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.get("/file/download", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    ctx.set('Content-disposition', "attachment; filename*=UTF-8''".concat(urlencode(ctx.request.query.fileName)));
                    ctx.set('Content-Type', 'application/octet-stream');
                    _a = ctx;
                    return [4 /*yield*/, fileService.download(ctx.request.query)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/file/collection/list", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, fileService.collectionList(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/file/collection/create", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, fileService.collectionCreate(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/file/openInFinder", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, fileService.openInFinder(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/file/copy", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, fileService.copy(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/file/aliyun", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, fileService.aliyun(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/swagger/list", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, fileService.swaggerList(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/swagger/detail", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, fileService.swaggerDetail(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/swagger/update", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, fileService.swaggerEdit(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/swagger/create", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, fileService.swaggerCreate(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/swagger/delete", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, fileService.swaggerDelete(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/project/list", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, fileService.projectList(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/project/create", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, fileService.projectCreate(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/project/update", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, fileService.projectUpdate(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/project/delete", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, fileService.projectDelete(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/service/list", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, fileService.serviceList(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/file/upload", koaBody({
        multipart: true,
        formidable: {
            maxFileSize: 10 * 1024 * 1024 * 1024, // 修改文件大小限制，默认位2M
        },
    }), function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var file, tmpPath, _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    file = ctx.request.files.file;
                    // console.log('ctx.request.files', file)
                    // console.log('ctx.request', ctx.request)
                    // const { text } = ctx.request.body
                    // let file = ctx.request.file; // 获取上传文件
                    // // 创建可读流
                    // const reader = fs.createReadStream(ctx.request.files['image']['path']);
                    // let filePath = `/shareSource/img/my_blog_img` + `/${ctx.request.files['image']['name']}`;
                    // let remotefilePath = `http://www.xxxx.com:8887/img/my_blog_img` + `/${ctx.request.files['image']['name']}`;
                    // // 创建可写流
                    // const upStream = fs.createWriteStream(filePath);
                    // // 可读流通过管道写入可写流
                    // reader.pipe(upStream);
                    // return ctx.body = {
                    //     url: remotefilePath,
                    //     message: "文件上传成功",
                    //     cc: 0
                    // }   
                    // 创建可读流
                    // console.log('pp', ctx.request.files['file']['path'])
                    // const reader = fs.createReadStream(ctx.request.files['file']['path']);
                    // let filePath = path.join(process.cwd(), file.name)
                    // // remotefilePath = `http://yourServerHostAndPath/images/${ctx.request.files['file']['name']}`;
                    // // 创建可写流
                    // const upStream = fs.createWriteStream(filePath);
                    // // 可读流通过管道写入可写流
                    // reader.pipe(upStream);
                    // ctx.body = 'ok';
                    // console.log(filePath)
                    // ctx.response.body = 'haha'
                    // console.log(text)
                    console.log('ctx.request', ctx.request);
                    console.log('ctx.request.files', ctx.request.files);
                    console.log('ctx.request.body', ctx.request.body);
                    tmpPath = ctx.request.files['file']['path'];
                    _a = ctx;
                    return [4 /*yield*/, fileService.upload(ctx.request.body, tmpPath)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/zip/list", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, fileService.zipList(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/oss/connect", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, fileService.ossConnect(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/oss/list", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, fileService.ossList(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/oss/accessKey/list", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, fileService.accessKeyList(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/oss/accessKey/update", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, fileService.accessKeyEdit(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/oss/accessKey/create", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, fileService.accessKeyCreate(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/oss/accessKey/delete", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, fileService.accessKeyDelete(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/oss/info", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, fileService.ossInfo(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/webdav/connect", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, fileService.webdavConnect(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/webdav/connection/list", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, fileService.webdavConnectionList(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/webdav/connection/update", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, fileService.webdavConnectionEdit(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/webdav/connection/create", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, fileService.webdavConnectionCreate(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/webdav/connection/delete", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, fileService.webdavConnectionDelete(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/sftp/connect", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, fileService.sftpConnect(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/logger/list", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, fileService.loggerList(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.get("/ssh", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, sshService.home(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/ssh/connect", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, sshService.connect(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/ssh/connection/list", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, sshService.connectionList(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/ssh/connection/update", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, sshService.connectionEdit(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/ssh/connection/create", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, sshService.connectionCreate(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/ssh/connection/delete", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, sshService.connectionDelete(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/ssh/command/list", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, sshService.commandList(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/socket/connect", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, socketService.connect(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/socket/send", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, socketService.send(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/socket/close", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, socketService.close(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/api/info", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, httpService.apiInfo(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/api/info", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, httpService.apiInfo(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/docs/path", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        return __generator(this, function (_a) {
            ctx.body = {
                path: path.resolve(__dirname, '../docs'),
            };
            return [2 /*return*/];
        });
    }); });
    router.post("/http/proxy", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, httpService.proxy(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/mongo/connection/list", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, mongoService.connectionList(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/mongo/connection/create", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, mongoService.connectionCreate(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/mongo/connection/update", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, mongoService.connectionUpdate(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/mongo/connection/delete", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, mongoService.connectionDelete(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/mongo/connect", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, mongoService.connect(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/mongo/databases", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, mongoService.databases(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/mongo/database/create", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, mongoService.databaseCreate(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/mongo/database/drop", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, mongoService.databaseDrop(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/mongo/collections", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, mongoService.collections(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/mongo/collection/create", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, mongoService.collectionCreate(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/mongo/collection/drop", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, mongoService.collectionDrop(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/mongo/documents", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, mongoService.documents(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/mongo/document/create", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, mongoService.documentCreate(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/mongo/document/update", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, mongoService.documentUpdate(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/mongo/document/remove", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, mongoService.documentRemove(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/mongo/index/list", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, mongoService.indexList(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    router.post("/mongo/mock", function (ctx) { return __awaiter(_this, void 0, void 0, function () {
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    _a = ctx;
                    return [4 /*yield*/, mongoService.mock(ctx.request.body)];
                case 1:
                    _a.body = _b.sent();
                    return [2 /*return*/];
            }
        });
    }); });
    // router.post(`/sls/list`, async (ctx) => {
    //     ctx.body = await loggerService.slsList(ctx.request.body)
    // })
    app.use(function (ctx, next) { return __awaiter(_this, void 0, void 0, function () {
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    // console.log('跨域？')
                    ctx.set('Access-Control-Allow-Origin', '*');
                    ctx.set('Access-Control-Allow-Headers', 'Content-Type, Content-Length, Authorization, Accept, X-Requested-With , yourHeaderFeild');
                    ctx.set('Access-Control-Allow-Methods', 'PUT, POST, GET, DELETE, OPTIONS');
                    if (!(ctx.method == 'OPTIONS')) return [3 /*break*/, 1];
                    // console.log('OPTIONS')
                    ctx.status = 200;
                    ctx.body = 'cros ok';
                    return [3 /*break*/, 3];
                case 1: 
                //   await next();
                return [4 /*yield*/, next()];
                case 2:
                    //   await next();
                    _a.sent();
                    _a.label = 3;
                case 3: return [2 /*return*/];
            }
        });
    }); });
    app.use(function (ctx, next) { return __awaiter(_this, void 0, void 0, function () {
        var err_1;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    _a.trys.push([0, 2, , 3]);
                    return [4 /*yield*/, next()];
                case 1:
                    _a.sent();
                    return [3 /*break*/, 3];
                case 2:
                    err_1 = _a.sent();
                    console.error(err_1);
                    ctx.status = 500;
                    ctx.body = {
                        message: err_1.message || 'Unknown Error'
                    };
                    return [3 /*break*/, 3];
                case 3: return [2 /*return*/];
            }
        });
    }); });
    app.use(statics(path.join(__dirname, staticPath)));
    // app.use(koaBody({
    //     multipart:true, // 支持文件上传
    //     encoding:'gzip',
    //     formidable:{
    //         uploadDir:path.join(__dirname,'public/upload/'), // 设置文件上传目录
    //         keepExtensions: true,    // 保持文件的后缀
    //         maxFieldsSize:2 * 1024 * 1024, // 文件上传大小
    //         onFileBegin:(name,file) => { // 文件上传前的设置
    //         console.log(`name: ${name}`);
    //         console.log(file);
    //         },
    //     }
    //     }));
    app.use(koaBody({
        // formLimit:"10mb",
        // jsonLimit:"10mb"
        formLimit: "20mb",
        jsonLimit: "20mb",
        textLimit: "20mb",
    }));
    // app.use(koaBody({
    //     multipart: true,  // 支持表单上传
    //     formidable: {
    //       maxFileSize: 10 * 1024 * 1024, // 修改文件大小限制，默认位2M
    //     }
    //   }))
    app.use(router.routes());
    // app.use(async ctx => {
    //   ctx.body = 'Hello World';
    // });
    app.listen(port);
    // console.log('ok')
}
exports.createServer = createServer;
//# sourceMappingURL=server.js.map