diff --git a/packages/hydrooj/package.json b/packages/hydrooj/package.json index 7360dc9a3..9bd092cc3 100644 --- a/packages/hydrooj/package.json +++ b/packages/hydrooj/package.json @@ -1,6 +1,6 @@ { "name": "hydrooj", - "version": "2.17.0", + "version": "2.17.1", "bin": "bin/hydrooj.js", "main": "dist/loader.js", "typings": "dist/loader.d.ts", diff --git a/packages/hydrooj/src/handler/problem.ts b/packages/hydrooj/src/handler/problem.ts index c4f7ade6a..489fd4a99 100644 --- a/packages/hydrooj/src/handler/problem.ts +++ b/packages/hydrooj/src/handler/problem.ts @@ -281,7 +281,6 @@ export class ProblemPretestHandler extends ProblemDetailHandler { @param('input', Types.String, true) async post(domainId: string, lang: string, code: string, input: string = '') { this.limitRate('add_record', 3600, 100); - // TODO parseConfig const rid = await record.add( domainId, this.pdoc.docId, this.user._id, lang, code, true, diff --git a/packages/hydrooj/src/script/rating.ts b/packages/hydrooj/src/script/rating.ts index f4b528a57..f2147e2f0 100644 --- a/packages/hydrooj/src/script/rating.ts +++ b/packages/hydrooj/src/script/rating.ts @@ -116,7 +116,6 @@ export async function calcLevel(domainId: string, report: Function) { bulk.find(query).update({ $set: { level: levels[i][0] } }); } const i = levels.length - 1; - report({ message: 'Updating users levelled {0}'.format(levels[i][0]) }); bulk.find({ domainId, rank: { $lte: levels[i][1] } }).update({ $set: { level: levels[i][0] } }); await bulk.execute(); } diff --git a/packages/hydrooj/src/service/server.ts b/packages/hydrooj/src/service/server.ts index b32463bc4..f5564f036 100644 --- a/packages/hydrooj/src/service/server.ts +++ b/packages/hydrooj/src/service/server.ts @@ -303,19 +303,12 @@ export class HandlerCommon { } try { const { anchor } = args; - if (!this.domain.host) { - if (this.domainId !== 'system' || args.domainId) { - name += '_with_domainId'; - args.domainId = args.domainId || this.domainId; - } - res = router.url(name, args, { query }); - } else { - if ((this.request.path || '').startsWith('/d/')) { - name += '_with_domainId'; - args.domainId = args.domainId || this.domainId; - } - res = `//${this.domain.host}${router.url(name, args, { query })}`; + if (args.domainId) name += '_with_domainId'; + else if (this.domain.host !== this.request.host && this.domainId !== 'system') { + name += '_with_domainId'; + args.domainId = this.domainId; } + res = router.url(name, args, { query }); if (anchor) return `${res}#${anchor}`; } catch (e) { logger.warn(e.message); @@ -546,29 +539,19 @@ export class Handler extends HandlerCommon { const expireSeconds = this.session.save ? system.get('session.expire_seconds') : system.get('session.unsaved_expire_seconds'); + const $update = { + updateIp: this.request.ip, + updateUa: this.request.headers['user-agent'] || '', + }; + const $create = { + createIp: this.request.ip, + createUa: this.request.headers['user-agent'] || '', + createHost: this.request.host, + }; if (this.session._id) { - await token.update( - this.session._id, - token.TYPE_SESSION, - expireSeconds, - { - ...this.session, - updateIp: this.request.ip, - updateUa: this.request.headers['user-agent'] || '', - }, - ); + await token.update(this.session._id, token.TYPE_SESSION, expireSeconds, { ...this.session, ...$update }); } else { - [, this.session] = await token.add( - token.TYPE_SESSION, - expireSeconds, - { - ...this.session, - createIp: this.request.ip, - createUa: this.request.headers['user-agent'] || '', - updateIp: this.request.ip, - updateUa: this.request.headers['user-agent'] || '', - }, - ); + [, this.session] = await token.add(token.TYPE_SESSION, expireSeconds, { ...this.session, ...$update, ...$create }); } const cookie: SetOption = { secure: !!system.get('session.secure'),