|
@@ -64,12 +64,16 @@ class FilestoreService extends Service {
|
|
|
throw error;
|
|
|
}
|
|
|
}
|
|
|
- async query({ skip, limit, filter }) {
|
|
|
+ async query({ skip, limit, fileName, name }) {
|
|
|
try {
|
|
|
+ const filter = {};
|
|
|
+ if (name || fileName) filter.$or = [];
|
|
|
+ if (fileName) filter.$or.push({ code: { $regex: fileName } });
|
|
|
+ if (name) filter.$or.push({ name: { $regex: name } });
|
|
|
let res;
|
|
|
const total = await this.model.find({ ...filter });
|
|
|
if (skip && limit) {
|
|
|
- res = await this.model.find({ ...filter }).skip(skip * limit);
|
|
|
+ res = await this.model.find({ ...filter }).skip(Number(skip) * Number(limit)).limit(Number(limit));
|
|
|
} else {
|
|
|
res = await this.model.find({ ...filter });
|
|
|
}
|
|
@@ -78,6 +82,16 @@ class FilestoreService extends Service {
|
|
|
throw error;
|
|
|
}
|
|
|
}
|
|
|
+ // 文件下载
|
|
|
+ async filesDownload({ filePath }) {
|
|
|
+ const rootPath = `${this.app.config.root_path}`;
|
|
|
+ const res = await this.model.findOne({ filePath });
|
|
|
+ const url = `${rootPath}${filePath}`;
|
|
|
+ const postfix = url.split('.')[1];
|
|
|
+ this.ctx.attachment(`${res.name}.${postfix}`);
|
|
|
+ // this.ctx.set('Content-Type', 'application/octet-stream');
|
|
|
+ return fs.createReadStream(url);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
module.exports = FilestoreService;
|