diff --git a/README.md b/README.md index 7401723..64819c0 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ - 🍩 **Why?** desktop software ( office direction , personal tools ), still Yes PC in the next ten years one of the requirements is to improve work efficiency - 🍉 **Simple:** just understand JavaScript - 🍑 **Vision:** all developers can learn how to develop desktop software -- 🍰 **Gitee:** https://gitee.com/wallace5303/electron-egg **2000+** +- 🍰 **Gitee:** https://gitee.com/wallace5303/electron-egg **2200+** - 🍨 **Github:** https://github.com/wallace5303/electron-egg **500+** - 🏆 most valuable open source project  diff --git a/README.zh-CN.md b/README.zh-CN.md index 1c8597c..83f940d 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -16,7 +16,7 @@ - 🍩 **为什么使用?** 桌面软件(办公方向、 个人工具),仍然是未来十几年PC端需求之一,提高工作效率 - 🍉 **简单:** 只需懂 JavaScript - 🍑 **愿景:** 所有开发者都能学会桌面软件研发 -- 🍰 **gitee:** https://gitee.com/wallace5303/electron-egg **2000+** +- 🍰 **gitee:** https://gitee.com/wallace5303/electron-egg **2200+** - 🍨 **github:** https://github.com/wallace5303/electron-egg **500+** - 🏆 码云最有价值开源项目  diff --git a/electron/config/config.default.js b/electron/config/config.default.js index 55660c7..7b39c0a 100644 --- a/electron/config/config.default.js +++ b/electron/config/config.default.js @@ -52,8 +52,8 @@ module.exports = (appInfo) => { minWidth: 800, minHeight: 650, webPreferences: { - //webSecurity: false, - contextIsolation: false, // false->可在渲染进程中使用electronApi,true->需要bridge.js(contextBridge) + //webSecurity: false, // 跨域问题 -> 打开注释 + contextIsolation: false, // false -> 可在渲染进程中使用electronApi,true->需要bridge.js(contextBridge) nodeIntegration: true, //preload: path.join(appInfo.baseDir, 'preload', 'bridge.js'), }, diff --git a/electron/controller/example.js b/electron/controller/example.js index 9e45a15..097710a 100644 --- a/electron/controller/example.js +++ b/electron/controller/example.js @@ -495,27 +495,6 @@ class ExampleController extends Controller { return; } - /** - * 上传文件 - */ - async uploadFile() { - // const self = this; - // const { ctx, service } = this; - // let tmpDir = Utils.getLogDir(); - // const file = ctx.request.files[0]; - - // try { - // 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 uploadRes = await service.example.uploadFileToSMMS(fileStream); - - // return uploadRes; - } - /** * 检测http服务是否开启 */ @@ -622,6 +601,27 @@ class ExampleController extends Controller { } } + /** + * 上传文件 + */ + async uploadFile() { + let tmpDir = Utils.getLogDir(); + const files = this.app.request.files; + let file = files.file; + + let tmpFilePath = path.join(tmpDir, file.originalFilename); + try { + let tmpFile = fs.readFileSync(file.filepath); + fs.writeFileSync(tmpFilePath, tmpFile); + } finally { + await fs.unlink(file.filepath, function(){}); + } + const fileStream = fs.createReadStream(tmpFilePath); + const uploadRes = await this.service.example.uploadFileToSMMS(fileStream); + + return uploadRes; + } + /** * 测试接口 */ diff --git a/electron/service/example.js b/electron/service/example.js index bc45ac3..8540238 100644 --- a/electron/service/example.js +++ b/electron/service/example.js @@ -23,6 +23,45 @@ class ExampleService extends Service { return obj; } + + /** + * 上传到smms + */ + async uploadFileToSMMS(tmpFile) { + const res = { + code: 1000, + message: 'unknown error', + }; + + try { + const headersObj = { + 'Content-Type': 'multipart/form-data', + 'Authorization': 'aaaaaaaaaaaaa' // 请修改这个token,用你自己的账号token + }; + const url = 'https://sm.ms/api/v2/upload'; + const response = await this.app.curl(url, { + method: 'POST', + headers: headersObj, + files: { + smfile: tmpFile, + }, + dataType: 'json', + timeout: 15000, + }); + const result = response.data; + if (this.app.config.env === 'local') { + this.app.logger.info('[ExampleService] [uploadFileToSMMS]: info result:%j', result); + } + if (result.code !== 'success') { + this.app.logger.error('[ExampleService] [uploadFileToSMMS]: res error result:%j', result); + } + return result; + } catch (e) { + this.app.logger.error('[ExampleService] [uploadFileToSMMS]: ERROR ', e); + } + + return res; + } } ExampleService.toString = () => '[class ExampleService]'; diff --git a/frontend/src/views/base/file/Index.vue b/frontend/src/views/base/file/Index.vue index fc00465..7b029ee 100644 --- a/frontend/src/views/base/file/Index.vue +++ b/frontend/src/views/base/file/Index.vue @@ -1,13 +1,5 @@ - - - - {{ item.id }}. {{ item.imageUrlText }}: - {{ item.url }} - - - 1. 系统原生对话框 @@ -38,7 +30,7 @@ - 4. 打开文件夹 + 3. 打开文件夹 @@ -52,11 +44,35 @@ + + + 4. 上传文件到图床 + + + + + + + + + 点击 或 拖拽文件到这里 + + + 注意:请使用您自己的图床token + + + diff --git a/package.json b/package.json index 0717289..c63d39d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ee", - "version": "2.2.1", + "version": "2.2.2", "description": "A fast, desktop software development framework", "main": "main.js", "scripts": {
+ +
+ 点击 或 拖拽文件到这里 +
+ 注意:请使用您自己的图床token +