diff --git a/packages/html2md/lib.ts b/packages/html2md/lib.ts
index 0cda67505..a4cf55161 100644
--- a/packages/html2md/lib.ts
+++ b/packages/html2md/lib.ts
@@ -1,6 +1,12 @@
import 'hydrooj';
import TurndownService from 'turndown';
+declare module 'hydrooj' {
+ interface Lib {
+ convertHTML: (str: string) => string,
+ }
+}
+
const turndownService = new TurndownService({
headingStyle: 'atx',
codeBlockStyle: 'fenced',
diff --git a/packages/hydrooj/src/entry/master.ts b/packages/hydrooj/src/entry/master.ts
index ae5c61cae..0c4252632 100644
--- a/packages/hydrooj/src/entry/master.ts
+++ b/packages/hydrooj/src/entry/master.ts
@@ -7,8 +7,10 @@ import pslist from 'ps-list';
import { argv } from 'yargs';
import { builtinModel } from './common';
import { Entry } from '../loader';
+import { Logger } from '../logger';
import * as bus from '../service/bus';
+const logger = new Logger('entry/master');
const tmpdir = path.resolve(os.tmpdir(), 'hydro');
const lockfile = path.resolve(tmpdir, 'lock.json');
@@ -19,7 +21,7 @@ export async function load(call: Entry) {
const file = require(lockfile);
const plist = await pslist();
if (file.pid && plist.map((i) => i.pid).includes(file.pid)) {
- console.error(`Lockfile exists, pid=${file.pid}`);
+ logger.error(`Lockfile exists, pid=${file.pid}`);
process.exit(1);
}
} catch {
@@ -37,9 +39,9 @@ export async function load(call: Entry) {
require('../error');
const config = require('../options')();
if (!config) {
- console.log('Starting setup');
+ logger.info('Starting setup');
await call({ entry: 'setup', newProcess: true }).catch((err) => {
- console.error('Cannot start setup process.', err);
+ logger.error('Cannot start setup process.', err);
process.exit(1);
});
}
diff --git a/packages/hydrooj/src/handler/homework.ts b/packages/hydrooj/src/handler/homework.ts
index 2d282f2b7..13646d687 100644
--- a/packages/hydrooj/src/handler/homework.ts
+++ b/packages/hydrooj/src/handler/homework.ts
@@ -199,7 +199,6 @@ class HomeworkDetailProblemSubmitHandler extends HomeworkDetailProblemHandler {
class HomeworkCreateHandler extends HomeworkHandler {
async get() {
const beginAt = moment().add(1, 'day');
- console.log(beginAt, beginAt.tz(this.user.timeZone));
const penaltySince = beginAt.clone().add(7, 'days');
const path = [
['Hydro', 'homepage'],
@@ -343,7 +342,6 @@ class HomeworkEditHandler extends HomeworkHandler {
class HomeworkScoreboardHandler extends HomeworkHandler {
@param('tid', Types.ObjectID)
async get(domainId: string, tid: ObjectID) {
- console.log(123);
const [tdoc, rows, udict] = await this.getScoreboard(
domainId, tid, false, document.TYPE_HOMEWORK,
);
diff --git a/packages/hydrooj/src/interface.ts b/packages/hydrooj/src/interface.ts
index 8942513d1..f5542bc28 100644
--- a/packages/hydrooj/src/interface.ts
+++ b/packages/hydrooj/src/interface.ts
@@ -410,6 +410,13 @@ export interface JudgeResultBody {
stderr?: string,
}
+export interface Task {
+ _id: ObjectID,
+ type: string,
+ executeAfter?: Date
+ [key: string]: any
+}
+
export type PathComponent = [string, string, Dictionary?, boolean?];
export interface Collections {
@@ -428,7 +435,7 @@ export interface Collections {
'status': any,
'oauth': any,
'system': System,
- 'task': any,
+ 'task': Task,
'opcount': any,
'fs.chunks': any,
'fs.files': any,
@@ -454,7 +461,7 @@ export interface Model {
token: typeof import('./model/token'),
training: typeof import('./model/training'),
user: typeof import('./model/user'),
- [key: string]: any,
+ oauth: typeof import('./model/oauth'),
}
export interface Service {
@@ -463,7 +470,11 @@ export interface Service {
gridfs: GridFSBucket,
monitor: typeof import('./service/monitor'),
server: typeof import('./service/server'),
- [key: string]: any,
+}
+
+interface GeoIP {
+ provider: string,
+ lookup: (ip: string, locale?: string) => any,
}
export interface Lib {
@@ -484,7 +495,8 @@ export interface Lib {
'testdata.convert.ini': typeof import('./lib/testdata.convert.ini'),
useragent: typeof import('./lib/useragent'),
validator: typeof import('./lib/validator'),
- [key: string]: any
+ template?: any,
+ geoip?: GeoIP,
}
export interface UI {
diff --git a/packages/login-with-github/lib.ts b/packages/login-with-github/lib.ts
index 26290cfaf..2c65fe066 100644
--- a/packages/login-with-github/lib.ts
+++ b/packages/login-with-github/lib.ts
@@ -10,6 +10,9 @@ declare module 'hydrooj' {
'login-with-github.secret': string,
'login-with-github.proxy': string,
}
+ interface Lib {
+ oauth_github: typeof import('./lib'),
+ }
}
async function get() {
diff --git a/packages/login-with-google/lib.ts b/packages/login-with-google/lib.ts
index 797724d87..7bf01c349 100644
--- a/packages/login-with-google/lib.ts
+++ b/packages/login-with-google/lib.ts
@@ -10,6 +10,9 @@ declare module 'hydrooj' {
'login-with-google.secret': string,
'login-with-google.proxy': string,
}
+ interface Lib {
+ oauth_google: typeof import('./lib'),
+ }
}
async function get() {
diff --git a/packages/login-with-osu/lib.ts b/packages/login-with-osu/lib.ts
index 3da90d76d..bc07210d3 100644
--- a/packages/login-with-osu/lib.ts
+++ b/packages/login-with-osu/lib.ts
@@ -10,6 +10,9 @@ declare module 'hydrooj' {
'login-with-osu.secret': string,
'login-with-osu.proxy': string,
}
+ interface Lib {
+ oauth_osu: typeof import('./lib'),
+ }
}
const BASE_URL = 'https://osu.ppy.sh/';
diff --git a/packages/login-with-qq/lib.ts b/packages/login-with-qq/lib.ts
index 40f64e3be..1f5e9fb79 100644
--- a/packages/login-with-qq/lib.ts
+++ b/packages/login-with-qq/lib.ts
@@ -1,6 +1,12 @@
import 'hydrooj';
import 'hydrooj/dist/utils';
+declare module 'hydrooj' {
+ interface Lib {
+ oauth_qq: typeof import('./lib'),
+ }
+}
+
async function get() {
const { system, token } = global.Hydro.model;
const secret = String.random(8);