mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: fix geoip inject
This commit is contained in:
3 files changed
+7
-8
No files matched your search
@@ -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();
|
||||
@@ -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'));
|
||||
}
|
||||
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 };
|
||||
}
|
||||
@@ -181,6 +181,7 @@ 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) {
|
||||
@@ -188,7 +189,7 @@ class HomeSecurityHandler extends Handler {
|
||||
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'),
|
||||
);
|
||||
@@ -201,7 +202,7 @@ class HomeSecurityHandler extends Handler {
|
||||
'credentialID', 'name', 'credentialType', 'credentialDeviceType',
|
||||
'authenticatorAttachment', 'regat', 'fmt',
|
||||
])),
|
||||
geoipProvider: this.ctx?.geoip?.provider,
|
||||
geoipProvider: geoip?.provider,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user