mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 17:36:08 +08:00
core: 将pid设置为可选
This commit is contained in:
1 parent
a22400d247
commit
4a294f59a8
8 files changed
+9
-14
No files matched your search
@@ -60,7 +60,6 @@ problem_detail: Problem Detail
|
||||
problem_edit: Problem Edit
|
||||
problem_import: Import Problem
|
||||
problem_main: Problem Set
|
||||
problem_settings: Problem Settings
|
||||
problem_solution: Problem Solution
|
||||
problem_statistics: Problem Statistics
|
||||
problem_submit: Problem Submit
|
||||
|
||||
@@ -525,7 +525,6 @@ problem_create: 문제 만들기
|
||||
problem_edit: 문제 수정
|
||||
problem_import: 문제 가져오기
|
||||
problem_main: 문제
|
||||
problem_settings: 문제 설정
|
||||
problem_solution: 문제 해설
|
||||
problem_statistics: 문제 통계
|
||||
problem_submit: 제출
|
||||
|
||||
@@ -540,7 +540,6 @@ problem_files: 题目文件
|
||||
problem_import_syzoj: 从 SYZOJ 导入题目
|
||||
problem_import: 导入题目
|
||||
problem_main: 题库
|
||||
problem_settings: 题目设置
|
||||
problem_solution: 题解
|
||||
problem_statistics: 题目统计
|
||||
problem_submit: 递交代码
|
||||
|
||||
@@ -344,7 +344,6 @@ Problem Tags Visibility: 題目標籤可見性
|
||||
problem_create: 創建題目
|
||||
problem_edit: 編輯題目
|
||||
problem_main: 題庫
|
||||
problem_settings: 題目設定
|
||||
problem_solution: 題解
|
||||
problem_submit: 遞交程式碼
|
||||
Problem: 題目
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hydrooj",
|
||||
"version": "2.20.7",
|
||||
"version": "2.20.8",
|
||||
"bin": "bin/hydrooj.js",
|
||||
"main": "dist/loader.js",
|
||||
"typings": "dist/loader.d.ts",
|
||||
|
||||
@@ -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 });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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> {
|
||||
|
||||
Reference in new issue
Block a user