mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-18 01:36:08 +08:00
core: 修复strpid无法设置的问题
This commit is contained in:
1 parent
65094e53b6
commit
0195137c61
5 files changed
+27
-28
No files matched your search
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hydrooj",
|
||||
"version": "2.13.54",
|
||||
"version": "2.13.55",
|
||||
"bin": "bin/hydrooj.js",
|
||||
"main": "dist/loader.js",
|
||||
"typings": "dist/loader.d.ts",
|
||||
|
||||
@@ -12,9 +12,7 @@ import {
|
||||
Pdoc, User, Rdoc, PathComponent,
|
||||
} from '../interface';
|
||||
import paginate from '../lib/paginate';
|
||||
import {
|
||||
checkPid, isTitle, isContent, isPid,
|
||||
} from '../lib/validator';
|
||||
import { isTitle, isContent, isPid } from '../lib/validator';
|
||||
import { ProblemAdd } from '../lib/ui';
|
||||
import * as file from '../model/file';
|
||||
import * as problem from '../model/problem';
|
||||
@@ -25,7 +23,7 @@ import * as solution from '../model/solution';
|
||||
import { PERM, PRIV, CONSTANT } from '../model/builtin';
|
||||
import * as bus from '../service/bus';
|
||||
import {
|
||||
Route, Connection, Handler, ConnectionHandler, Types, param,
|
||||
Route, Connection, Handler, ConnectionHandler, Types, param, post, route,
|
||||
} from '../service/server';
|
||||
|
||||
export const parseCategory = (value: string) => flatten(value.split('+').map((e) => e.split(','))).map((e) => e.trim());
|
||||
@@ -170,7 +168,7 @@ export class ProblemDetailHandler extends ProblemHandler {
|
||||
|
||||
udoc: User;
|
||||
|
||||
@param('pid', Types.String, true, null, parsePid)
|
||||
@route('pid', Types.String, true, null, parsePid)
|
||||
async _prepare(domainId: string, pid: number | string) {
|
||||
this.response.template = 'problem_detail.html';
|
||||
this.pdoc = await problem.get(domainId, pid, this.user._id);
|
||||
@@ -437,15 +435,12 @@ export class ProblemEditHandler extends ProblemManageHandler {
|
||||
|
||||
@param('title', Types.String, isTitle)
|
||||
@param('content', Types.String, isContent)
|
||||
async post(domainId: string, title: string, content: string) {
|
||||
const $update: Partial<Pdoc> = { title, content };
|
||||
if (this.request.body.pid) {
|
||||
if (this.request.body.pid.toString() === this.pdoc.docId.toString()) $update.pid = this.request.body.pid;
|
||||
else $update.pid = checkPid(this.request.body.pid);
|
||||
}
|
||||
const pdoc = await problem.get(domainId, this.request.params.pid);
|
||||
await problem.edit(domainId, pdoc.docId, $update);
|
||||
this.response.redirect = this.url('problem_detail', { pid: this.request.params.pid });
|
||||
@post('pid', Types.String, isPid, true)
|
||||
async post(domainId: string, title: string, content: string, newPid: string = '') {
|
||||
const $update: Partial<Pdoc> = { title, content, pid: newPid };
|
||||
let pdoc = await problem.get(domainId, this.request.params.pid);
|
||||
pdoc = await problem.edit(domainId, pdoc.docId, $update);
|
||||
this.response.redirect = this.url('problem_detail', { pid: pdoc.pid || pdoc.docId });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* eslint-disable object-curly-newline */
|
||||
import assert from 'assert';
|
||||
import {
|
||||
ObjectID, Cursor, FilterQuery, UpdateQuery,
|
||||
ObjectID, Cursor, FilterQuery, UpdateQuery, OnlyFieldsOfType,
|
||||
} from 'mongodb';
|
||||
import {
|
||||
Pdoc, Ddoc, Drdoc, Tdoc, TrainingDoc, ProblemStatusDoc,
|
||||
@@ -92,12 +92,15 @@ export async function get<K extends keyof DocType>(domainId: string, docType: K,
|
||||
}
|
||||
|
||||
export async function set<K extends keyof DocType>(
|
||||
domainId: string, docType: K, docId: DocType[K]['docId'], $set: Partial<DocType[K]>,
|
||||
domainId: string, docType: K, docId: DocType[K]['docId'], $set?: Partial<DocType[K]>, $unset?: OnlyFieldsOfType<DocType[K], any, true | '' | 1>,
|
||||
): Promise<DocType[K]> {
|
||||
await bus.parallel('document/set', domainId, docType, docId, $set);
|
||||
await bus.parallel('document/set', domainId, docType, docId, $set, $unset);
|
||||
const update: UpdateQuery<DocType[K]> = {};
|
||||
if ($set) update.$set = $set;
|
||||
if ($unset) update.$unset = $unset;
|
||||
const res = await coll.findOneAndUpdate(
|
||||
{ domainId, docType, docId },
|
||||
{ $set },
|
||||
update,
|
||||
{ returnOriginal: false, upsert: true },
|
||||
);
|
||||
return res.value;
|
||||
|
||||
@@ -82,12 +82,11 @@ export async function add(
|
||||
tag: string[] = [], category: string[] = [], data: ProblemDataSource = null, hidden = false,
|
||||
) {
|
||||
const pidCounter = await domain.inc(domainId, 'pidCounter', 1);
|
||||
return await document.add(
|
||||
domainId, content, owner, document.TYPE_PROBLEM, pidCounter, null, null,
|
||||
{
|
||||
pid, title, data, category, tag, hidden, nSubmit: 0, nAccept: 0,
|
||||
},
|
||||
) as number;
|
||||
const args: Partial<Pdoc> = {
|
||||
title, data, category, tag, hidden, nSubmit: 0, nAccept: 0,
|
||||
};
|
||||
if (pid) args.pid = pid;
|
||||
return await document.add(domainId, content, owner, document.TYPE_PROBLEM, pidCounter, null, null, args);
|
||||
}
|
||||
|
||||
export async function get(
|
||||
@@ -116,7 +115,9 @@ export function getMultiStatus(domainId: string, query: FilterQuery<Pdoc>) {
|
||||
}
|
||||
|
||||
export function edit(domainId: string, _id: number, $set: Partial<Pdoc>): Promise<Pdoc> {
|
||||
return document.set(domainId, document.TYPE_PROBLEM, _id, $set);
|
||||
const delpid = $set.pid === '';
|
||||
if (delpid) delete $set.pid;
|
||||
return document.set(domainId, document.TYPE_PROBLEM, _id, $set, delpid ? { pid: '' } : undefined);
|
||||
}
|
||||
|
||||
export function inc(domainId: string, _id: number, field: NumberKeys<Pdoc>, n: number): Promise<Pdoc> {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* eslint-disable no-await-in-loop */
|
||||
import cluster from 'cluster';
|
||||
import { Db, FilterQuery } from 'mongodb';
|
||||
import { Db, FilterQuery, OnlyFieldsOfType } from 'mongodb';
|
||||
import { argv } from 'yargs';
|
||||
import { Logger } from '../logger';
|
||||
import {
|
||||
@@ -48,7 +48,7 @@ export interface EventMap {
|
||||
|
||||
'document/add': (doc: any) => VoidReturn
|
||||
'document/set': <T extends keyof DocType>
|
||||
(domainId: string, docType: T, docId: DocType[T], $set: any) => VoidReturn
|
||||
(domainId: string, docType: T, docId: DocType[T], $set: any, $unset: OnlyFieldsOfType<DocType[T], any, true | '' | 1>) => VoidReturn
|
||||
|
||||
'problem/edit': (doc: Pdoc) => VoidReturn
|
||||
'problem/list': (query: FilterQuery<Pdoc>, handler: any) => VoidReturn
|
||||
|
||||
Reference in new issue
Block a user