core: cli: fix ObjectID convert & serializer

pull/96/head
undefined 4 years ago
parent 4ccb9f3283
commit 981b21160f

@ -63,7 +63,7 @@ async function cli() {
return console.error(parameters.join(', '));
}
for (let i = 0; i < args.length; i++) {
if (ObjectID.isValid(args[i])) {
if (args[i].length === 24 && ObjectID.isValid(args[i])) {
args[i] = new ObjectID(args[i]);
}
}

@ -249,14 +249,12 @@ class UserModel {
@ArgMethod
static async setSuperAdmin(uid: number) {
await UserModel.setPriv(uid, PRIV.PRIV_ALL);
return uid;
return await UserModel.setPriv(uid, PRIV.PRIV_ALL);
}
@ArgMethod
static async setJudge(uid: number) {
await UserModel.setPriv(uid, PRIV.PRIV_USER_PROFILE | PRIV.PRIV_JUDGE);
return uid;
return await UserModel.setPriv(uid, PRIV.PRIV_USER_PROFILE | PRIV.PRIV_JUDGE);
}
@ArgMethod

@ -16,7 +16,6 @@ import proxy from 'koa-proxies';
import cache from 'koa-static-cache';
import sockjs from 'sockjs';
import type { SetOption } from 'cookies';
import serialize, { SerializeJSOptions } from 'serialize-javascript';
import { argv } from 'yargs';
import { createHash } from 'crypto';
import * as bus from './bus';
@ -27,7 +26,7 @@ import {
UserNotFoundError, BlacklistedError, PermissionError,
UserFacingError, ValidationError, PrivilegeError,
CsrfTokenError, InvalidOperationError, MethodNotAllowedError,
NotFoundError, HydroError,
NotFoundError, HydroError, SystemError,
} from '../error';
import * as misc from '../lib/misc';
import { isContent, isName, isTitle } from '../lib/validator';
@ -483,7 +482,7 @@ export class Handler extends HandlerCommon {
}
async init({ domainId }) {
if (!argv.benchmark) await this.limitRate('global', 10, 50);
if (!argv.benchmark) await this.limitRate('global', 10, 88);
const [absoluteDomain, inferDomain] = await Promise.all([
domain.get(domainId),
domain.getByHost(this.request.host),
@ -551,11 +550,9 @@ export class Handler extends HandlerCommon {
this.request.json || this.response.redirect
|| this.request.query.noTemplate || !this.response.template) {
try {
this.response.body = JSON.stringify(this.response.body);
this.response.body = JSON.stringify(this.response.body, serializer, 2);
} catch (e) {
const opt: SerializeJSOptions = { ignoreFunction: true };
if (this.request.query.noTemplate) opt.space = 2;
this.response.body = serialize(this.response.body, opt);
this.response.body = new SystemError('Serialize failure', e.message);
}
this.response.type = 'application/json';
} else if (this.response.body || this.response.template) {

Loading…
Cancel
Save