mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 09:46:28 +08:00
core: fix geoip inject
This commit is contained in:
3 files changed
+11
-12
No files matched your search
@@ -11,7 +11,7 @@ import { MongoService } from '../service/db';
|
|||||||
import { ConfigService } from '../settings';
|
import { ConfigService } from '../settings';
|
||||||
import {
|
import {
|
||||||
addon, builtinModel, handler, lib, locale, model,
|
addon, builtinModel, handler, lib, locale, model,
|
||||||
script, service, setting, template,
|
script, service, setting,
|
||||||
} from './common';
|
} from './common';
|
||||||
|
|
||||||
const argv = cac().parse();
|
const argv = cac().parse();
|
||||||
@@ -95,9 +95,12 @@ export async function apply(ctx: Context) {
|
|||||||
// eslint-disable-next-line no-await-in-loop
|
// eslint-disable-next-line no-await-in-loop
|
||||||
if (await fs.pathExists(dir)) await fs.copy(dir, path.join(os.homedir(), '.hydro/static'));
|
if (await fs.pathExists(dir)) await fs.copy(dir, path.join(os.homedir(), '.hydro/static'));
|
||||||
}
|
}
|
||||||
await ctx.parallel('app/listen');
|
ctx.inject(['server'], async ({ server }) => {
|
||||||
logger.success('Server started');
|
await server.listen();
|
||||||
process.send?.('ready');
|
await ctx.parallel('app/listen');
|
||||||
await ctx.parallel('app/ready');
|
logger.success('Server started');
|
||||||
|
process.send?.('ready');
|
||||||
|
await ctx.parallel('app/ready');
|
||||||
|
});
|
||||||
return { fail };
|
return { fail };
|
||||||
}
|
}
|
||||||
@@ -181,6 +181,7 @@ export class HomeHandler extends Handler {
|
|||||||
class HomeSecurityHandler extends Handler {
|
class HomeSecurityHandler extends Handler {
|
||||||
@requireSudo
|
@requireSudo
|
||||||
async get() {
|
async get() {
|
||||||
|
const geoip = this.ctx.get('geoip');
|
||||||
// TODO(iceboy): pagination? or limit session count for uid?
|
// TODO(iceboy): pagination? or limit session count for uid?
|
||||||
const sessions = await token.getSessionListByUid(this.user._id);
|
const sessions = await token.getSessionListByUid(this.user._id);
|
||||||
for (const session of sessions) {
|
for (const session of sessions) {
|
||||||
@@ -188,7 +189,7 @@ class HomeSecurityHandler extends Handler {
|
|||||||
session._id = md5(session._id);
|
session._id = md5(session._id);
|
||||||
const ua = session.updateUa || session.createUa;
|
const ua = session.updateUa || session.createUa;
|
||||||
if (ua) session.updateUaInfo = UAParser(ua);
|
if (ua) session.updateUaInfo = UAParser(ua);
|
||||||
session.updateGeoip = this.ctx.geoip?.lookup?.(
|
session.updateGeoip = geoip?.lookup?.(
|
||||||
session.updateIp || session.createIp,
|
session.updateIp || session.createIp,
|
||||||
this.translate('geoip_locale'),
|
this.translate('geoip_locale'),
|
||||||
);
|
);
|
||||||
@@ -201,7 +202,7 @@ class HomeSecurityHandler extends Handler {
|
|||||||
'credentialID', 'name', 'credentialType', 'credentialDeviceType',
|
'credentialID', 'name', 'credentialType', 'credentialDeviceType',
|
||||||
'authenticatorAttachment', 'regat', 'fmt',
|
'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) {
|
export function apply(ctx: Context) {
|
||||||
ctx.Route('homepage', '/', HomeHandler);
|
ctx.Route('homepage', '/', HomeHandler);
|
||||||
ctx.Route('home_security', '/home/security', HomeSecurityHandler, PRIV.PRIV_USER_PROFILE);
|
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) => {
|
on('handler/create/ws', async (h) => {
|
||||||
if (h.context.pendingError) throw h.context.pendingError;
|
if (h.context.pendingError) throw h.context.pendingError;
|
||||||
});
|
});
|
||||||
|
|
||||||
on('app/listen', () => {
|
|
||||||
server.listen();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user