mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 09:36:08 +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);
|
||||
validate(global.Hydro.script[id].validate, args);
|
||||
const rid = await record.add(domainId, -1, this.user._id, '-', id, false, { input: 'raw' });
|
||||
judge.next({ domainId, rid, message: `Running script: ${id}` });
|
||||
async function report(data) {
|
||||
judge.next({ domainId, rid, ...data });
|
||||
}
|
||||
setTimeout(() => {
|
||||
const start = new Date().getTime();
|
||||
global.Hydro.script[id].run(args, report)
|
||||
.then((ret: any) => {
|
||||
const time = new Date().getTime() - start;
|
||||
judge.end({
|
||||
domainId,
|
||||
rid,
|
||||
status: STATUS.STATUS_ACCEPTED,
|
||||
message: ret.toString(),
|
||||
judger: 1,
|
||||
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,
|
||||
});
|
||||
const report = (data) => judge.next({ domainId, rid, ...data });
|
||||
report({ message: `Running script: ${id}` });
|
||||
const start = new Date().getTime();
|
||||
// Maybe async?
|
||||
global.Hydro.script[id].run(args, report)
|
||||
.then((ret: any) => {
|
||||
const time = new Date().getTime() - start;
|
||||
judge.end({
|
||||
domainId,
|
||||
rid,
|
||||
status: STATUS.STATUS_ACCEPTED,
|
||||
message: ret.toString(),
|
||||
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.redirect = this.url('record_detail', { rid });
|
||||
}
|
||||
|
||||
+7
-2
@@ -210,8 +210,13 @@ export async function getPrefixList(prefix: string, limit = 50) {
|
||||
return udocs;
|
||||
}
|
||||
|
||||
export function setPriv(uid: number, priv: number) {
|
||||
return coll.findOneAndUpdate({ _id: uid }, { $set: priv }, { returnOriginal: false });
|
||||
export async function setPriv(uid: number, priv: number) {
|
||||
const udoc = await coll.findOneAndUpdate(
|
||||
{ _id: uid },
|
||||
{ $set: { priv } },
|
||||
{ returnOriginal: false },
|
||||
);
|
||||
return udoc.value;
|
||||
}
|
||||
|
||||
export function ban(uid: number) {
|
||||
|
||||
@@ -380,6 +380,15 @@ export class Handler {
|
||||
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.UIContext.csrfToken = this.csrfToken;
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hydrooj",
|
||||
"version": "2.10.10",
|
||||
"version": "2.10.11",
|
||||
"main": "dist/loader.js",
|
||||
"bin": "bin/hydrooj.js",
|
||||
"repository": "https://github.com/hydro-dev/Hydro.git",
|
||||
|
||||
Reference in new issue
Block a user