mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
bug fix
This commit is contained in:
1 parent
63bf550311
commit
d9f13feade
17 files changed
+54
-34
No files matched your search
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hydrooj",
|
||||
"version": "2.32.13",
|
||||
"version": "2.32.14",
|
||||
"bin": "bin/hydrooj.js",
|
||||
"main": "src/loader",
|
||||
"module": "src/loader",
|
||||
|
||||
@@ -89,7 +89,7 @@ export async function add(
|
||||
};
|
||||
await bus.serial('discussion/before-add', payload);
|
||||
const res = await document.add(
|
||||
payload.domainId, payload.content, payload.owner, document.TYPE_DISCUSSION,
|
||||
payload.domainId!, payload.content!, payload.owner!, document.TYPE_DISCUSSION,
|
||||
null, payload.parentType, payload.parentId, omit(payload, ['domainId', 'content', 'owner', 'parentType', 'parentId']),
|
||||
);
|
||||
payload.docId = res;
|
||||
|
||||
@@ -63,7 +63,7 @@ class DomainModel {
|
||||
const query: FilterQuery<DomainDoc> = { lower: domainId.toLowerCase() };
|
||||
await bus.serial('domain/before-get', query);
|
||||
const result = await coll.findOne(query);
|
||||
await bus.serial('domain/get', result);
|
||||
if (result) await bus.serial('domain/get', result);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ class DomainModel {
|
||||
const query: FilterQuery<DomainDoc> = { host };
|
||||
await bus.serial('domain/before-get', query);
|
||||
const result = await coll.findOne(query);
|
||||
await bus.serial('domain/get', result);
|
||||
if (result) await bus.serial('domain/get', result);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ class DomainModel {
|
||||
static async edit(domainId: string, $set: Partial<DomainDoc>) {
|
||||
await bus.serial('domain/before-update', domainId, $set);
|
||||
const result = await coll.findOneAndUpdate({ _id: domainId }, { $set }, { returnDocument: 'after' });
|
||||
await bus.serial('domain/update', domainId, $set, result.value);
|
||||
if (result.value) await bus.serial('domain/update', domainId, $set, result.value);
|
||||
return result.value;
|
||||
}
|
||||
|
||||
@@ -96,12 +96,12 @@ class DomainModel {
|
||||
{ $inc: { [field]: n } },
|
||||
{ returnDocument: 'after' },
|
||||
);
|
||||
return res.value[field];
|
||||
return res.value?.[field];
|
||||
}
|
||||
|
||||
@ArgMethod
|
||||
static async getList(domainIds: string[]): Promise<Dictionary<DomainDoc>> {
|
||||
const r = {};
|
||||
static async getList(domainIds: string[]) {
|
||||
const r: Record<string, DomainDoc | null> = {};
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
for (const domainId of domainIds) r[domainId] = await DomainModel.get(domainId);
|
||||
return r;
|
||||
|
||||
@@ -48,7 +48,7 @@ class MessageModel {
|
||||
{ $bit: { flag: { xor: flag } } },
|
||||
{ returnDocument: 'after' },
|
||||
);
|
||||
return result.value;
|
||||
return result.value || null;
|
||||
}
|
||||
|
||||
static async del(_id: ObjectID) {
|
||||
|
||||
@@ -21,7 +21,7 @@ class OauthModel {
|
||||
{ $set: { value } },
|
||||
{ upsert: true, returnDocument: 'after' },
|
||||
);
|
||||
return res.value.uid;
|
||||
return res.value?.uid;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,14 +3,15 @@ import {
|
||||
PushOperator, MatchKeysAndValues, OnlyFieldsOfType,
|
||||
FilterQuery,
|
||||
} from 'mongodb';
|
||||
import { sum } from 'lodash';
|
||||
import { omit, sum } from 'lodash';
|
||||
import moment from 'moment';
|
||||
import { STATUS } from './builtin';
|
||||
import task from './task';
|
||||
import problem from './problem';
|
||||
import {
|
||||
RecordDoc, ContestInfo, ProblemConfigFile, ExternalProblemId,
|
||||
RecordDoc, ContestInfo, ProblemConfigFile, ExternalProblemId, FileInfo,
|
||||
} from '../interface';
|
||||
import { ProblemNotFoundError } from '../error';
|
||||
import { ArgMethod, buildProjection, Time } from '../utils';
|
||||
import { MaybeArray } from '../typeutils';
|
||||
import * as bus from '../service/bus';
|
||||
@@ -34,7 +35,7 @@ class RecordModel {
|
||||
|
||||
static async get(_id: ObjectID): Promise<RecordDoc | null>
|
||||
static async get(domainId: string, _id: ObjectID): Promise<RecordDoc | null>
|
||||
static async get(arg0, arg1?) {
|
||||
static async get(arg0: string | ObjectID, arg1?: any) {
|
||||
const _id = arg1 || arg0;
|
||||
const domainId = arg1 ? arg0 : null;
|
||||
const res = await RecordModel.coll.findOne({ _id });
|
||||
@@ -61,15 +62,16 @@ class RecordModel {
|
||||
|
||||
static async judge(domainId: string, rid: ObjectID, priority = 0, config: ProblemConfigFile = {}) {
|
||||
const rdoc = await RecordModel.get(domainId, rid);
|
||||
let data = [];
|
||||
delete rdoc._id;
|
||||
if (!rdoc) return null;
|
||||
let data: FileInfo[] = [];
|
||||
if (rdoc.pid) {
|
||||
const pdoc = await problem.get(rdoc.pdomain, rdoc.pid);
|
||||
if (!pdoc) throw new ProblemNotFoundError(rdoc?.pdomain, rdoc.pid);
|
||||
data = pdoc.data;
|
||||
if (typeof pdoc.config === 'string') throw new Error(); // Just for typings. This won't happen.
|
||||
if (typeof pdoc.config === 'string') throw new Error(pdoc.config);
|
||||
if (pdoc.config.type === 'remote_judge') {
|
||||
return await task.add({
|
||||
...rdoc,
|
||||
...omit(rdoc, ['_id']),
|
||||
priority,
|
||||
type: 'remotejudge',
|
||||
subType: pdoc.config.subType,
|
||||
@@ -82,7 +84,7 @@ class RecordModel {
|
||||
}
|
||||
}
|
||||
return await task.add({
|
||||
...rdoc,
|
||||
...omit(rdoc, ['_id']),
|
||||
priority,
|
||||
type: 'judge',
|
||||
rid,
|
||||
@@ -162,7 +164,7 @@ class RecordModel {
|
||||
$update,
|
||||
{ returnDocument: 'after' },
|
||||
);
|
||||
return res.value;
|
||||
return res.value || null;
|
||||
}
|
||||
return await RecordModel.get(domainId, _id);
|
||||
}
|
||||
@@ -204,14 +206,13 @@ class RecordModel {
|
||||
static async getList(
|
||||
domainId: string, rids: ObjectID[], showHidden: boolean, fields?: (keyof RecordDoc)[],
|
||||
): Promise<Record<string, Partial<RecordDoc>>> {
|
||||
const r = {};
|
||||
const r: Record<string, RecordDoc> = {};
|
||||
rids = Array.from(new Set(rids));
|
||||
let cursor = RecordModel.coll.find({ domainId, _id: { $in: rids } });
|
||||
if (fields) cursor = cursor.project(buildProjection(fields));
|
||||
const rdocs = await cursor.toArray();
|
||||
for (const rdoc of rdocs) {
|
||||
if (rdoc.hidden && !showHidden) r[rdoc._id.toHexString()] = null;
|
||||
else r[rdoc._id.toHexString()] = rdoc;
|
||||
if (!rdoc.hidden || showHidden) r[rdoc._id.toHexString()] = rdoc;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -868,6 +868,7 @@ let started = false;
|
||||
export function start() {
|
||||
if (started) return;
|
||||
const port = system.get('server.port');
|
||||
router.all('domain_main_redirect', '/d/:domain', (ctx) => ctx.redirect(`/d/${ctx.params.domain}/`));
|
||||
app.use(router.routes()).use(router.allowedMethods());
|
||||
server.listen(argv.options.port || port);
|
||||
logger.success('Server listening at: %d', argv.options.port || port);
|
||||
|
||||
@@ -193,7 +193,7 @@ class StorageService {
|
||||
async signDownloadLink(target: string, filename?: string, noExpire = false, useAlternativeEndpointFor?: 'user' | 'judge'): Promise<string> {
|
||||
if (target.includes('..') || target.includes('//')) throw new Error('Invalid path');
|
||||
try {
|
||||
const headers = {};
|
||||
const headers: Record<string, string> = {};
|
||||
if (filename) headers['response-content-disposition'] = `attachment; filename="${encodeRFC5987ValueChars(filename)}"`;
|
||||
if (/\.(jpe?g|png|gif)$/i.test(target)) headers['cache-control'] = 'max-age=604800';
|
||||
const url = await this.client.presignedGetObject(
|
||||
@@ -209,6 +209,19 @@ class StorageService {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
async signUpload(target: string, size: number) {
|
||||
const policy = this.client.newPostPolicy();
|
||||
policy.setBucket(this.opts.bucket);
|
||||
policy.setKey(target);
|
||||
policy.setExpires(new Date(Date.now() + 30 * 60 * 1000));
|
||||
if (size) policy.setContentLengthRange(size - 50, size + 50);
|
||||
const policyResult = await this.client.presignedPostPolicy(policy);
|
||||
return {
|
||||
url: this.replaceWithAlternativeUrlFor.user(policyResult.postURL),
|
||||
extraFormData: policyResult.formData,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
const service = new StorageService();
|
||||
|
||||
Reference in new issue
Block a user