mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: remove lib.logger
This commit is contained in:
1 parent
441515297a
commit
a58c36961f
6 files changed
+5
-47
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hydrooj",
|
"name": "hydrooj",
|
||||||
"version": "2.13.21",
|
"version": "2.13.22",
|
||||||
"bin": "bin/hydrooj.js",
|
"bin": "bin/hydrooj.js",
|
||||||
"main": "dist/loader.js",
|
"main": "dist/loader.js",
|
||||||
"typings": "dist/loader.d.ts",
|
"typings": "dist/loader.d.ts",
|
||||||
|
|||||||
@@ -10,9 +10,8 @@ const logger = new Logger('common', true);
|
|||||||
|
|
||||||
export const builtinLib = [
|
export const builtinLib = [
|
||||||
'jwt', 'download', 'i18n', 'mail', 'useragent',
|
'jwt', 'download', 'i18n', 'mail', 'useragent',
|
||||||
'md5', 'misc', 'paginate', 'hash.hydro', 'rank',
|
'crypto', 'misc', 'paginate', 'hash.hydro', 'rank',
|
||||||
'validator', 'ui', 'sysinfo', 'testdata.convert.ini', 'testdataConfig',
|
'validator', 'ui', 'sysinfo', 'testdata.convert.ini', 'testdataConfig',
|
||||||
'logger',
|
|
||||||
];
|
];
|
||||||
|
|
||||||
export const builtinModel = [
|
export const builtinModel = [
|
||||||
|
|||||||
@@ -418,7 +418,6 @@ export class ProblemEditHandler extends ProblemManageHandler {
|
|||||||
@param('content', Types.String, isContent)
|
@param('content', Types.String, isContent)
|
||||||
async post(domainId: string, title: string, content: string) {
|
async post(domainId: string, title: string, content: string) {
|
||||||
const $update: Partial<Pdoc> = { title, content };
|
const $update: Partial<Pdoc> = { title, content };
|
||||||
console.log(this.request.body);
|
|
||||||
if (this.request.body.pid) $update.pid = checkPid(this.request.body.pid);
|
if (this.request.body.pid) $update.pid = checkPid(this.request.body.pid);
|
||||||
const pdoc = await problem.get(domainId, this.request.params.pid);
|
const pdoc = await problem.get(domainId, this.request.params.pid);
|
||||||
await problem.edit(domainId, pdoc.docId, $update);
|
await problem.edit(domainId, pdoc.docId, $update);
|
||||||
|
|||||||
@@ -498,7 +498,6 @@ export interface Lib {
|
|||||||
'hash.hydro': typeof import('./lib/hash.hydro'),
|
'hash.hydro': typeof import('./lib/hash.hydro'),
|
||||||
i18n: typeof import('./lib/i18n'),
|
i18n: typeof import('./lib/i18n'),
|
||||||
jwt: typeof import('./lib/jwt'),
|
jwt: typeof import('./lib/jwt'),
|
||||||
logger: typeof import('./lib/logger'),
|
|
||||||
mail: typeof import('./lib/mail'),
|
mail: typeof import('./lib/mail'),
|
||||||
md5: typeof import('./lib/crypto').md5,
|
md5: typeof import('./lib/crypto').md5,
|
||||||
sha1: typeof import('./lib/crypto').sha1,
|
sha1: typeof import('./lib/crypto').sha1,
|
||||||
|
|||||||
@@ -1,41 +0,0 @@
|
|||||||
import serialize from 'serialize-javascript';
|
|
||||||
|
|
||||||
function wrap(func: Function, type: string) {
|
|
||||||
return (...args: any) => {
|
|
||||||
const time = new Date();
|
|
||||||
func(...args);
|
|
||||||
if (global.Hydro.model.message) {
|
|
||||||
try {
|
|
||||||
global.Hydro.model.message.send(1, 1, serialize({ time, type, args }), 0);
|
|
||||||
} catch (e) {
|
|
||||||
func(e.message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
class Logger {
|
|
||||||
log: (...args: any[]) => void;
|
|
||||||
|
|
||||||
error: (...args: any[]) => void;
|
|
||||||
|
|
||||||
info: (...args: any[]) => void;
|
|
||||||
|
|
||||||
warn: (...args: any[]) => void;
|
|
||||||
|
|
||||||
debug: (...args: any[]) => void;
|
|
||||||
|
|
||||||
constructor() {
|
|
||||||
this.log = wrap(console.log, 'log');
|
|
||||||
this.error = wrap(console.error, 'error');
|
|
||||||
this.info = wrap(console.info, 'info');
|
|
||||||
this.warn = wrap(console.warn, 'warn');
|
|
||||||
this.debug = wrap(console.debug, 'debug');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const exp = new Logger();
|
|
||||||
|
|
||||||
global.Hydro.lib.logger = exp;
|
|
||||||
|
|
||||||
export = exp;
|
|
||||||
@@ -7,11 +7,13 @@ import { BUILTIN_USERS, PRIV } from './builtin';
|
|||||||
import { UserNotFoundError, UserAlreadyExistError, LoginError } from '../error';
|
import { UserNotFoundError, UserAlreadyExistError, LoginError } from '../error';
|
||||||
import { User as _User, Udoc, Udict } from '../interface';
|
import { User as _User, Udoc, Udict } from '../interface';
|
||||||
import { Value } from '../typeutils';
|
import { Value } from '../typeutils';
|
||||||
|
import { Logger } from '../logger';
|
||||||
import pwhash from '../lib/hash.hydro';
|
import pwhash from '../lib/hash.hydro';
|
||||||
import * as db from '../service/db';
|
import * as db from '../service/db';
|
||||||
import * as bus from '../service/bus';
|
import * as bus from '../service/bus';
|
||||||
|
|
||||||
const coll: Collection<Udoc> = db.collection('user');
|
const coll: Collection<Udoc> = db.collection('user');
|
||||||
|
const logger = new Logger('model/user');
|
||||||
|
|
||||||
export async function setPassword(uid: number, password: string): Promise<Udoc> {
|
export async function setPassword(uid: number, password: string): Promise<Udoc> {
|
||||||
const salt = String.random();
|
const salt = String.random();
|
||||||
@@ -216,7 +218,7 @@ export async function create(
|
|||||||
gravatar: mail,
|
gravatar: mail,
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
logger.warn(e);
|
||||||
throw new UserAlreadyExistError([uid, uname, mail]);
|
throw new UserAlreadyExistError([uid, uname, mail]);
|
||||||
}
|
}
|
||||||
return uid;
|
return uid;
|
||||||
|
|||||||
Reference in new issue
Block a user