123456789101112131415161718192021222324252627282930313233343536373839404142 |
- 'use strict';
- const fs = require('fs');
- // node.js 路径操作对象
- const path = require('path');
- const Service = require('../service/baseService');
- class OperationManualService extends Service {
- tag() {
- return this.ctx.model.OperationManualModel;
- }
- // 上传前先删除原有文件
- async upload(query) {
- const { service } = this;
- const { id } = query;
- if (id) {
- const oneFile = await this.one(id);
- // if (oneFile.filePath && oneFile.filePath !== '') {
- // // 同步删除 unlinkSync (异步 : unlink)
- // const dicPath = path.join(this.app.config.defaultWriteAliOSSPath, oneFile.fileName);
- // // if (fs.existsSync(dicPath)) {
- // // fs.unlinkSync(dicPath);
- // // }
- // if (this.ctx.oss.delete(dicPath)) {
- // this.ctx.oss.delete(dicPath);
- // }
- // }
- // TODO 修改成OSS -CH (已完成)
- const url = await service.imageHandleService.uploadOperationManual(oneFile.fileName);
- if (url) {
- const data = {};
- data.filePath = url;
- data.time = Date.now();
- return await this.update(id, data);
- }
- }
- return null;
- }
- }
- module.exports = OperationManualService;
|