|
@@ -18,7 +18,7 @@ class FilesService extends Service {
|
|
|
await model.create({ name, path, type, createAt });
|
|
|
return { errmsg: '', errcode: 0 };
|
|
|
} catch (error) {
|
|
|
- throw new Error({ errcode: -2001, errmsg: '添加失败' });
|
|
|
+ throw new Error('添加失败');
|
|
|
}
|
|
|
}
|
|
|
async update({ name, path, id }) {
|
|
@@ -28,7 +28,7 @@ class FilesService extends Service {
|
|
|
await model.findById(id).update({ name, path });
|
|
|
return { errmsg: '', errcode: 0 };
|
|
|
} catch (error) {
|
|
|
- throw new Error({ errcode: -2001, errmsg: '修改失败' });
|
|
|
+ throw new Error('修改失败');
|
|
|
}
|
|
|
}
|
|
|
async del({ id }) {
|
|
@@ -43,7 +43,7 @@ class FilesService extends Service {
|
|
|
await model.findById(id).remove();
|
|
|
return { errmsg: '', errcode: 0 };
|
|
|
} catch (error) {
|
|
|
- throw new Error({ errcode: -2001, errmsg: '删除失败' });
|
|
|
+ throw new Error('删除失败');
|
|
|
}
|
|
|
}
|
|
|
async query({ skip, limit, type, name }) {
|
|
@@ -62,7 +62,7 @@ class FilesService extends Service {
|
|
|
}
|
|
|
return { errmsg: '', errcode: 0, data: res, total: total.length };
|
|
|
} catch (error) {
|
|
|
- throw new Error({ errcode: -2001, errmsg: '查询失败' });
|
|
|
+ throw new Error('查询失败');
|
|
|
}
|
|
|
}
|
|
|
async upload() {
|
|
@@ -74,11 +74,11 @@ class FilesService extends Service {
|
|
|
const index = filename.indexOf('.');
|
|
|
const fileType = filename.slice(index, filename.length);
|
|
|
const uuid = uuidv1();
|
|
|
- const filepath = `/filespath/${type === 'files' ? 'files' : 'resource'}/${uuid}${fileType}`;
|
|
|
- const paths = path.join(`${this.app.config.filespath}${filepath}`);
|
|
|
+ // const filepath = `/filespath/${type === 'files' ? 'files' : 'resource'}/${uuid}${fileType}`;
|
|
|
+ // const paths = path.join(`${this.app.config.filespath}${filepath}`);
|
|
|
|
|
|
- // const filepath = `/public/${type === 'files' ? 'files' : 'resource'}/${uuid}${fileType}`;
|
|
|
- // const paths = path.join(this.app.baseDir, `/app${filepath}`);
|
|
|
+ const filepath = `/public/${type === 'files' ? 'files' : 'resource'}/${uuid}${fileType}`;
|
|
|
+ const paths = path.join(this.app.baseDir, `/app${filepath}`);
|
|
|
// 存储
|
|
|
const result = await new Promise((resolve, reject) => {
|
|
|
const remoteFileStream = fs.createWriteStream(paths);
|
|
@@ -97,12 +97,12 @@ class FilesService extends Service {
|
|
|
});
|
|
|
});
|
|
|
if (!result) {
|
|
|
- throw new Error({ errcode: -2001, errmsg: '上传失败' });
|
|
|
+ throw new Error('上传失败');
|
|
|
}
|
|
|
await this.ctx.service.files.create({ name: filename, path: filepath, type });
|
|
|
return { errmsg: '', errcode: 0, data: { name: filename, path: filepath } };
|
|
|
} catch (error) {
|
|
|
- throw new Error({ errcode: -2001, errmsg: '上传失败' });
|
|
|
+ throw new Error('上传失败');
|
|
|
}
|
|
|
}
|
|
|
}
|