mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: feat: problem_send
This commit is contained in:
1 parent
62a5bc319b
commit
6fbb7588e1
4 files changed
+35
-4
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hydrooj",
|
"name": "hydrooj",
|
||||||
"version": "2.15.31",
|
"version": "2.15.32",
|
||||||
"bin": "bin/hydrooj.js",
|
"bin": "bin/hydrooj.js",
|
||||||
"main": "dist/loader.js",
|
"main": "dist/loader.js",
|
||||||
"typings": "dist/loader.d.ts",
|
"typings": "dist/loader.d.ts",
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { isSafeInteger, flatten, pick } from 'lodash';
|
|||||||
import yaml from 'js-yaml';
|
import yaml from 'js-yaml';
|
||||||
import fs from 'fs-extra';
|
import fs from 'fs-extra';
|
||||||
import { FilterQuery, ObjectID } from 'mongodb';
|
import { FilterQuery, ObjectID } from 'mongodb';
|
||||||
|
import superagent from 'superagent';
|
||||||
import AdmZip from 'adm-zip';
|
import AdmZip from 'adm-zip';
|
||||||
import {
|
import {
|
||||||
NoProblemError, BadRequestError, PermissionError,
|
NoProblemError, BadRequestError, PermissionError,
|
||||||
@@ -17,6 +18,8 @@ import { ProblemAdd } from '../lib/ui';
|
|||||||
import * as problem from '../model/problem';
|
import * as problem from '../model/problem';
|
||||||
import * as record from '../model/record';
|
import * as record from '../model/record';
|
||||||
import * as domain from '../model/domain';
|
import * as domain from '../model/domain';
|
||||||
|
import * as system from '../model/system';
|
||||||
|
import * as token from '../model/token';
|
||||||
import * as user from '../model/user';
|
import * as user from '../model/user';
|
||||||
import * as solution from '../model/solution';
|
import * as solution from '../model/solution';
|
||||||
import { PERM, PRIV, CONSTANT } from '../model/builtin';
|
import { PERM, PRIV, CONSTANT } from '../model/builtin';
|
||||||
@@ -687,6 +690,33 @@ export class ProblemImportHandler extends Handler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class ProblemSendHandler extends Handler {
|
||||||
|
async get() {
|
||||||
|
this.response.template = 'problem_send.html';
|
||||||
|
}
|
||||||
|
|
||||||
|
@post('target', Types.String)
|
||||||
|
@post('pids', Types.Array)
|
||||||
|
async post(domainId: string, target: any, pids: number[]) {
|
||||||
|
target = target.split('@');
|
||||||
|
const getHidden = this.user.hasPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN);
|
||||||
|
const pdocs = await problem.getList(domainId, pids, getHidden, true);
|
||||||
|
const getData = this.user.hasPerm(PERM.PERM_READ_PROBLEM_DATA);
|
||||||
|
if (!getData) {
|
||||||
|
for (const pid in pdocs) {
|
||||||
|
if (pdocs[pid].owner !== this.user._id) {
|
||||||
|
throw new PermissionError(PERM.PERM_READ_PROBLEM_DATA);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const [source, expire] = system.getMany(['server.url', 'session.expire_seconds']);
|
||||||
|
const tokenId = await token.createOrUpdate(token.TYPE_EXPORT, expire, { domainId, pids });
|
||||||
|
await superagent.post(`${target[1]}/d/${target[0]}/problem/receive`)
|
||||||
|
.send({ source, domainId, tokenId });
|
||||||
|
this.back();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export async function apply() {
|
export async function apply() {
|
||||||
ProblemAdd('problem_import', {}, 'copy', 'Import From Hydro');
|
ProblemAdd('problem_import', {}, 'copy', 'Import From Hydro');
|
||||||
Route('problem_main', '/p', ProblemMainHandler, PERM.PERM_VIEW_PROBLEM);
|
Route('problem_main', '/p', ProblemMainHandler, PERM.PERM_VIEW_PROBLEM);
|
||||||
@@ -706,6 +736,7 @@ export async function apply() {
|
|||||||
Route('problem_solution_reply_raw', '/p/:pid/solution/:psid/:psrid/raw', ProblemSolutionRawHandler, PERM.PERM_VIEW_PROBLEM);
|
Route('problem_solution_reply_raw', '/p/:pid/solution/:psid/:psrid/raw', ProblemSolutionRawHandler, PERM.PERM_VIEW_PROBLEM);
|
||||||
Route('problem_create', '/problem/create', ProblemCreateHandler, PERM.PERM_CREATE_PROBLEM);
|
Route('problem_create', '/problem/create', ProblemCreateHandler, PERM.PERM_CREATE_PROBLEM);
|
||||||
Route('problem_import', '/problem/import', ProblemImportHandler, PERM.PERM_CREATE_PROBLEM);
|
Route('problem_import', '/problem/import', ProblemImportHandler, PERM.PERM_CREATE_PROBLEM);
|
||||||
|
Route('problem_send', '/problem/send', ProblemSendHandler, PERM.PERM_VIEW_PROBLEM);
|
||||||
Connection('problem_pretest_conn', '/conn/pretest', ProblemPretestConnectionHandler, PERM.PERM_SUBMIT_PROBLEM);
|
Connection('problem_pretest_conn', '/conn/pretest', ProblemPretestConnectionHandler, PERM.PERM_SUBMIT_PROBLEM);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { Dictionary } from 'lodash';
|
|||||||
import { FilterQuery } from 'mongodb';
|
import { FilterQuery } from 'mongodb';
|
||||||
import { BUILTIN_ROLES, PRIV } from './builtin';
|
import { BUILTIN_ROLES, PRIV } from './builtin';
|
||||||
import { DomainDoc } from '../interface';
|
import { DomainDoc } from '../interface';
|
||||||
|
import { NumberKeys } from '../typeutils';
|
||||||
import * as bus from '../service/bus';
|
import * as bus from '../service/bus';
|
||||||
import db from '../service/db';
|
import db from '../service/db';
|
||||||
|
|
||||||
@@ -56,9 +57,7 @@ export async function get(domainId: string): Promise<DomainDoc | null> {
|
|||||||
export async function getByHost(host: string): Promise<DomainDoc | null> {
|
export async function getByHost(host: string): Promise<DomainDoc | null> {
|
||||||
const query: FilterQuery<DomainDoc> = { host };
|
const query: FilterQuery<DomainDoc> = { host };
|
||||||
await bus.serial('domain/before-get', query);
|
await bus.serial('domain/before-get', query);
|
||||||
console.log(query);
|
|
||||||
const result = await coll.findOne(query);
|
const result = await coll.findOne(query);
|
||||||
console.log(result);
|
|
||||||
await bus.serial('domain/get', result);
|
await bus.serial('domain/get', result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -74,7 +73,7 @@ export async function edit(domainId: string, $set: Partial<DomainDoc>) {
|
|||||||
return result.value;
|
return result.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function inc(domainId: string, field: keyof DomainDoc, n: number): Promise<number | null> {
|
export async function inc(domainId: string, field: NumberKeys<DomainDoc>, n: number): Promise<number | null> {
|
||||||
const res = await coll.findOneAndUpdate(
|
const res = await coll.findOneAndUpdate(
|
||||||
{ _id: domainId },
|
{ _id: domainId },
|
||||||
// FIXME
|
// FIXME
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ export const TYPE_REGISTRATION = 2;
|
|||||||
export const TYPE_CHANGEMAIL = 3;
|
export const TYPE_CHANGEMAIL = 3;
|
||||||
export const TYPE_OAUTH = 4;
|
export const TYPE_OAUTH = 4;
|
||||||
export const TYPE_LOSTPASS = 5;
|
export const TYPE_LOSTPASS = 5;
|
||||||
|
export const TYPE_EXPORT = 6;
|
||||||
|
|
||||||
function ensureIndexes() {
|
function ensureIndexes() {
|
||||||
return Promise.all([
|
return Promise.all([
|
||||||
|
|||||||
Reference in new issue
Block a user