core: 将pid设置为可选

This commit is contained in:
undefined committed 2021-03-08 00:00:53 +08:00
1 parent a22400d247
commit 4a294f59a8
8 files changed
+9 -14

No files matched your search

+2 -2
View File
@@ -246,11 +246,11 @@ class ProblemImportSYZOJHandler extends Handler {
protocol, host, pid, false,
);
this.response.body = { pid: targetPid || docId };
this.response.redirect = this.url('problem_settings', { pid: targetPid || docId });
this.response.redirect = this.url('problem_files', { pid: targetPid || docId });
} else {
const docId = await this.v2(domainId, targetPid, hidden, url);
this.response.body = { pid: targetPid || docId };
this.response.redirect = this.url('problem_settings', { pid: targetPid || docId });
this.response.redirect = this.url('problem_files', { pid: targetPid || docId });
}
}
}
+3 -3
View File
@@ -552,17 +552,17 @@ export class ProblemCreateHandler extends Handler {
@post('title', Types.String, isTitle)
@post('content', Types.String, isContent)
@post('pid', Types.String, isPid, true)
@post('pid', Types.String, true, isPid)
@post('hidden', Types.Boolean)
@post('tag', Types.String, true, null, parseCategory)
async post(domainId: string, title: string, content: string, pid: string, hidden = false, tag: string[] = []) {
try {
content = JSON.parse(content);
} catch { /* Ignore */ }
if (await problem.get(domainId, pid)) throw new BadRequestError('invalid pid');
if (pid && await problem.get(domainId, pid)) throw new BadRequestError('invalid pid');
const docId = await problem.add(domainId, pid, title, content, this.user._id, tag, hidden);
this.response.body = { pid: pid || docId };
this.response.redirect = this.url('problem_settings', { pid: pid || docId });
this.response.redirect = this.url('problem_files', { pid: pid || docId });
}
}
+3 -4
View File
@@ -21,19 +21,18 @@ function ensureIndexes() {
}
export async function add(
tokenType: number, expireSeconds: number, data: any,
tokenType: number, expireSeconds: number, data: any, id = String.random(32),
): Promise<[string, TokenDoc]> {
const now = new Date();
const str = String.random(32);
const res = await coll.insertOne({
...data,
_id: str,
_id: id,
tokenType,
createAt: now,
updateAt: now,
expireAt: new Date(now.getTime() + expireSeconds * 1000),
});
return [str, res.ops[0]];
return [id, res.ops[0]];
}
export async function get(tokenId: string, tokenType: number): Promise<TokenDoc | null> {