更加严格的lib&model定义

This commit is contained in:
undefined committed 2020-09-09 00:11:16 +08:00
1 parent 76b001305d
commit cd3a426ef8
8 files changed
+42 -9

No files matched your search

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