mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +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(', '));
|
return console.error(parameters.join(', '));
|
||||||
}
|
}
|
||||||
for (let i = 0; i < args.length; i++) {
|
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]);
|
args[i] = new ObjectID(args[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -249,14 +249,12 @@ class UserModel {
|
|||||||
|
|
||||||
@ArgMethod
|
@ArgMethod
|
||||||
static async setSuperAdmin(uid: number) {
|
static async setSuperAdmin(uid: number) {
|
||||||
await UserModel.setPriv(uid, PRIV.PRIV_ALL);
|
return await UserModel.setPriv(uid, PRIV.PRIV_ALL);
|
||||||
return uid;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ArgMethod
|
@ArgMethod
|
||||||
static async setJudge(uid: number) {
|
static async setJudge(uid: number) {
|
||||||
await UserModel.setPriv(uid, PRIV.PRIV_USER_PROFILE | PRIV.PRIV_JUDGE);
|
return await UserModel.setPriv(uid, PRIV.PRIV_USER_PROFILE | PRIV.PRIV_JUDGE);
|
||||||
return uid;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ArgMethod
|
@ArgMethod
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ import proxy from 'koa-proxies';
|
|||||||
import cache from 'koa-static-cache';
|
import cache from 'koa-static-cache';
|
||||||
import sockjs from 'sockjs';
|
import sockjs from 'sockjs';
|
||||||
import type { SetOption } from 'cookies';
|
import type { SetOption } from 'cookies';
|
||||||
import serialize, { SerializeJSOptions } from 'serialize-javascript';
|
|
||||||
import { argv } from 'yargs';
|
import { argv } from 'yargs';
|
||||||
import { createHash } from 'crypto';
|
import { createHash } from 'crypto';
|
||||||
import * as bus from './bus';
|
import * as bus from './bus';
|
||||||
@@ -27,7 +26,7 @@ import {
|
|||||||
UserNotFoundError, BlacklistedError, PermissionError,
|
UserNotFoundError, BlacklistedError, PermissionError,
|
||||||
UserFacingError, ValidationError, PrivilegeError,
|
UserFacingError, ValidationError, PrivilegeError,
|
||||||
CsrfTokenError, InvalidOperationError, MethodNotAllowedError,
|
CsrfTokenError, InvalidOperationError, MethodNotAllowedError,
|
||||||
NotFoundError, HydroError,
|
NotFoundError, HydroError, SystemError,
|
||||||
} from '../error';
|
} from '../error';
|
||||||
import * as misc from '../lib/misc';
|
import * as misc from '../lib/misc';
|
||||||
import { isContent, isName, isTitle } from '../lib/validator';
|
import { isContent, isName, isTitle } from '../lib/validator';
|
||||||
@@ -483,7 +482,7 @@ export class Handler extends HandlerCommon {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async init({ domainId }) {
|
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([
|
const [absoluteDomain, inferDomain] = await Promise.all([
|
||||||
domain.get(domainId),
|
domain.get(domainId),
|
||||||
domain.getByHost(this.request.host),
|
domain.getByHost(this.request.host),
|
||||||
@@ -551,11 +550,9 @@ export class Handler extends HandlerCommon {
|
|||||||
this.request.json || this.response.redirect
|
this.request.json || this.response.redirect
|
||||||
|| this.request.query.noTemplate || !this.response.template) {
|
|| this.request.query.noTemplate || !this.response.template) {
|
||||||
try {
|
try {
|
||||||
this.response.body = JSON.stringify(this.response.body);
|
this.response.body = JSON.stringify(this.response.body, serializer, 2);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const opt: SerializeJSOptions = { ignoreFunction: true };
|
this.response.body = new SystemError('Serialize failure', e.message);
|
||||||
if (this.request.query.noTemplate) opt.space = 2;
|
|
||||||
this.response.body = serialize(this.response.body, opt);
|
|
||||||
}
|
}
|
||||||
this.response.type = 'application/json';
|
this.response.type = 'application/json';
|
||||||
} else if (this.response.body || this.response.template) {
|
} else if (this.response.body || this.response.template) {
|
||||||
|
|||||||
Reference in new issue
Block a user