mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
feat: interface HydroFileSystem
This commit is contained in:
1 parent
a58c36961f
commit
9aedeb33b3
5 files changed
+23
-6
No files matched your search
Submodule
+1
Submodule packages/customize added at 88b1f57a84.
@@ -13,3 +13,5 @@ message.markAsRead
|
|||||||
extend problem settings
|
extend problem settings
|
||||||
+oplog
|
+oplog
|
||||||
将系统设置存于本地而非数据库
|
将系统设置存于本地而非数据库
|
||||||
|
添加nav排序功能
|
||||||
|
自动拓扑组件加载顺序?
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
import { Readable, Writable } from 'stream';
|
||||||
import { ObjectID, GridFSBucket } from 'mongodb';
|
import { ObjectID, GridFSBucket } from 'mongodb';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import { Dictionary, NumericDictionary } from 'lodash';
|
import { Dictionary, NumericDictionary } from 'lodash';
|
||||||
@@ -433,6 +434,17 @@ export interface Task {
|
|||||||
[key: string]: any
|
[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 type PathComponent = [string, string, Dictionary<any>?, boolean?];
|
||||||
|
|
||||||
export interface Collections {
|
export interface Collections {
|
||||||
@@ -483,7 +495,7 @@ export interface Model {
|
|||||||
export interface Service {
|
export interface Service {
|
||||||
bus: typeof import('./service/bus'),
|
bus: typeof import('./service/bus'),
|
||||||
db: typeof import('./service/db'),
|
db: typeof import('./service/db'),
|
||||||
gridfs: GridFSBucket,
|
fs: HydroFileSystem,
|
||||||
monitor: typeof import('./service/monitor'),
|
monitor: typeof import('./service/monitor'),
|
||||||
server: typeof import('./service/server'),
|
server: typeof import('./service/server'),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ export async function add(
|
|||||||
const w = gridfs.openUploadStream(filename);
|
const w = gridfs.openUploadStream(filename);
|
||||||
await coll.insertOne({
|
await coll.insertOne({
|
||||||
...meta,
|
...meta,
|
||||||
_id: w.id as ObjectID,
|
_id: w.id,
|
||||||
secret: String.random(32),
|
secret: String.random(32),
|
||||||
owner,
|
owner,
|
||||||
filename,
|
filename,
|
||||||
@@ -37,8 +37,8 @@ export async function add(
|
|||||||
stream.pipe(w);
|
stream.pipe(w);
|
||||||
});
|
});
|
||||||
const c = await gridfs.find({ _id: w.id }).toArray();
|
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 } });
|
await coll.updateOne({ _id: w.id }, { $set: { md5: c[0].md5, size: c[0].length } });
|
||||||
return w.id as ObjectID;
|
return w.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function del(_id: ObjectID) {
|
export function del(_id: ObjectID) {
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
import { GridFSBucket } from 'mongodb';
|
import { GridFSBucket } from 'mongodb';
|
||||||
import { db2 } from './db';
|
import { db2 } from './db';
|
||||||
|
import { HydroFileSystem } from '../interface';
|
||||||
|
|
||||||
const fs = new GridFSBucket(db2);
|
const fs = new GridFSBucket(db2);
|
||||||
|
|
||||||
global.Hydro.service.gridfs = fs;
|
// @ts-ignore
|
||||||
|
global.Hydro.service.fs = fs;
|
||||||
|
|
||||||
export = fs;
|
export = fs as HydroFileSystem;
|
||||||
Reference in new issue
Block a user