|
@@ -25,7 +25,7 @@ class FilesService extends Service {
|
|
|
assert(id, 'id不存在');
|
|
|
const { Files: model } = this.ctx.model;
|
|
|
try {
|
|
|
- await model.findByIdAndUpdate(id, { name, path });
|
|
|
+ await model.findById(id).update({ name, path });
|
|
|
return { errmsg: '', errcode: 0 };
|
|
|
} catch (error) {
|
|
|
throw new Error({ errcode: -2001, errmsg: '修改失败' });
|
|
@@ -37,9 +37,9 @@ class FilesService extends Service {
|
|
|
try {
|
|
|
// 获取文件路径
|
|
|
const files = await model.findById(id);
|
|
|
- const filepath = `${files.path}`;
|
|
|
+ const filepath = `${this.app.config.filespath}${files.path}`;
|
|
|
// 开始删除文件
|
|
|
- fs.unlinkSync(path.join(this.app.baseDir, `/app${filepath}`));
|
|
|
+ fs.unlinkSync(path.join(filepath));
|
|
|
await model.findById(id).remove();
|
|
|
return { errmsg: '', errcode: 0 };
|
|
|
} catch (error) {
|
|
@@ -74,8 +74,8 @@ class FilesService extends Service {
|
|
|
const index = filename.indexOf('.');
|
|
|
const fileType = filename.slice(index, filename.length);
|
|
|
const uuid = uuidv1();
|
|
|
- const filepath = `${this.app.config.filespath}${type === 'files' ? 'files' : 'resource'}/${uuid}${fileType}`;
|
|
|
- const paths = path.join(filepath);
|
|
|
+ const filepath = `/filespath/${type === 'files' ? 'files' : 'resource'}/${uuid}${fileType}`;
|
|
|
+ const paths = path.join(`${this.app.config.filespath}${filepath}`);
|
|
|
// 存储
|
|
|
const result = await new Promise((resolve, reject) => {
|
|
|
const remoteFileStream = fs.createWriteStream(paths);
|