mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-18 09:36:08 +08:00
core: data feedback system
This commit is contained in:
1 parent
83cc85492d
commit
1817341eee
7 files changed
+54
-5
No files matched your search
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hydrooj",
|
||||
"version": "2.13.59",
|
||||
"version": "2.13.60",
|
||||
"bin": "bin/hydrooj.js",
|
||||
"main": "dist/loader.js",
|
||||
"typings": "dist/loader.d.ts",
|
||||
|
||||
@@ -130,6 +130,7 @@ class SwitchLanguageHandler extends Handler {
|
||||
@param('lang', Types.String)
|
||||
async get(domainId: string, lang: string) {
|
||||
if (this.user.hasPriv(PRIV.PRIV_USER_PROFILE)) {
|
||||
this.session.viewLang = lang;
|
||||
await user.setById(this.user._id, { viewLang: lang });
|
||||
} else this.session.viewLang = lang;
|
||||
this.back();
|
||||
|
||||
@@ -19,6 +19,7 @@ export interface SystemKeys {
|
||||
'smtp.port': number,
|
||||
'smtp.secure': boolean,
|
||||
'user': number,
|
||||
'installid': string,
|
||||
'server.name': string,
|
||||
'server.url': string,
|
||||
'server.xff': string,
|
||||
|
||||
@@ -54,7 +54,7 @@ wtfnode.setLogger('info', logger.info.bind(logger));
|
||||
logger.debug('%o', argv);
|
||||
|
||||
async function terminate() {
|
||||
wtfnode.dump();
|
||||
if (argv.debug) wtfnode.dump();
|
||||
try {
|
||||
await bus.parallel('app/exit');
|
||||
} catch (e) {
|
||||
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
} from '../interface';
|
||||
import * as db from '../service/db';
|
||||
|
||||
const coll: Collection<Rdoc> = db.collection('record');
|
||||
export const coll: Collection<Rdoc> = db.collection('record');
|
||||
|
||||
export interface RdocBase {
|
||||
_id?: ObjectID,
|
||||
@@ -186,6 +186,7 @@ export function getByUid(domainId: string, uid: number, limit: number): Promise<
|
||||
}
|
||||
|
||||
global.Hydro.model.record = {
|
||||
coll,
|
||||
add,
|
||||
get,
|
||||
getMulti,
|
||||
|
||||
@@ -227,7 +227,7 @@ export async function create(
|
||||
return uid;
|
||||
}
|
||||
|
||||
export function getMulti(params: any) {
|
||||
export function getMulti(params: any = {}) {
|
||||
return coll.find(params);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,56 @@
|
||||
import cluster from 'cluster';
|
||||
import crypto from 'crypto';
|
||||
import axios from 'axios';
|
||||
import { safeDump } from 'js-yaml';
|
||||
import * as db from './db';
|
||||
import * as bus from './bus';
|
||||
import * as sysinfo from '../lib/sysinfo';
|
||||
|
||||
const coll = db.collection('status');
|
||||
|
||||
function crypt(str: string) {
|
||||
const cipher = crypto.createCipheriv('des-ecb', 'hydro-oj', '');
|
||||
let encrypted = cipher.update(str, 'utf8', 'hex');
|
||||
encrypted += cipher.final('hex');
|
||||
return encrypted;
|
||||
}
|
||||
|
||||
export async function feedback() {
|
||||
const {
|
||||
system, domain, document, user, record,
|
||||
} = global.Hydro.model;
|
||||
const version = require('hydrooj/package.json').version;
|
||||
const [mid, , inf] = await sysinfo.update();
|
||||
const [installid, name, url] = system.getMany([
|
||||
'installid', 'server.name', 'server.url',
|
||||
]);
|
||||
const [domainCount, userCount, problemCount, discussionCount, recordCount] = await Promise.all([
|
||||
domain.getMulti().count(),
|
||||
user.getMulti().count(),
|
||||
document.coll.find({ docType: document.TYPE_PROBLEM }).count(),
|
||||
document.coll.find({ docType: document.TYPE_DISCUSSION }).count(),
|
||||
record.coll.find().count(),
|
||||
]);
|
||||
const payload = crypt(safeDump({
|
||||
_id: installid + mid.toString(),
|
||||
version,
|
||||
name,
|
||||
url,
|
||||
domainCount,
|
||||
userCount,
|
||||
problemCount,
|
||||
discussionCount,
|
||||
recordCount,
|
||||
addons: global.addons,
|
||||
memory: inf.memory,
|
||||
osinfo: inf.osinfo,
|
||||
flags: inf.flags,
|
||||
}));
|
||||
axios.post('https://feedback.undefined.moe/', { payload });
|
||||
}
|
||||
|
||||
export async function update() {
|
||||
await feedback();
|
||||
const [mid, $set] = await sysinfo.update();
|
||||
$set.updateAt = new Date();
|
||||
$set.reqCount = global.Hydro.stat.reqCount;
|
||||
@@ -36,8 +81,9 @@ if (cluster.isMaster) {
|
||||
{ $set: { ...info, updateAt: new Date(), type: 'server' } },
|
||||
{ upsert: true },
|
||||
);
|
||||
await feedback();
|
||||
setInterval(update, 60 * 1000);
|
||||
});
|
||||
}
|
||||
|
||||
global.Hydro.service.monitor = { update, updateJudger };
|
||||
global.Hydro.service.monitor = { feedback, update, updateJudger };
|
||||
Reference in new issue
Block a user