From 9428efb156883360dd974f789130ea4bad058c5e Mon Sep 17 00:00:00 2001 From: undefined Date: Wed, 15 Jul 2020 22:10:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=BAmodel.file=E6=B7=BB=E5=8A=A0=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hydro/model/file.ts | 18 ++++++++++++++---- hydro/script/recalcRating.ts | 4 ++-- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/hydro/model/file.ts b/hydro/model/file.ts index e267821f..a781c541 100644 --- a/hydro/model/file.ts +++ b/hydro/model/file.ts @@ -69,7 +69,7 @@ export async function dec(_id: ObjectID): Promise { return file.value.count; } -export async function getWithSecret(_id: ObjectID, secret: string) { +export async function getWithSecret(_id: ObjectID, secret: string, reject?: Function) { const file = await coll.findOne({ _id }); if (!file) throw new NotFoundError(_id); const timestamp = _timestamp(); @@ -78,13 +78,23 @@ export async function getWithSecret(_id: ObjectID, secret: string) { throw new ForbiddenError(); } } - return gridfs.openDownloadStream(_id); + const stream = gridfs.openDownloadStream(_id); + stream.on('error', (err) => { + console.error(err); + if (reject) reject(); + }); + return stream; } -export async function get(_id: ObjectID) { +export async function get(_id: ObjectID, reject?: Function) { const file = await coll.findOne({ _id }); if (!file) throw new NotFoundError(_id); - return gridfs.openDownloadStream(_id); + const stream = gridfs.openDownloadStream(_id); + stream.on('error', (err) => { + console.error(err); + if (reject) reject(); + }); + return stream; } export function getMeta(_id: ObjectID): Promise { diff --git a/hydro/script/recalcRating.ts b/hydro/script/recalcRating.ts index dc0926ce..e4a03c31 100644 --- a/hydro/script/recalcRating.ts +++ b/hydro/script/recalcRating.ts @@ -6,7 +6,7 @@ import { STATUS } from '../model/builtin'; export const description = 'Calculate rating of a domain, or all domains'; -export async function run({ domainId, isSub = false }, report) { +export async function run({ domainId, isSub = false }, report: Function) { if (!domainId) { const domains = await domain.getMulti().toArray(); await report({ message: `Found ${domains.length} domains` }); @@ -16,7 +16,7 @@ export async function run({ domainId, isSub = false }, report) { await report({ case: { status: STATUS.STATUS_ACCEPTED, - judgeText: `Domain ${i} finished`, + judgeText: `Domain ${domains[i]._id} finished`, time_ms: new Date().getTime() - start, memory_kb: 0, score: 0,