operationManualService.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. 'use strict';
  2. const fs = require('fs');
  3. // node.js 路径操作对象
  4. const path = require('path');
  5. const Service = require('../service/baseService');
  6. class OperationManualService extends Service {
  7. tag() {
  8. return this.ctx.model.OperationManualModel;
  9. }
  10. // 上传前先删除原有文件
  11. async upload(query) {
  12. const { service } = this;
  13. const { id } = query;
  14. if (id) {
  15. const oneFile = await this.one(id);
  16. // if (oneFile.filePath && oneFile.filePath !== '') {
  17. // // 同步删除 unlinkSync (异步 : unlink)
  18. // const dicPath = path.join(this.app.config.defaultWriteAliOSSPath, oneFile.fileName);
  19. // // if (fs.existsSync(dicPath)) {
  20. // // fs.unlinkSync(dicPath);
  21. // // }
  22. // if (this.ctx.oss.delete(dicPath)) {
  23. // this.ctx.oss.delete(dicPath);
  24. // }
  25. // }
  26. // TODO 修改成OSS -CH (已完成)
  27. const url = await service.imageHandleService.uploadOperationManual(oneFile.fileName);
  28. if (url) {
  29. const data = {};
  30. data.filePath = url;
  31. data.time = Date.now();
  32. return await this.update(id, data);
  33. }
  34. }
  35. return null;
  36. }
  37. }
  38. module.exports = OperationManualService;