mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: 支持绑定自定义域名
This commit is contained in:
1 parent
c0efda36cd
commit
62a5bc319b
6 files changed
+33
-6
No files matched your search
+1
-1
@@ -65,7 +65,7 @@ pm2 start "./minio server /data/file" --name minio
|
|||||||
# TODO: install basic addons?
|
# TODO: install basic addons?
|
||||||
echo "Installing Hydro"
|
echo "Installing Hydro"
|
||||||
yarn global add hydrooj @hydrooj/ui-default @hydrooj/hydrojudge
|
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_
|
chmod +x /usr/bin/sandbox_
|
||||||
pm2 start "/usr/bin/sandbox_"
|
pm2 start "/usr/bin/sandbox_"
|
||||||
mkdir ~/.hydro
|
mkdir ~/.hydro
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hydrooj",
|
"name": "hydrooj",
|
||||||
"version": "2.15.30",
|
"version": "2.15.31",
|
||||||
"bin": "bin/hydrooj.js",
|
"bin": "bin/hydrooj.js",
|
||||||
"main": "dist/loader.js",
|
"main": "dist/loader.js",
|
||||||
"typings": "dist/loader.d.ts",
|
"typings": "dist/loader.d.ts",
|
||||||
|
|||||||
@@ -310,7 +310,7 @@ export interface DomainDoc extends Dictionary<any> {
|
|||||||
bulletin: string,
|
bulletin: string,
|
||||||
pidCounter: number,
|
pidCounter: number,
|
||||||
join?: any,
|
join?: any,
|
||||||
hostname?: string,
|
host?: string,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Message
|
// Message
|
||||||
|
|||||||
@@ -53,6 +53,16 @@ export async function get(domainId: string): Promise<DomainDoc | null> {
|
|||||||
return result;
|
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> = {}) {
|
export function getMulti(query: FilterQuery<DomainDoc> = {}) {
|
||||||
return coll.find(query);
|
return coll.find(query);
|
||||||
}
|
}
|
||||||
@@ -212,6 +222,7 @@ global.Hydro.model.domain = {
|
|||||||
add,
|
add,
|
||||||
inc,
|
inc,
|
||||||
get,
|
get,
|
||||||
|
getByHost,
|
||||||
edit,
|
edit,
|
||||||
getMulti,
|
getMulti,
|
||||||
getList,
|
getList,
|
||||||
|
|||||||
@@ -108,6 +108,7 @@ DomainSetting(
|
|||||||
Setting('setting_domain', 'gravatar', null, '', 'text', 'gravatar', 'Will be used as the domain icon.'),
|
Setting('setting_domain', 'gravatar', null, '', 'text', 'gravatar', 'Will be used as the domain icon.'),
|
||||||
Setting('setting_domain', 'bulletin', null, '', 'markdown', 'Bulletin'),
|
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', '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(
|
DomainUserSetting(
|
||||||
|
|||||||
@@ -302,12 +302,20 @@ export class HandlerCommon {
|
|||||||
else query[key] = kwargs.query[key].toString();
|
else query[key] = kwargs.query[key].toString();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
const { anchor } = args;
|
||||||
|
if (!this.domain.host) {
|
||||||
if (this.domainId !== 'system' || args.domainId) {
|
if (this.domainId !== 'system' || args.domainId) {
|
||||||
name += '_with_domainId';
|
name += '_with_domainId';
|
||||||
args.domainId = args.domainId || this.domainId;
|
args.domainId = args.domainId || this.domainId;
|
||||||
}
|
}
|
||||||
const { anchor } = args;
|
|
||||||
res = router.url(name, args, { query });
|
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}`;
|
if (anchor) return `${res}#${anchor}`;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.warn(e.message);
|
logger.warn(e.message);
|
||||||
@@ -431,13 +439,20 @@ export class Handler extends HandlerCommon {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async init({ domainId }) {
|
async init({ domainId }) {
|
||||||
[this.domain] = await Promise.all([
|
const [absoluteDomain, inferDomain] = await Promise.all([
|
||||||
domain.get(domainId),
|
domain.get(domainId),
|
||||||
|
domain.getByHost(this.request.host),
|
||||||
this.limitRate('global', 10, 100),
|
this.limitRate('global', 10, 100),
|
||||||
this.getSession(),
|
this.getSession(),
|
||||||
this.getBdoc(),
|
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.args.domainId = 'system';
|
||||||
this.user = await user.getById('system', this.session.uid);
|
this.user = await user.getById('system', this.session.uid);
|
||||||
if (!this.user) this.user = await user.getById('system', 0);
|
if (!this.user) this.user = await user.getById('system', 0);
|
||||||
|
|||||||
Reference in new issue
Block a user