移除一些anyscript特性

This commit is contained in:
undefined committed 2020-08-09 11:41:45 +08:00
1 parent c3ff5856e4
commit cc62fd3cd7
7 files changed
+97 -19

No files matched your search

+9 -1
View File
@@ -6,10 +6,18 @@ import { Reader } from 'maxmind';
const buffer = fs.readFileSync(path.resolve(__dirname, 'GeoLite2-City.mmdb')); const buffer = fs.readFileSync(path.resolve(__dirname, 'GeoLite2-City.mmdb'));
const reader = new Reader(buffer); const reader = new Reader(buffer);
export interface Result {
location?: string,
continent?: string,
country?: string,
city?: string,
display: string
}
function lookup(ip: string, locale: string) { function lookup(ip: string, locale: string) {
const res: any = reader.get(ip); const res: any = reader.get(ip);
if (!res) return {}; if (!res) return {};
const ret: any = {}; const ret: Result = { display: '' };
if (res.location) ret.location = res.location; if (res.location) ret.location = res.location;
if (res.continent) ret.continent = res.continent.names[locale] || res.continent.names.en; if (res.continent) ret.continent = res.continent.names[locale] || res.continent.names.en;
if (res.country || res.registered_country) { if (res.country || res.registered_country) {
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "hydrooj", "name": "hydrooj",
"version": "2.12.7", "version": "2.12.8",
"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",
+2 -1
View File
@@ -1,4 +1,5 @@
import moment from 'moment-timezone'; import moment from 'moment-timezone';
import { Dictionary } from 'lodash';
import { import {
RoleAlreadyExistError, ValidationError, DomainJoinForbiddenError, RoleAlreadyExistError, ValidationError, DomainJoinForbiddenError,
DomainJoinAlreadyMemberError, InvalidJoinInvitationCodeError, DomainJoinAlreadyMemberError, InvalidJoinInvitationCodeError,
@@ -170,7 +171,7 @@ class DomainRoleHandler extends ManageHandler {
@param('role', Types.String) @param('role', Types.String)
async postAdd(domainId: string, role: string) { async postAdd(domainId: string, role: string) {
const roles = await domain.getRoles(this.domain); const roles = await domain.getRoles(this.domain);
const rdict: any = {}; const rdict: Dictionary<any> = {};
for (const r of roles) rdict[r._id] = r.perm; for (const r of roles) rdict[r._id] = r.perm;
if (rdict[role]) throw new RoleAlreadyExistError(role); if (rdict[role]) throw new RoleAlreadyExistError(role);
await domain.addRole(domainId, role, rdict.default.perm); await domain.addRole(domainId, role, rdict.default.perm);
+11 -12
View File
@@ -1,5 +1,5 @@
import { ObjectID } from 'mongodb'; import { ObjectID, PushOperator, MatchKeysAndValues } from 'mongodb';
import { JudgeResultBody, Rdoc } from '../interface'; import { JudgeResultBody, Rdoc, TestCase } from '../interface';
import * as record from '../model/record'; import * as record from '../model/record';
import * as problem from '../model/problem'; import * as problem from '../model/problem';
import * as builtin from '../model/builtin'; import * as builtin from '../model/builtin';
@@ -36,14 +36,15 @@ async function _postJudge(rdoc: Rdoc) {
export async function next(body: JudgeResultBody) { export async function next(body: JudgeResultBody) {
if (body.rid) body.rid = new ObjectID(body.rid); if (body.rid) body.rid = new ObjectID(body.rid);
let rdoc = await record.get(body.domainId, body.rid); let rdoc = await record.get(body.domainId, body.rid);
const $set: any = {}; const $set: Partial<Rdoc> = {};
const $push: any = {}; const $push: any = {};
if (body.case) { if (body.case) {
const c: any = {}; const c: TestCase = {
c.memory = body.case.memory; memory: body.case.memory,
c.time = body.case.time; time: body.case.time,
c.message = body.case.message; message: body.case.message,
c.status = body.case.status; status: body.case.status,
};
rdoc.testCases.push(c); rdoc.testCases.push(c);
$push.testCases = c; $push.testCases = c;
} }
@@ -67,9 +68,9 @@ export async function next(body: JudgeResultBody) {
export async function end(body: JudgeResultBody) { export async function end(body: JudgeResultBody) {
if (body.rid) body.rid = new ObjectID(body.rid); if (body.rid) body.rid = new ObjectID(body.rid);
let rdoc = await record.get(body.domainId, body.rid); let rdoc = await record.get(body.domainId, body.rid);
const $set: any = {}; const $set: Partial<Rdoc> = {};
const $push: any = {}; const $push: any = {};
const $unset = { progress: '' }; const $unset: { progress: '' } = { progress: '' };
if (body.message) { if (body.message) {
rdoc.judgeTexts.push(body.message); rdoc.judgeTexts.push(body.message);
$push.judgeTexts = body.message; $push.judgeTexts = body.message;
@@ -80,8 +81,6 @@ export async function end(body: JudgeResultBody) {
} }
if (body.status) $set.status = body.status; if (body.status) $set.status = body.status;
if (body.score) $set.score = body.score; if (body.score) $set.score = body.score;
if (body.stdout) $set.stdout = body.stdout;
if (body.stderr) $set.stderr = body.stderr;
if (body.time) $set.time = body.time; if (body.time) $set.time = body.time;
if (body.memory) $set.memory = body.memory; if (body.memory) $set.memory = body.memory;
$set.judgeAt = new Date(); $set.judgeAt = new Date();
+2 -1
View File
@@ -191,10 +191,11 @@ export interface Rdoc {
compilerTexts: string[], compilerTexts: string[],
testCases: TestCase[], testCases: TestCase[],
rejudged: boolean, rejudged: boolean,
judger: string, judger: number,
judgeAt: Date, judgeAt: Date,
status: number, status: number,
hidden: boolean, hidden: boolean,
progress?: number,
config?: PretestConfig, config?: PretestConfig,
contest?: ContestInfo, contest?: ContestInfo,
} }
+7 -3
View File
@@ -1,4 +1,6 @@
import { ObjectID, Collection } from 'mongodb'; import {
ObjectID, Collection, UpdateQuery, PushOperator, MatchKeysAndValues, OnlyFieldsOfType,
} from 'mongodb';
import { Dictionary } from 'lodash'; import { Dictionary } from 'lodash';
import { STATUS } from './builtin'; import { STATUS } from './builtin';
import * as task from './task'; import * as task from './task';
@@ -109,9 +111,11 @@ export function getMulti(domainId: string, query: any) {
export async function update( export async function update(
domainId: string, _id: ObjectID, domainId: string, _id: ObjectID,
$set: any = {}, $push: any = {}, $unset: any = {}, $set?: MatchKeysAndValues<Rdoc>,
$push?: PushOperator<Rdoc>,
$unset?: OnlyFieldsOfType<Rdoc, any, true | '' | 1>,
): Promise<Rdoc | null> { ): Promise<Rdoc | null> {
const $update: any = {}; const $update: UpdateQuery<Rdoc> = {};
if ($set && Object.keys($set).length) $update.$set = $set; if ($set && Object.keys($set).length) $update.$set = $set;
if ($push && Object.keys($push).length) $update.$push = $push; if ($push && Object.keys($push).length) $update.$push = $push;
if ($unset && Object.keys($unset).length) $update.$unset = $unset; if ($unset && Object.keys($unset).length) $update.$unset = $unset;
+65
View File
@@ -0,0 +1,65 @@
import 'hydrooj';
import * as superagent from 'superagent';
import superagentProxy from 'superagent-proxy';
superagentProxy(superagent);
async function get() {
const { system, token } = global.Hydro.model;
const [[appid, url], [state]] = await Promise.all([
system.getMany([
'login-with-osu.id',
'server.url',
]),
token.add(token.TYPE_OAUTH, 600, { redirect: this.request.referer }),
]);
this.response.redirect = `https://osu.ppy.sh/oauth/authorize?client_id=${appid}&state=${state}&redirect_uri=${url}oauth/osu/callback&response_type=code`;
}
async function callback({ state, code }) {
const { system, token } = global.Hydro.model;
const { UserFacingError } = global.Hydro.error;
const [[appid, secret, proxy, url], s] = await Promise.all([
system.getMany([
'login-with-osu.id',
'login-with-osu.secret',
'login-with-osu.proxy',
'server.url',
]),
token.get(state, token.TYPE_OAUTH),
]);
const res = await superagent.post('https://osu.ppy.sh/oauth/token')
.proxy(proxy)
.send({
client_id: appid,
client_secret: secret,
code,
grant_type: 'authorization_code',
redirect_uri: `${url}oauth/github/callback`,
})
.set('accept', 'application/json');
if (res.body.error) {
throw new UserFacingError(
res.body.error, res.body.error_description, res.body.error_uri,
);
}
const t = res.body.access_token;
const userInfo = await superagent.get('https://osu.ppy.sh/api/v2/me')
.proxy(proxy)
.set('User-Agent', 'Hydro-OAuth')
.set('Authorization', `Bearer ${t}`);
const ret = {
email: `${userInfo.body.id}@osu.local`,
bio: '',
uname: [userInfo.body.username],
};
this.response.redirect = s.redirect;
await token.del(s._id, token.TYPE_OAUTH);
return ret;
}
global.Hydro.lib.oauth_osu = {
text: 'Login with Osu',
callback,
get,
};