mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: fix script load
This commit is contained in:
1 parent
446859822a
commit
cb424c9cac
4 files changed
+18
-13
No files matched your search
@@ -1,6 +1,8 @@
|
|||||||
/* eslint-disable import/no-dynamic-require */
|
/* eslint-disable import/no-dynamic-require */
|
||||||
/* eslint-disable no-await-in-loop */
|
/* eslint-disable no-await-in-loop */
|
||||||
|
import path from 'path';
|
||||||
import cac from 'cac';
|
import cac from 'cac';
|
||||||
|
import fs from 'fs-extra';
|
||||||
import { ObjectID } from 'mongodb';
|
import { ObjectID } from 'mongodb';
|
||||||
import db from '../service/db';
|
import db from '../service/db';
|
||||||
import {
|
import {
|
||||||
@@ -94,7 +96,10 @@ export async function load(ctx) {
|
|||||||
await service(pending, fail, ctx);
|
await service(pending, fail, ctx);
|
||||||
require('../model/index');
|
require('../model/index');
|
||||||
await model(pending, fail, ctx);
|
await model(pending, fail, ctx);
|
||||||
require('../script/index');
|
const scriptDir = path.resolve(__dirname, '..', 'script');
|
||||||
|
for (const h of await fs.readdir(scriptDir)) {
|
||||||
|
ctx.loader.reloadPlugin(ctx, path.resolve(scriptDir, h), {}, `hydrooj/script/${h.split('.')[0]}`);
|
||||||
|
}
|
||||||
await script(pending, fail, ctx);
|
await script(pending, fail, ctx);
|
||||||
await cli();
|
await cli();
|
||||||
}
|
}
|
||||||
@@ -58,7 +58,10 @@ export async function apply(ctx: Context) {
|
|||||||
await handler(pending, fail, ctx);
|
await handler(pending, fail, ctx);
|
||||||
await addon(pending, fail, ctx);
|
await addon(pending, fail, ctx);
|
||||||
for (const i in global.Hydro.handler) await global.Hydro.handler[i]();
|
for (const i in global.Hydro.handler) await global.Hydro.handler[i]();
|
||||||
require('../script/index');
|
const scriptDir = path.resolve(__dirname, '..', 'script');
|
||||||
|
for (const h of await fs.readdir(scriptDir)) {
|
||||||
|
ctx.loader.reloadPlugin(ctx, path.resolve(scriptDir, h), {}, `hydrooj/script/${h.split('.')[0]}`);
|
||||||
|
}
|
||||||
await script(pending, fail, ctx);
|
await script(pending, fail, ctx);
|
||||||
await ctx.parallel('app/started');
|
await ctx.parallel('app/started');
|
||||||
if (process.env.NODE_APP_INSTANCE === '0') {
|
if (process.env.NODE_APP_INSTANCE === '0') {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import Schema from 'schemastery';
|
import Schema from 'schemastery';
|
||||||
|
import { Context } from '../context';
|
||||||
import { PRIV } from '../model/builtin';
|
import { PRIV } from '../model/builtin';
|
||||||
import user from '../model/user';
|
import user from '../model/user';
|
||||||
import db from '../service/db';
|
import db from '../service/db';
|
||||||
@@ -8,15 +9,17 @@ const collDomainUser = db.collection('domain.user');
|
|||||||
const collRecord = db.collection('record');
|
const collRecord = db.collection('record');
|
||||||
const collMessage = db.collection('message');
|
const collMessage = db.collection('message');
|
||||||
|
|
||||||
export const apply = (ctx) => ctx.addScript('deleteUser', 'Delete a user')
|
export const apply = (ctx: Context) => ctx.addScript(
|
||||||
.args(Schema.object({
|
'deleteUser', 'Delete a user',
|
||||||
|
Schema.object({
|
||||||
uid: Schema.number(),
|
uid: Schema.number(),
|
||||||
}))
|
}),
|
||||||
.action(async ({ uid }) => {
|
async ({ uid }) => {
|
||||||
await collDocument.deleteMany({ owner: uid });
|
await collDocument.deleteMany({ owner: uid });
|
||||||
await collRecord.deleteMany({ uid });
|
await collRecord.deleteMany({ uid });
|
||||||
await collDomainUser.deleteMany({ uid });
|
await collDomainUser.deleteMany({ uid });
|
||||||
await collMessage.deleteMany({ $or: [{ from: uid }, { to: uid }] });
|
await collMessage.deleteMany({ $or: [{ from: uid }, { to: uid }] });
|
||||||
await user.setPriv(uid, PRIV.PRIV_NONE);
|
await user.setPriv(uid, PRIV.PRIV_NONE);
|
||||||
return true;
|
return true;
|
||||||
});
|
},
|
||||||
|
);
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
import './rating';
|
|
||||||
import './problemStat';
|
|
||||||
import './blacklist';
|
|
||||||
import './deleteUser';
|
|
||||||
import './storageUsage';
|
|
||||||
import './checkUpdate';
|
|
||||||
Reference in new issue
Block a user