feat: interface HydroFileSystem

This commit is contained in:
undefined committed 2020-09-27 23:02:33 +08:00
1 parent a58c36961f
commit 9aedeb33b3
5 files changed
+24 -7

No files matched your search

Submodule packages/customize added at 88b1f57a84.
+3 -1
View File
@@ -12,4 +12,6 @@ message.markAsRead
存储系统抽象化
extend problem settings
+oplog
将系统设置存于本地而非数据库
将系统设置存于本地而非数据库
添加nav排序功能
自动拓扑组件加载顺序?
+13 -1
View File
@@ -1,4 +1,5 @@
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import { Readable, Writable } from 'stream';
import { ObjectID, GridFSBucket } from 'mongodb';
import fs from 'fs';
import { Dictionary, NumericDictionary } from 'lodash';
@@ -433,6 +434,17 @@ export interface Task {
[key: string]: any
}
export interface UploadStream extends Writable {
id: ObjectID
}
export interface HydroFileSystem {
openUploadStream: (filename: string) => UploadStream
openDownloadStream: (_id: ObjectID) => Readable
// TODO
find: (...args: any[]) => any
}
export type PathComponent = [string, string, Dictionary<any>?, boolean?];
export interface Collections {
@@ -483,7 +495,7 @@ export interface Model {
export interface Service {
bus: typeof import('./service/bus'),
db: typeof import('./service/db'),
gridfs: GridFSBucket,
fs: HydroFileSystem,
monitor: typeof import('./service/monitor'),
server: typeof import('./service/server'),
}
+3 -3
View File
@@ -26,7 +26,7 @@ export async function add(
const w = gridfs.openUploadStream(filename);
await coll.insertOne({
...meta,
_id: w.id as ObjectID,
_id: w.id,
secret: String.random(32),
owner,
filename,
@@ -37,8 +37,8 @@ export async function add(
stream.pipe(w);
});
const c = await gridfs.find({ _id: w.id }).toArray();
await coll.updateOne({ _id: w.id as ObjectID }, { $set: { md5: c[0].md5, size: c[0].length } });
return w.id as ObjectID;
await coll.updateOne({ _id: w.id }, { $set: { md5: c[0].md5, size: c[0].length } });
return w.id;
}
export function del(_id: ObjectID) {
+4 -2
View File
@@ -1,8 +1,10 @@
import { GridFSBucket } from 'mongodb';
import { db2 } from './db';
import { HydroFileSystem } from '../interface';
const fs = new GridFSBucket(db2);
global.Hydro.service.gridfs = fs;
// @ts-ignore
global.Hydro.service.fs = fs;
export = fs;
export = fs as HydroFileSystem;