From 47cd2fa5cac3ca24a9e4f8629b84da3019791d0f Mon Sep 17 00:00:00 2001 From: "gao.zhiyuan" Date: Tue, 4 Apr 2023 10:28:44 +0800 Subject: [PATCH] =?UTF-8?q?=E7=B2=BE=E7=AE=80=E4=BE=9D=E8=B5=96=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- console/client/src/utils/hooks.js | 30 ------------- console/client/src/utils/index.js | 2 - console/package.json | 10 ----- console/routes/attachment/index.js | 71 ------------------------------ 4 files changed, 113 deletions(-) delete mode 100644 console/client/src/utils/hooks.js diff --git a/console/client/src/utils/hooks.js b/console/client/src/utils/hooks.js deleted file mode 100644 index 37a7deb..0000000 --- a/console/client/src/utils/hooks.js +++ /dev/null @@ -1,30 +0,0 @@ -import React, { useEffect } from 'react'; -import { useRequest } from 'ahooks'; -import { Request } from '@peace/utils'; - -export const useFsRequest = ({ ...props }) => { - const { - method = 'get', header = null, body = {}, query = {}, root = null, url, ...rest - } = props; - return useRequest(() => { - if (method === 'post') { - return Request.post(url, body, query, root, header); - } - if (method === 'put') { - return Request.put(url, body, query, root, header); - } - if (method === 'delete') { - return Request.delete(url, query, root, header); - } - return Request.get(url, query, root, header); - }, { - loadingDelay: 500, - ...rest, - }); -}; - - - -export default { - useFsRequest, -}; diff --git a/console/client/src/utils/index.js b/console/client/src/utils/index.js index b697c96..7b60922 100644 --- a/console/client/src/utils/index.js +++ b/console/client/src/utils/index.js @@ -2,11 +2,9 @@ import { AuthorizationCode } from './authCode'; import { ApiTable, RouteTable, } from './webapi' import Func from './func'; -import { useFsRequest } from './hooks'; export { AuthorizationCode, Func, ApiTable, RouteTable, - useFsRequest, } \ No newline at end of file diff --git a/console/package.json b/console/package.json index 8940e61..5c82691 100644 --- a/console/package.json +++ b/console/package.json @@ -73,21 +73,11 @@ }, "dependencies": { "@ant-design/icons": "^4.6.2", - "@ant-design/pro-form": "^1.34.0", - "@ant-design/pro-table": "^2.48.0", - "@antv/g6": "^4.2.5", - "@fs/attachment": "^1.0.0", - "@peace/components": "0.0.35", "@peace/utils": "0.0.37", - "ahooks": "^3.7.4", - "ali-oss": "^6.17.1", "antd": "^4.24.5", "args": "^5.0.1", "cross-env": "^7.0.3", "crypto-js": "^4.1.1", - "echarts": "^5.4.1", - "echarts-for-react": "^3.0.2", - "electron-squirrel-startup": "^1.0.0", "file-saver": "^2.0.5", "fs-attachment": "^1.0.0", "fs-web-server-scaffold": "^1.0.6", diff --git a/console/routes/attachment/index.js b/console/routes/attachment/index.js index 6c1de58..43dbec0 100644 --- a/console/routes/attachment/index.js +++ b/console/routes/attachment/index.js @@ -3,8 +3,6 @@ const request = require('superagent'); const parse = require('async-busboy'); const path = require('path') const fs = require('fs'); -const OSS = require('ali-oss'); -const uuid = require('uuid'); const UploadPath = { project: ['.txt', '.dwg', '.doc', '.docx', '.xls', '.xlsx', ".csv", '.pdf', '.pptx', '.png', '.jpg', '.svg', '.rar', '.zip', '.jpeg', '.mp4'], @@ -162,78 +160,9 @@ module.exports = { } } - const uploadAliOSS = async (ctx,) => { - // 这个是上传到阿里 - try { - const { aliOss } = opts - const { p = 'default' } = ctx.params; - const { files } = await parse(ctx.req); - const file = files[0]; - const filename = file.filename || path.basename(file); - - const client = new OSS({ - // yourRegion填写Bucket所在地域.以华东1(杭州)为例,Region填写为oss-cn-hangzhou. - region: aliOss.region, - // 阿里云账号AccessKey拥有所有API的访问权限,风险很高.强烈建议您创建并使用RAM用户进行API访问或日常运维,请登录RAM控制台创建RAM用户. - accessKeyId: aliOss.accessKey, - accessKeySecret: aliOss.secretKey, - // 填写Bucket名称,例如examplebucket. - bucket: aliOss.bucket, - }); - - let uploadPath = path.posix.join(p, uuid.v4(), filename); - let result = await client.putStream( - uploadPath, - file, - // { contentLength: size } - ); - - ctx.status = 200; - ctx.body = { - key: result.name, - uploaded: result.name, - url: result.url, - }; - } catch (error) { - ctx.status = 400; - ctx.fs.logger.error(error); - ctx.body = { err: 'upload error.' }; - } - } - - const downloadFromAli = async (ctx) => { - try { - const { aliOss } = opts - const { path, filename } = ctx.query - const client = new OSS({ - // yourRegion填写Bucket所在地域.以华东1(杭州)为例,Region填写为oss-cn-hangzhou. - region: aliOss.region, - // 阿里云账号AccessKey拥有所有API的访问权限,风险很高.强烈建议您创建并使用RAM用户进行API访问或日常运维,请登录RAM控制台创建RAM用户. - accessKeyId: aliOss.accessKey, - accessKeySecret: aliOss.secretKey, - // 填写Bucket名称,例如examplebucket. - bucket: aliOss.bucket, - }); - - const filename_ = filename || path.split('/').pop() - - const result = await client.get(path); - ctx.status = 200; - ctx.set('Content-Type', 'application/x-xls'); - ctx.set('Content-disposition', 'attachment; filename=' + filename_); - ctx.body = result.content; - } catch (error) { - ctx.status = 400; - ctx.fs.logger.error(error); - ctx.body = { err: 'download error.' }; - } - } - router.use(download_); router.post('/_upload/new', upload); router.delete('/_upload/cleanup', remove); - router.post('/_upload/attachments/ali/:p', uploadAliOSS); - router.get('/_download/attachments/ali', downloadFromAli); router.post('/_upload/attachments/:p', upload_); } };