|
|
@@ -1,6 +1,6 @@
|
|
|
'use strict';
|
|
|
|
|
|
-const BaseController = require('../base');
|
|
|
+const BaseController = require('../base');
|
|
|
const os = require('os');
|
|
|
const fs = require('fs');
|
|
|
const path = require('path');
|
|
|
@@ -20,13 +20,13 @@ class ExampleController extends BaseController {
|
|
|
break;
|
|
|
case 'picture' :
|
|
|
dir = os.userInfo().homedir + '/Pictures';
|
|
|
- break;
|
|
|
+ break;
|
|
|
case 'doc' :
|
|
|
dir = os.userInfo().homedir + '/Documents';
|
|
|
- break;
|
|
|
+ break;
|
|
|
case 'music' :
|
|
|
dir = os.userInfo().homedir + '/Music';
|
|
|
- break;
|
|
|
+ break;
|
|
|
}
|
|
|
|
|
|
await service.example.openLocalDir(dir);
|
|
|
@@ -34,6 +34,15 @@ class ExampleController extends BaseController {
|
|
|
self.sendSuccess(data);
|
|
|
}
|
|
|
|
|
|
+ async executeJS() {
|
|
|
+ const self = this;
|
|
|
+ const { ctx, service } = this;
|
|
|
+ const body = ctx.request.body;
|
|
|
+ const str = body.str;
|
|
|
+ let data = await service.example.executeJS(str);
|
|
|
+ self.sendSuccess(data);
|
|
|
+ }
|
|
|
+
|
|
|
async uploadFile() {
|
|
|
const self = this;
|
|
|
const { ctx, service } = this;
|
|
|
@@ -42,24 +51,24 @@ class ExampleController extends BaseController {
|
|
|
// this.app.logger.info('file:', file);
|
|
|
|
|
|
// try {
|
|
|
- // let tmpFile = fs.readFileSync(file.filepath)
|
|
|
+ // let tmpFile = fs.readFileSync(file.filepath)
|
|
|
// fs.writeFileSync(path.join(tmpDir, file.filename), tmpFile)
|
|
|
// } finally {
|
|
|
// await fs.unlink(file.filepath, function(){});
|
|
|
// }
|
|
|
- // const fileStream = fs.createReadStream(path.join(tmpDir, file.filename))
|
|
|
+ // const fileStream = fs.createReadStream(path.join(tmpDir, file.filename))
|
|
|
// const uploadRes = await service.example.uploadFileToSMMS(fileStream);
|
|
|
// }
|
|
|
const file = ctx.request.files[0];
|
|
|
//this.app.logger.info('file:', file);
|
|
|
|
|
|
try {
|
|
|
- let tmpFile = fs.readFileSync(file.filepath)
|
|
|
+ let tmpFile = fs.readFileSync(file.filepath)
|
|
|
fs.writeFileSync(path.join(tmpDir, file.filename), tmpFile)
|
|
|
} finally {
|
|
|
await fs.unlink(file.filepath, function(){});
|
|
|
}
|
|
|
- const fileStream = fs.createReadStream(path.join(tmpDir, file.filename))
|
|
|
+ const fileStream = fs.createReadStream(path.join(tmpDir, file.filename))
|
|
|
const uploadRes = await service.example.uploadFileToSMMS(fileStream);
|
|
|
|
|
|
self.sendData(uploadRes);
|