mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 17:36:08 +08:00
core: cli: fix ObjectID convert & serializer
This commit is contained in:
1 parent
4ccb9f3283
commit
981b21160f
3 files changed
+7
-12
No files matched your search
@@ -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) {
|
||||
|
||||
Reference in new issue
Block a user