@kokkoro/web
Version:
Create web serve for kokkoro.
52 lines (51 loc) • 1.88 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.verifyGroupMsg = exports.verifyPrivateMsg = exports.verifyUin = exports.verifyKey = exports.verifyOnline = void 0;
const app_1 = require("../app");
const bot_service_1 = __importDefault(require("../service/bot.service"));
async function verifyOnline(ctx, next) {
const { uin } = ctx.request.body ?? {};
const bot = bot_service_1.default.getBot(uin);
const is_online = bot.isOnline();
if (!is_online) {
throw new app_1.SourceError(409, '该 bot 未登录');
}
await next();
}
exports.verifyOnline = verifyOnline;
async function verifyKey(ctx, next) {
const { KOKKORO_API_KEY } = process.env;
const { api_key } = ctx.request.body ?? {};
if (KOKKORO_API_KEY && (KOKKORO_API_KEY !== api_key)) {
throw new app_1.SourceError(403, '无效的 api key');
}
await next();
}
exports.verifyKey = verifyKey;
async function verifyUin(ctx, next) {
const { uin } = ctx.request.body ?? {};
if (!uin) {
throw new app_1.SourceError(403, 'uin 不能为空');
}
await next();
}
exports.verifyUin = verifyUin;
async function verifyPrivateMsg(ctx, next) {
const { user_id, message } = ctx.request.body ?? {};
if (!user_id || !message) {
throw new app_1.SourceError(403, '参数不能为空');
}
await next();
}
exports.verifyPrivateMsg = verifyPrivateMsg;
async function verifyGroupMsg(ctx, next) {
const { group_id, message } = ctx.request.body ?? {};
if (!group_id || !message) {
throw new app_1.SourceError(403, '参数不能为空');
}
await next();
}
exports.verifyGroupMsg = verifyGroupMsg;