mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
在session无效时切换至guest
This commit is contained in:
1 parent
2bf6adbaa0
commit
875bf696e2
4 files changed
+20
-9
No files matched your search
@@ -94,12 +94,10 @@ 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 });
|
|
||||||
}
|
|
||||||
setTimeout(() => {
|
|
||||||
const start = new Date().getTime();
|
const start = new Date().getTime();
|
||||||
|
// Maybe async?
|
||||||
global.Hydro.script[id].run(args, report)
|
global.Hydro.script[id].run(args, report)
|
||||||
.then((ret: any) => {
|
.then((ret: any) => {
|
||||||
const time = new Date().getTime() - start;
|
const time = new Date().getTime() - start;
|
||||||
@@ -125,7 +123,6 @@ class SystemScriptHandler extends SystemHandler {
|
|||||||
memory: 0,
|
memory: 0,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}, 300);
|
|
||||||
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