Browse Source

精简依赖包

simplify_dependencies
巴林闲侠 2 years ago
parent
commit
47cd2fa5ca
  1. 30
      console/client/src/utils/hooks.js
  2. 2
      console/client/src/utils/index.js
  3. 10
      console/package.json
  4. 71
      console/routes/attachment/index.js

30
console/client/src/utils/hooks.js

@ -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,
};

2
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,
}

10
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",

71
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_);
}
};

Loading…
Cancel
Save