mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
在session无效时切换至guest
This commit is contained in:
1 parent
2bf6adbaa0
commit
875bf696e2
4 files changed
+45
-34
No files matched your search
+28
-31
@@ -94,38 +94,35 @@ class SystemScriptHandler extends SystemHandler {
|
|||||||
const args = JSON.parse(raw);
|
const args = JSON.parse(raw);
|
||||||
validate(global.Hydro.script[id].validate, args);
|
validate(global.Hydro.script[id].validate, args);
|
||||||
const rid = await record.add(domainId, -1, this.user._id, '-', id, false, { input: 'raw' });
|
const rid = await record.add(domainId, -1, this.user._id, '-', id, false, { input: 'raw' });
|
||||||
judge.next({ domainId, rid, message: `Running script: ${id}` });
|
const report = (data) => judge.next({ domainId, rid, ...data });
|
||||||
async function report(data) {
|
report({ message: `Running script: ${id}` });
|
||||||
judge.next({ domainId, rid, ...data });
|
const start = new Date().getTime();
|
||||||
}
|
// Maybe async?
|
||||||
setTimeout(() => {
|
global.Hydro.script[id].run(args, report)
|
||||||
const start = new Date().getTime();
|
.then((ret: any) => {
|
||||||
global.Hydro.script[id].run(args, report)
|
const time = new Date().getTime() - start;
|
||||||
.then((ret: any) => {
|
judge.end({
|
||||||
const time = new Date().getTime() - start;
|
domainId,
|
||||||
judge.end({
|
rid,
|
||||||
domainId,
|
status: STATUS.STATUS_ACCEPTED,
|
||||||
rid,
|
message: ret.toString(),
|
||||||
status: STATUS.STATUS_ACCEPTED,
|
judger: 1,
|
||||||
message: ret.toString(),
|
time,
|
||||||
judger: 1,
|
memory: 0,
|
||||||
time,
|
|
||||||
memory: 0,
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.catch((err: Error) => {
|
|
||||||
const time = new Date().getTime() - start;
|
|
||||||
judge.end({
|
|
||||||
domainId,
|
|
||||||
rid,
|
|
||||||
status: STATUS.STATUS_SYSTEM_ERROR,
|
|
||||||
message: `${err}\n${err.stack}`,
|
|
||||||
judger: 1,
|
|
||||||
time,
|
|
||||||
memory: 0,
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}, 300);
|
})
|
||||||
|
.catch((err: Error) => {
|
||||||
|
const time = new Date().getTime() - start;
|
||||||
|
judge.end({
|
||||||
|
domainId,
|
||||||
|
rid,
|
||||||
|
status: STATUS.STATUS_SYSTEM_ERROR,
|
||||||
|
message: `${err}\n${err.stack}`,
|
||||||
|
judger: 1,
|
||||||
|
time,
|
||||||
|
memory: 0,
|
||||||
|
});
|
||||||
|
});
|
||||||
this.response.body = { rid };
|
this.response.body = { rid };
|
||||||
this.response.redirect = this.url('record_detail', { rid });
|
this.response.redirect = this.url('record_detail', { rid });
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-2
@@ -210,8 +210,13 @@ export async function getPrefixList(prefix: string, limit = 50) {
|
|||||||
return udocs;
|
return udocs;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setPriv(uid: number, priv: number) {
|
export async function setPriv(uid: number, priv: number) {
|
||||||
return coll.findOneAndUpdate({ _id: uid }, { $set: priv }, { returnOriginal: false });
|
const udoc = await coll.findOneAndUpdate(
|
||||||
|
{ _id: uid },
|
||||||
|
{ $set: { priv } },
|
||||||
|
{ returnOriginal: false },
|
||||||
|
);
|
||||||
|
return udoc.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ban(uid: number) {
|
export function ban(uid: number) {
|
||||||
|
|||||||
@@ -380,6 +380,15 @@ export class Handler {
|
|||||||
token.TYPE_TOKEN, 600, { uid: this.session.uid, domainId },
|
token.TYPE_TOKEN, 600, { uid: this.session.uid, domainId },
|
||||||
),
|
),
|
||||||
]);
|
]);
|
||||||
|
if (!this.user) {
|
||||||
|
this.session.uid = 0;
|
||||||
|
[this.user, this.UIContext.token] = await Promise.all([
|
||||||
|
user.getById(domainId, this.session.uid),
|
||||||
|
token.createOrUpdate(
|
||||||
|
token.TYPE_TOKEN, 600, { uid: this.session.uid, domainId },
|
||||||
|
),
|
||||||
|
]);
|
||||||
|
}
|
||||||
this.csrfToken = this.getCsrfToken(this.session._id || String.random(32));
|
this.csrfToken = this.getCsrfToken(this.session._id || String.random(32));
|
||||||
this.UIContext.csrfToken = this.csrfToken;
|
this.UIContext.csrfToken = this.csrfToken;
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hydrooj",
|
"name": "hydrooj",
|
||||||
"version": "2.10.10",
|
"version": "2.10.11",
|
||||||
"main": "dist/loader.js",
|
"main": "dist/loader.js",
|
||||||
"bin": "bin/hydrooj.js",
|
"bin": "bin/hydrooj.js",
|
||||||
"repository": "https://github.com/hydro-dev/Hydro.git",
|
"repository": "https://github.com/hydro-dev/Hydro.git",
|
||||||
|
|||||||
Reference in new issue
Block a user