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