mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
为model.file添加错误处理
This commit is contained in:
1 parent
8f6968bbbd
commit
9428efb156
2 files changed
+16
-6
No files matched your search
+14
-4
@@ -69,7 +69,7 @@ export async function dec(_id: ObjectID): Promise<number> {
|
|||||||
return file.value.count;
|
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 });
|
const file = await coll.findOne({ _id });
|
||||||
if (!file) throw new NotFoundError(_id);
|
if (!file) throw new NotFoundError(_id);
|
||||||
const timestamp = _timestamp();
|
const timestamp = _timestamp();
|
||||||
@@ -78,13 +78,23 @@ export async function getWithSecret(_id: ObjectID, secret: string) {
|
|||||||
throw new ForbiddenError();
|
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 });
|
const file = await coll.findOne({ _id });
|
||||||
if (!file) throw new NotFoundError(_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<Ufdoc> {
|
export function getMeta(_id: ObjectID): Promise<Ufdoc> {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { STATUS } from '../model/builtin';
|
|||||||
|
|
||||||
export const description = 'Calculate rating of a domain, or all domains';
|
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) {
|
if (!domainId) {
|
||||||
const domains = await domain.getMulti().toArray();
|
const domains = await domain.getMulti().toArray();
|
||||||
await report({ message: `Found ${domains.length} domains` });
|
await report({ message: `Found ${domains.length} domains` });
|
||||||
@@ -16,7 +16,7 @@ export async function run({ domainId, isSub = false }, report) {
|
|||||||
await report({
|
await report({
|
||||||
case: {
|
case: {
|
||||||
status: STATUS.STATUS_ACCEPTED,
|
status: STATUS.STATUS_ACCEPTED,
|
||||||
judgeText: `Domain ${i} finished`,
|
judgeText: `Domain ${domains[i]._id} finished`,
|
||||||
time_ms: new Date().getTime() - start,
|
time_ms: new Date().getTime() - start,
|
||||||
memory_kb: 0,
|
memory_kb: 0,
|
||||||
score: 0,
|
score: 0,
|
||||||
|
|||||||
Reference in new issue
Block a user