mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
修复oauth.google setting字段异常问题,将__mock__添加至ignore
This commit is contained in:
1 parent
147637d539
commit
6ba93841ea
17 files changed
+103
-16
No files matched your search
+2
-1
@@ -1,4 +1,5 @@
|
|||||||
dist
|
dist
|
||||||
*.d.ts
|
*.d.ts
|
||||||
*.js
|
*.js
|
||||||
test
|
test
|
||||||
|
tests
|
||||||
+2
-1
@@ -10,7 +10,8 @@
|
|||||||
"lint": "eslint packages --ext ts --fix",
|
"lint": "eslint packages --ext ts --fix",
|
||||||
"pub": "node build/publish",
|
"pub": "node build/publish",
|
||||||
"jest": "node build/jest",
|
"jest": "node build/jest",
|
||||||
"start": "node --async-stack-traces --trace-deprecation --enable-source-maps build/start"
|
"start": "node --async-stack-traces --trace-deprecation --enable-source-maps build/start",
|
||||||
|
"clean": "zsh -c \"rm -r tsconfig.build.tsbuildinfo ./packages/*/tsconfig.build.tsbuildinfo ./packages/*/dist ./coverage\""
|
||||||
},
|
},
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"license": "AGPL-3.0-only",
|
"license": "AGPL-3.0-only",
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { compilerText } from './utils';
|
|||||||
export = async function compile(
|
export = async function compile(
|
||||||
lang: string, code: string, target: string, copyIn: any, next?: Function,
|
lang: string, code: string, target: string, copyIn: any, next?: Function,
|
||||||
) {
|
) {
|
||||||
const LANGS = yaml.safeLoad(await global.Hydro.model.system.get('hydrojudge.langs') as string);
|
const LANGS = yaml.safeLoad(await global.Hydro.model.system.get('hydrojudge.langs'));
|
||||||
if (!LANGS[lang]) throw new SystemError(`不支持的语言:${lang}`);
|
if (!LANGS[lang]) throw new SystemError(`不支持的语言:${lang}`);
|
||||||
const info = LANGS[lang];
|
const info = LANGS[lang];
|
||||||
const f = {};
|
const f = {};
|
||||||
|
|||||||
@@ -8,6 +8,12 @@ import { ObjectID } from 'bson';
|
|||||||
import fs from 'fs-extra';
|
import fs from 'fs-extra';
|
||||||
import { homedir, tmpdir } from 'os';
|
import { homedir, tmpdir } from 'os';
|
||||||
|
|
||||||
|
declare module 'hydrooj' {
|
||||||
|
interface SystemKeys {
|
||||||
|
'hydrojudge.langs': string,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function postInit() {
|
async function postInit() {
|
||||||
// Only start a single daemon
|
// Only start a single daemon
|
||||||
if (!cluster.isFirstWorker) return;
|
if (!cluster.isFirstWorker) return;
|
||||||
|
|||||||
@@ -159,7 +159,7 @@ class HomeSecurityHandler extends Handler {
|
|||||||
if (udoc) throw new UserAlreadyExistError(email);
|
if (udoc) throw new UserAlreadyExistError(email);
|
||||||
const [code] = await token.add(
|
const [code] = await token.add(
|
||||||
token.TYPE_CHANGEMAIL,
|
token.TYPE_CHANGEMAIL,
|
||||||
await system.get('changemail_token_expire_seconds') as number,
|
await system.get('changemail_token_expire_seconds'),
|
||||||
{ uid: this.user._id, email },
|
{ uid: this.user._id, email },
|
||||||
);
|
);
|
||||||
const m = await this.renderHTML('user_changemail_mail.html', {
|
const m = await this.renderHTML('user_changemail_mail.html', {
|
||||||
|
|||||||
@@ -151,10 +151,12 @@ class SystemSettingHandler extends SystemHandler {
|
|||||||
if (typeof args[key] === 'object') {
|
if (typeof args[key] === 'object') {
|
||||||
for (const subkey in args[key]) {
|
for (const subkey in args[key]) {
|
||||||
if (typeof set(`${key}.${subkey}`, args[key][subkey]) !== 'undefined') {
|
if (typeof set(`${key}.${subkey}`, args[key][subkey]) !== 'undefined') {
|
||||||
|
// @ts-ignore
|
||||||
tasks.push(system.set(`${key}.${subkey}`, set(`${key}.${subkey}`, args[key][subkey])));
|
tasks.push(system.set(`${key}.${subkey}`, set(`${key}.${subkey}`, args[key][subkey])));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (typeof set(key, args[key]) !== 'undefined') {
|
} else if (typeof set(key, args[key]) !== 'undefined') {
|
||||||
|
// @ts-ignore
|
||||||
tasks.push(system.set(key, set(key, args[key])));
|
tasks.push(system.set(key, set(key, args[key])));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ class UserRegisterHandler extends Handler {
|
|||||||
this.limitRate('send_mail', 3600, 30);
|
this.limitRate('send_mail', 3600, 30);
|
||||||
const t = await token.add(
|
const t = await token.add(
|
||||||
token.TYPE_REGISTRATION,
|
token.TYPE_REGISTRATION,
|
||||||
await system.get('registration_token_expire_seconds') as number,
|
await system.get('registration_token_expire_seconds'),
|
||||||
{ mail },
|
{ mail },
|
||||||
);
|
);
|
||||||
if (await system.get('smtp.user')) {
|
if (await system.get('smtp.user')) {
|
||||||
@@ -118,7 +118,7 @@ class UserLostPassHandler extends Handler {
|
|||||||
if (!udoc) throw new UserNotFoundError(mail);
|
if (!udoc) throw new UserNotFoundError(mail);
|
||||||
const [tid] = await token.add(
|
const [tid] = await token.add(
|
||||||
token.TYPE_LOSTPASS,
|
token.TYPE_LOSTPASS,
|
||||||
await system.get('lostpass_token_expire_seconds') as number,
|
await system.get('lostpass_token_expire_seconds'),
|
||||||
{ uid: udoc._id },
|
{ uid: udoc._id },
|
||||||
);
|
);
|
||||||
const m = await this.renderHTML('user_lostpass_mail', { url: `lostpass/${tid}`, uname: udoc.uname });
|
const m = await this.renderHTML('user_lostpass_mail', { url: `lostpass/${tid}`, uname: udoc.uname });
|
||||||
|
|||||||
@@ -9,7 +9,29 @@ export type NumberKeys<O> = {
|
|||||||
|
|
||||||
export interface System {
|
export interface System {
|
||||||
_id: string,
|
_id: string,
|
||||||
value: string | number,
|
value: any,
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SystemKeys {
|
||||||
|
'smtp.user': string,
|
||||||
|
'smtp.from': string,
|
||||||
|
'smtp.pass': string,
|
||||||
|
'smtp.host': string,
|
||||||
|
'smtp.port': number,
|
||||||
|
'smtp.secure': boolean,
|
||||||
|
'user': number,
|
||||||
|
'server.url': string,
|
||||||
|
'server.xff': string,
|
||||||
|
'server.worker': number,
|
||||||
|
'server.port': number,
|
||||||
|
'session.keys': string[],
|
||||||
|
'session.secure': boolean,
|
||||||
|
'session.expire_seconds': number,
|
||||||
|
'session.unsaved_expire_seconds': number,
|
||||||
|
'lostpass_token_expire_seconds': number,
|
||||||
|
'registration_token_expire_seconds': number,
|
||||||
|
'changemail_token_expire_seconds': number,
|
||||||
|
'user.quota': number,
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Setting {
|
export interface Setting {
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ export async function sendMail(to: string, subject: string, text: string, html:
|
|||||||
system.get('smtp.user'),
|
system.get('smtp.user'),
|
||||||
system.get('smtp.pass'),
|
system.get('smtp.pass'),
|
||||||
system.get('smtp.from'),
|
system.get('smtp.from'),
|
||||||
]) as unknown as [string, number, boolean, string, string, string];
|
]);
|
||||||
const transporter = nodemailer.createTransport({
|
const transporter = nodemailer.createTransport({
|
||||||
host, port, secure, auth: { user, pass },
|
host, port, secure, auth: { user, pass },
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -143,8 +143,10 @@ SystemSetting(
|
|||||||
bus.once('app/started', async () => {
|
bus.once('app/started', async () => {
|
||||||
for (const setting of SYSTEM_SETTINGS) {
|
for (const setting of SYSTEM_SETTINGS) {
|
||||||
if (setting.value) {
|
if (setting.value) {
|
||||||
|
// @ts-ignore
|
||||||
const current = await global.Hydro.model.system.get(setting.key);
|
const current = await global.Hydro.model.system.get(setting.key);
|
||||||
if (current === null || current === '') {
|
if (current === null || current === '') {
|
||||||
|
// @ts-ignore
|
||||||
await global.Hydro.model.system.set(setting.key, setting.value);
|
await global.Hydro.model.system.set(setting.key, setting.value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
import Lru from 'lru-cache';
|
import Lru from 'lru-cache';
|
||||||
|
import { NumberKeys, SystemKeys } from '../interface';
|
||||||
import * as db from '../service/db';
|
import * as db from '../service/db';
|
||||||
|
|
||||||
const coll = db.collection('system');
|
const coll = db.collection('system');
|
||||||
const cache = new Lru<string, string | number>({
|
|
||||||
|
const cache = new Lru<string, any>({
|
||||||
maxAge: 5000,
|
maxAge: 5000,
|
||||||
});
|
});
|
||||||
|
|
||||||
export async function get(_id: string): Promise<string | number> {
|
export async function get<K extends keyof SystemKeys>(_id: K): Promise<SystemKeys[K]> {
|
||||||
const res = cache.get(_id);
|
const res = cache.get(_id);
|
||||||
if (res !== undefined) return res;
|
if (res !== undefined) return res;
|
||||||
const doc = await coll.findOne({ _id });
|
const doc = await coll.findOne({ _id });
|
||||||
@@ -17,6 +19,25 @@ export async function get(_id: string): Promise<string | number> {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getMany<
|
||||||
|
A extends keyof SystemKeys, B extends keyof SystemKeys,
|
||||||
|
>(keys: [A, B]): Promise<[SystemKeys[A], SystemKeys[B]]>
|
||||||
|
export async function getMany<
|
||||||
|
A extends keyof SystemKeys, B extends keyof SystemKeys, C extends keyof SystemKeys,
|
||||||
|
>(keys: [A, B, C]): Promise<[SystemKeys[A], SystemKeys[B], SystemKeys[C]]>
|
||||||
|
export async function getMany<
|
||||||
|
A extends keyof SystemKeys, B extends keyof SystemKeys, C extends keyof SystemKeys,
|
||||||
|
D extends keyof SystemKeys,
|
||||||
|
>(keys: [A, B, C, D]): Promise<[SystemKeys[A], SystemKeys[B], SystemKeys[C], SystemKeys[D]]>
|
||||||
|
export async function getMany<
|
||||||
|
A extends keyof SystemKeys, B extends keyof SystemKeys, C extends keyof SystemKeys,
|
||||||
|
D extends keyof SystemKeys, E extends keyof SystemKeys,
|
||||||
|
>(keys: [A, B, C, D, E]): Promise<[SystemKeys[A], SystemKeys[B], SystemKeys[C], SystemKeys[D], SystemKeys[E]]>
|
||||||
|
export async function getMany<
|
||||||
|
A extends keyof SystemKeys, B extends keyof SystemKeys, C extends keyof SystemKeys,
|
||||||
|
D extends keyof SystemKeys, E extends keyof SystemKeys, F extends keyof SystemKeys,
|
||||||
|
>(keys: [A, B, C, D, E, F]): Promise<[SystemKeys[A], SystemKeys[B], SystemKeys[C], SystemKeys[D], SystemKeys[E], SystemKeys[F]]>
|
||||||
|
export async function getMany(keys: (keyof SystemKeys)[]): Promise<any[]>
|
||||||
export async function getMany(keys: string[]): Promise<any[]> {
|
export async function getMany(keys: string[]): Promise<any[]> {
|
||||||
const r = [];
|
const r = [];
|
||||||
let success = true;
|
let success = true;
|
||||||
@@ -38,7 +59,7 @@ export async function getMany(keys: string[]): Promise<any[]> {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function set(_id: string, value: any) {
|
export async function set<K extends keyof SystemKeys>(_id: K, value: SystemKeys[K]) {
|
||||||
cache.set(_id, value);
|
cache.set(_id, value);
|
||||||
const res = await coll.findOneAndUpdate(
|
const res = await coll.findOneAndUpdate(
|
||||||
{ _id },
|
{ _id },
|
||||||
@@ -48,7 +69,7 @@ export async function set(_id: string, value: any) {
|
|||||||
return res.value.value;
|
return res.value.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function inc(_id: string) {
|
export async function inc<K extends NumberKeys<SystemKeys>>(_id: K) {
|
||||||
const res = await coll.findOneAndUpdate(
|
const res = await coll.findOneAndUpdate(
|
||||||
{ _id },
|
{ _id },
|
||||||
// FIXME NumberKeys<>
|
// FIXME NumberKeys<>
|
||||||
@@ -57,7 +78,7 @@ export async function inc(_id: string) {
|
|||||||
{ upsert: true, returnOriginal: false },
|
{ upsert: true, returnOriginal: false },
|
||||||
);
|
);
|
||||||
cache.set(_id, res.value.value);
|
cache.set(_id, res.value.value);
|
||||||
return res.value.value as number;
|
return res.value.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
global.Hydro.model.system = {
|
global.Hydro.model.system = {
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
"src"
|
"src"
|
||||||
],
|
],
|
||||||
"exclude": [
|
"exclude": [
|
||||||
"__mocks__",
|
"**/__mocks__",
|
||||||
"bin",
|
"bin",
|
||||||
"dist"
|
"dist"
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -4,6 +4,14 @@ import superagentProxy from 'superagent-proxy';
|
|||||||
|
|
||||||
superagentProxy(superagent);
|
superagentProxy(superagent);
|
||||||
|
|
||||||
|
declare module 'hydrooj' {
|
||||||
|
interface SystemKeys {
|
||||||
|
'login-with-github.id': string,
|
||||||
|
'login-with-github.secret': string,
|
||||||
|
'login-with-github.proxy': string,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function get() {
|
async function get() {
|
||||||
const { system, token } = global.Hydro.model;
|
const { system, token } = global.Hydro.model;
|
||||||
const [appid, [state]] = await Promise.all([
|
const [appid, [state]] = await Promise.all([
|
||||||
|
|||||||
@@ -4,6 +4,14 @@ import proxy from 'superagent-proxy';
|
|||||||
|
|
||||||
proxy(superagent);
|
proxy(superagent);
|
||||||
|
|
||||||
|
declare module 'hydrooj' {
|
||||||
|
interface SystemKeys {
|
||||||
|
'login-with-google.id': string,
|
||||||
|
'login-with-google.secret': string,
|
||||||
|
'login-with-google.proxy': string,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function get() {
|
async function get() {
|
||||||
const { system, token } = global.Hydro.model;
|
const { system, token } = global.Hydro.model;
|
||||||
const [appid, url, [state]] = await Promise.all([
|
const [appid, url, [state]] = await Promise.all([
|
||||||
@@ -26,7 +34,7 @@ async function callback({
|
|||||||
s,
|
s,
|
||||||
] = await Promise.all([
|
] = await Promise.all([
|
||||||
system.getMany([
|
system.getMany([
|
||||||
'login-with-google.id', 'oauth.googlesecret', 'server.url', 'proxy',
|
'login-with-google.id', 'login-with-google.secret', 'server.url', 'login-with-google.proxy',
|
||||||
]),
|
]),
|
||||||
token.get(state, token.TYPE_OAUTH),
|
token.get(state, token.TYPE_OAUTH),
|
||||||
]);
|
]);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@hydrooj/login-with-google",
|
"name": "@hydrooj/login-with-google",
|
||||||
"version": "0.0.7",
|
"version": "0.0.8",
|
||||||
"main": "package.json",
|
"main": "package.json",
|
||||||
"repository": "git@github.com:hydro-dev/Hydro.git",
|
"repository": "git@github.com:hydro-dev/Hydro.git",
|
||||||
"author": "undefined <masnn0@outlook.com>",
|
"author": "undefined <masnn0@outlook.com>",
|
||||||
|
|||||||
@@ -4,6 +4,14 @@ import superagentProxy from 'superagent-proxy';
|
|||||||
|
|
||||||
superagentProxy(superagent);
|
superagentProxy(superagent);
|
||||||
|
|
||||||
|
declare module 'hydrooj' {
|
||||||
|
interface SystemKeys {
|
||||||
|
'login-with-osu.id': string,
|
||||||
|
'login-with-osu.secret': string,
|
||||||
|
'login-with-osu.proxy': string,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const BASE_URL = 'https://osu.ppy.sh/';
|
const BASE_URL = 'https://osu.ppy.sh/';
|
||||||
|
|
||||||
async function get() {
|
async function get() {
|
||||||
|
|||||||
@@ -2,6 +2,14 @@ import { } from 'hydrooj';
|
|||||||
import * as bus from 'hydrooj/dist/service/bus';
|
import * as bus from 'hydrooj/dist/service/bus';
|
||||||
import WebSocket from 'ws';
|
import WebSocket from 'ws';
|
||||||
|
|
||||||
|
declare module 'hydrooj' {
|
||||||
|
interface SystemKeys {
|
||||||
|
'login-with-qq.id': string,
|
||||||
|
'login-with-qq.url': string,
|
||||||
|
'login-with-qq.token': string,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export async function postInit() {
|
export async function postInit() {
|
||||||
const { system, token } = global.Hydro.model;
|
const { system, token } = global.Hydro.model;
|
||||||
const [url, accessToken] = await system.getMany(['login-with-qq.url', 'login-with-qq.token']);
|
const [url, accessToken] = await system.getMany(['login-with-qq.url', 'login-with-qq.token']);
|
||||||
|
|||||||
Reference in new issue
Block a user