mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 09:36:08 +08:00
core: remove deprecated db2 & gridfs api
This commit is contained in:
1 parent
49a60eeaa1
commit
c54c7151ff
5 files changed
+17
-16
No files matched your search
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hydrooj",
|
||||
"version": "3.4.29",
|
||||
"version": "3.4.30",
|
||||
"bin": "bin/hydrooj.js",
|
||||
"main": "src/loader",
|
||||
"module": "src/loader",
|
||||
@@ -39,7 +39,7 @@
|
||||
"minio": "7.0.25",
|
||||
"moment-timezone": "^0.5.34",
|
||||
"mongodb": "^3.7.3",
|
||||
"nanoid": "^3.2.0",
|
||||
"nanoid": "^3.3.0",
|
||||
"nodemailer": "^6.7.2",
|
||||
"notp": "^2.0.3",
|
||||
"p-queue": "^7.2.0",
|
||||
|
||||
@@ -316,7 +316,8 @@ export class ContestEditHandler extends Handler {
|
||||
|
||||
export class ContestCodeHandler extends Handler {
|
||||
@param('tid', Types.ObjectID)
|
||||
async get(domainId: string, tid: ObjectID) {
|
||||
@param('all', Types.Boolean)
|
||||
async get(domainId: string, tid: ObjectID, all: boolean) {
|
||||
await this.limitRate('contest_code', 3600, 60);
|
||||
const [tdoc, tsdocs] = await contest.getAndListStatus(domainId, tid);
|
||||
if (!this.user.own(tdoc) && !this.user.hasPriv(PRIV.PRIV_READ_RECORD_CODE)) {
|
||||
@@ -327,10 +328,18 @@ export class ContestCodeHandler extends Handler {
|
||||
}
|
||||
const rnames = {};
|
||||
for (const tsdoc of tsdocs) {
|
||||
for (const pid in tsdoc.detail || {}) {
|
||||
let name = `U${tsdoc.uid}_P${pid}_R${tsdoc.detail[pid].rid}`;
|
||||
if (typeof tsdoc.detail[pid].score === 'number') name += `_S${tsdoc.detail[pid].status}@${tsdoc.detail[pid].score}`;
|
||||
rnames[tsdoc.detail[pid].rid] = name;
|
||||
if (all) {
|
||||
for (const j of tsdoc.journal || []) {
|
||||
let name = `U${tsdoc.uid}_P${j.pid}_R${j.rid}`;
|
||||
if (typeof j.score === 'number') name += `_S${j.status || 0}@${j.score}`;
|
||||
rnames[j.rid] = name;
|
||||
}
|
||||
} else {
|
||||
for (const pid in tsdoc.detail || {}) {
|
||||
let name = `U${tsdoc.uid}_P${pid}_R${tsdoc.detail[pid].rid}`;
|
||||
if (typeof tsdoc.detail[pid].score === 'number') name += `_S${tsdoc.detail[pid].status || 0}@${tsdoc.detail[pid].score}`;
|
||||
rnames[tsdoc.detail[pid].rid] = name;
|
||||
}
|
||||
}
|
||||
}
|
||||
const zip = new AdmZip();
|
||||
|
||||
@@ -15,9 +15,7 @@ interface MongoConfig {
|
||||
|
||||
class MongoService implements BaseService {
|
||||
public client: MongoClient;
|
||||
public client2: MongoClient;
|
||||
public db: Db;
|
||||
public db2: Db;
|
||||
public started = false;
|
||||
private opts: MongoConfig;
|
||||
|
||||
@@ -25,8 +23,6 @@ class MongoService implements BaseService {
|
||||
this.opts = opts;
|
||||
this.client = await MongoClient.connect(global.__MONGO_URI__, { useNewUrlParser: true, useUnifiedTopology: true });
|
||||
this.db = this.client.db(global.__MONGO_DB_NAME_);
|
||||
this.client2 = await MongoClient.connect(global.__MONGO_URI__, { useNewUrlParser: true, useUnifiedTopology: true });
|
||||
this.db2 = this.client2.db(global.__MONGO_DB_NAME_);
|
||||
await bus.parallel('database/connect', this.db);
|
||||
this.started = true;
|
||||
}
|
||||
|
||||
@@ -21,9 +21,7 @@ interface MongoConfig {
|
||||
|
||||
class MongoService implements BaseService {
|
||||
public client: MongoClient;
|
||||
public client2: MongoClient;
|
||||
public db: Db;
|
||||
public db2: Db;
|
||||
public started = false;
|
||||
private opts: MongoConfig;
|
||||
|
||||
@@ -40,8 +38,6 @@ class MongoService implements BaseService {
|
||||
const mongourl = MongoService.buildUrl(opts);
|
||||
this.client = await MongoClient.connect(mongourl, { useNewUrlParser: true, useUnifiedTopology: true });
|
||||
this.db = this.client.db(opts.name);
|
||||
this.client2 = await MongoClient.connect(mongourl, { useNewUrlParser: true, useUnifiedTopology: true });
|
||||
this.db2 = this.client2.db(opts.name);
|
||||
await bus.parallel('database/connect', this.db);
|
||||
this.started = true;
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ const scripts: UpgradeScript[] = [
|
||||
else savedProgress = { pdocs: [] };
|
||||
const ddocs = await domain.getMulti().project({ _id: 1 }).toArray();
|
||||
logger.info('Found %d domains.', ddocs.length);
|
||||
const gridfs = new GridFSBucket(db.db2);
|
||||
const gridfs = new GridFSBucket(db.db);
|
||||
for (let i = 0; i < ddocs.length; i++) {
|
||||
const ddoc = ddocs[i];
|
||||
logger.info('Domain %s (%d/%d)', ddoc._id, i + 1, ddocs.length);
|
||||
|
||||
Reference in new issue
Block a user