Skip to content

Commit

Permalink
core: fix geoip inject
Browse files Browse the repository at this point in the history
  • Loading branch information
undefined-moe committed Mar 9, 2025
1 parent 97ef575 commit c4301a5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
13 changes: 8 additions & 5 deletions packages/hydrooj/src/entry/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { MongoService } from '../service/db';
import { ConfigService } from '../settings';
import {
addon, builtinModel, handler, lib, locale, model,
script, service, setting, template,
script, service, setting,
} from './common';

const argv = cac().parse();
Expand Down Expand Up @@ -95,9 +95,12 @@ export async function apply(ctx: Context) {
// eslint-disable-next-line no-await-in-loop
if (await fs.pathExists(dir)) await fs.copy(dir, path.join(os.homedir(), '.hydro/static'));
}
await ctx.parallel('app/listen');
logger.success('Server started');
process.send?.('ready');
await ctx.parallel('app/ready');
ctx.inject(['server'], async ({ server }) => {
await server.listen();
await ctx.parallel('app/listen');
logger.success('Server started');
process.send?.('ready');
await ctx.parallel('app/ready');
});
return { fail };
}
6 changes: 3 additions & 3 deletions packages/hydrooj/src/handler/home.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,15 @@ export class HomeHandler extends Handler {
class HomeSecurityHandler extends Handler {
@requireSudo
async get() {
const geoip = this.ctx.get('geoip');
// TODO(iceboy): pagination? or limit session count for uid?
const sessions = await token.getSessionListByUid(this.user._id);
for (const session of sessions) {
session.isCurrent = session._id === this.session._id;
session._id = md5(session._id);
const ua = session.updateUa || session.createUa;
if (ua) session.updateUaInfo = UAParser(ua);
session.updateGeoip = this.ctx.geoip?.lookup?.(
session.updateGeoip = geoip?.lookup?.(
session.updateIp || session.createIp,
this.translate('geoip_locale'),
);
Expand All @@ -201,7 +202,7 @@ class HomeSecurityHandler extends Handler {
'credentialID', 'name', 'credentialType', 'credentialDeviceType',
'authenticatorAttachment', 'regat', 'fmt',
])),
geoipProvider: this.ctx?.geoip?.provider,
geoipProvider: geoip?.provider,
};
}

Expand Down Expand Up @@ -603,7 +604,6 @@ class HomeMessagesConnectionHandler extends ConnectionHandler {
}
}

export const inject = { geoip: { required: false } };
export function apply(ctx: Context) {
ctx.Route('homepage', '/', HomeHandler);
ctx.Route('home_security', '/home/security', HomeSecurityHandler, PRIV.PRIV_USER_PROFILE);
Expand Down
4 changes: 0 additions & 4 deletions packages/hydrooj/src/service/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,5 @@ export async function apply(ctx: Context) {
on('handler/create/ws', async (h) => {
if (h.context.pendingError) throw h.context.pendingError;
});

on('app/listen', () => {
server.listen();
});
});
}

0 comments on commit c4301a5

Please sign in to comment.