feat: file relate kb

This commit is contained in:
archer
2023-09-04 10:51:57 +08:00
parent a3c6d6800b
commit 44e772f0fd
7 changed files with 50 additions and 26 deletions

View File

@@ -79,7 +79,7 @@ export class GridFSStorage {
return Promise.reject(`file not found`);
}
if (String(file.metadata?.userId) !== this.uid) {
if (file.metadata?.userId !== this.uid) {
return Promise.reject(ERROR_ENUM.unAuthFile);
}
@@ -100,6 +100,16 @@ export class GridFSStorage {
return true;
}
async deleteFilesByKbId(kbId: string) {
if (!kbId) return;
const bucket = this.GridFSBucket();
const files = await bucket
.find({ ['metadata.kbId']: kbId, ['metadata.userId']: this.uid }, { projection: { _id: 1 } })
.toArray();
return Promise.all(files.map((file) => this.delete(String(file._id))));
}
async download(id: string) {
await this.findAndAuthFile(id);