core: 支持绑定自定义域名

pull/56/head
undefined 4 years ago
parent c0efda36cd
commit 62a5bc319b

@ -65,7 +65,7 @@ pm2 start "./minio server /data/file" --name minio
# TODO: install basic addons?
echo "Installing Hydro"
yarn global add hydrooj @hydrooj/ui-default @hydrooj/hydrojudge
wget https://github.com/criyle/go-judge/releases/download/v1.0.5/executorserver-amd64 -O /usr/bin/sandbox
wget https://github.com/criyle/go-judge/releases/download/v1.0.5/executorserver-amd64 -O /usr/bin/sandbox_
chmod +x /usr/bin/sandbox_
pm2 start "/usr/bin/sandbox_"
mkdir ~/.hydro

@ -1,6 +1,6 @@
{
"name": "hydrooj",
"version": "2.15.30",
"version": "2.15.31",
"bin": "bin/hydrooj.js",
"main": "dist/loader.js",
"typings": "dist/loader.d.ts",

@ -310,7 +310,7 @@ export interface DomainDoc extends Dictionary<any> {
bulletin: string,
pidCounter: number,
join?: any,
hostname?: string,
host?: string,
}
// Message

@ -53,6 +53,16 @@ export async function get(domainId: string): Promise<DomainDoc | null> {
return result;
}
export async function getByHost(host: string): Promise<DomainDoc | null> {
const query: FilterQuery<DomainDoc> = { host };
await bus.serial('domain/before-get', query);
console.log(query);
const result = await coll.findOne(query);
console.log(result);
await bus.serial('domain/get', result);
return result;
}
export function getMulti(query: FilterQuery<DomainDoc> = {}) {
return coll.find(query);
}
@ -212,6 +222,7 @@ global.Hydro.model.domain = {
add,
inc,
get,
getByHost,
edit,
getMulti,
getList,

@ -108,6 +108,7 @@ DomainSetting(
Setting('setting_domain', 'gravatar', null, '', 'text', 'gravatar', 'Will be used as the domain icon.'),
Setting('setting_domain', 'bulletin', null, '', 'markdown', 'Bulletin'),
Setting('setting_storage', 'pidCounter', null, 0, 'number', 'Problem ID Counter', null, FLAG_HIDDEN | FLAG_DISABLED),
Setting('setting_storage', 'host', null, '', 'text', 'Custom host', null, FLAG_HIDDEN | FLAG_DISABLED),
);
DomainUserSetting(

@ -302,12 +302,20 @@ export class HandlerCommon {
else query[key] = kwargs.query[key].toString();
}
try {
if (this.domainId !== 'system' || args.domainId) {
name += '_with_domainId';
args.domainId = args.domainId || this.domainId;
}
const { anchor } = args;
res = router.url(name, args, { query });
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 (anchor) return `${res}#${anchor}`;
} catch (e) {
logger.warn(e.message);
@ -431,13 +439,20 @@ export class Handler extends HandlerCommon {
}
async init({ domainId }) {
[this.domain] = await Promise.all([
const [absoluteDomain, inferDomain] = await Promise.all([
domain.get(domainId),
domain.getByHost(this.request.host),
this.limitRate('global', 10, 100),
this.getSession(),
this.getBdoc(),
]);
if (!this.domain) {
if (inferDomain) {
this.domainId = inferDomain._id;
this.args.domainId = inferDomain._id;
this.domain = inferDomain;
domainId = inferDomain._id;
} else if (absoluteDomain) this.domain = absoluteDomain;
else {
this.args.domainId = 'system';
this.user = await user.getById('system', this.session.uid);
if (!this.user) this.user = await user.getById('system', 0);

Loading…
Cancel
Save