core: cordis alpha.7

This commit is contained in:
undefined committed 2025-03-21 07:46:36 +08:00
1 parent b6f1a9c627
commit 033e88fdce
14 files changed
+40 -34

No files matched your search

+3 -3
View File
@@ -16,8 +16,8 @@
"@aws-sdk/lib-storage": "3.726.1",
"@aws-sdk/s3-presigned-post": "3.726.1",
"@aws-sdk/s3-request-presigner": "3.726.1",
"@cordisjs/core": "4.0.0-alpha.6",
"@cordisjs/logger": "1.0.0-alpha.3",
"@cordisjs/core": "4.0.0-alpha.7",
"@cordisjs/logger": "1.0.0-alpha.4",
"@cordisjs/plugin-timer": "1.0.0-alpha.0",
"@graphql-tools/schema": "^10.0.23",
"@hydrooj/common": "workspace:^",
@@ -33,7 +33,7 @@
"emojis-list": "2.1.0",
"fs-extra": "^11.3.0",
"graphql": "^16.10.0",
"graphql-scalars": "^1.24.1",
"graphql-scalars": "^1.24.2",
"js-yaml": "^4.1.0",
"koa-proxies": "^0.12.4",
"koa-static-cache": "^5.1.4",
+1 -1
View File
@@ -130,7 +130,7 @@ export async function load(ctx: Context) {
await setting(pending, fail, require('../model/setting'));
ctx.plugin(require('../service/server'));
ctx = await new Promise((resolve) => {
ctx.inject(['server'], (c) => {
ctx.inject(['server', 'setting', 'worker'], (c) => {
resolve(c);
});
});
+5 -1
View File
@@ -59,7 +59,11 @@ export async function apply(ctx: Context) {
await builtinModel(ctx);
await model(pending, fail, ctx);
await setting(pending, fail, require('../model/setting'));
ctx = await new Promise((resolve) => {
ctx.inject(['worker', 'setting'], (c) => {
resolve(c);
});
});
const handlerDir = path.resolve(__dirname, '..', 'handler');
const handlers = await fs.readdir(handlerDir);
for (const h of handlers.filter((i) => i.endsWith('.ts'))) {
+1 -1
View File
@@ -4,7 +4,7 @@ import { Context } from '../context';
import { Schedule } from '../interface';
import { Logger } from '../logger';
import db from '../service/db';
import type { WorkerService } from '../service/worker';
import type WorkerService from '../service/worker';
import RecordModel from './record';
const logger = new Logger('model/schedule');
-1
View File
@@ -389,7 +389,6 @@ export class SettingService extends Service {
export const inject = ['db'];
export async function apply(ctx: Context) {
ctx.provide('setting', undefined, true);
ctx.plugin(SettingService);
logger.info('Ensuring settings');
const system = global.Hydro.model.system;
+2 -6
View File
@@ -55,10 +55,11 @@ export class MongoService extends Service {
return mongourl;
}
async [Service.setup]() {
async *[Context.init]() {
const mongourl = await MongoService.getUrl();
const url = mongoUri.parse(mongourl);
this.client = await MongoClient.connect(mongourl);
yield () => { this.client.close(); }
this.db = this.client.db(url.database || 'hydro');
await bus.parallel('database/connect', this.db);
this.ctx.setInterval(() => this.fixExpireAfter(), Time.hour);
@@ -176,11 +177,6 @@ export class MongoService extends Service {
}
return results;
}
public async apply(ctx) {
await this.start();
ctx.on('dispose', () => this.client.close());
}
}
/** @deprecated use ctx.db instead */
+1 -6
View File
@@ -9,7 +9,7 @@ declare module '../context' {
}
}
export class WorkerService extends Service {
export default class WorkerService extends Service {
private handlers: Record<string, Function> = {};
consuming = true;
running = null;
@@ -85,8 +85,3 @@ export class WorkerService extends Service {
await this.promise;
}
}
export async function apply(ctx: Context) {
ctx.provide('worker', undefined, true);
ctx.worker = new WorkerService(ctx);
}
+1 -1
View File
@@ -27,7 +27,7 @@ export class ConfigService extends Service {
super(ctx, 'config');
}
async [Service.setup]() {
async [Context.init]() {
const payload = await this.ctx.db.collection('system').find({}).toArray();
this.initialValues = Object.fromEntries(payload.map((v) => [v._id, v.value]));
return await this.loadConfig();