#68 hotfix: 去除aliyun-oss的全局依赖,改为props调用

Sloučený
AdamFu sloučil 3 revizí z větve Roxas/comment_component:hotfix/ali-oss do větve master před před 4 roky

+ 1
- 1
lib/components/AudioPlayer/index.js.map
Diff nebyl zobrazen, protože je příliš veliký
Zobrazit soubor


+ 1
- 34
lib/components/Editor/Upload.js Zobrazit soubor

@@ -40,14 +40,6 @@ var _react = require("react");
40 40
 
41 41
 var _react2 = _interopRequireDefault(_react);
42 42
 
43
-var _dayjs = require("dayjs");
44
-
45
-var _dayjs2 = _interopRequireDefault(_dayjs);
46
-
47
-var _shortid = require("shortid");
48
-
49
-var _shortid2 = _interopRequireDefault(_shortid);
50
-
51 43
 var _reactIntlUniversal = require("react-intl-universal");
52 44
 
53 45
 var _reactIntlUniversal2 = _interopRequireDefault(_reactIntlUniversal);
@@ -68,31 +60,6 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen
68 60
 
69 61
 function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
70 62
 
71
-var client = function client(oss) {
72
-  return new window.OSS.Wrapper({
73
-    accessKeyId: oss.access_key_id,
74
-    accessKeySecret: oss.access_key_secret,
75
-    stsToken: oss.security_token,
76
-    endpoint: _constant.OSS_ENDPOINT, //常量,你可以自己定义
77
-    bucket: _constant.OSS_BUCKET
78
-  });
79
-};
80
-
81
-var uploadPath = function uploadPath(path, file) {
82
-  return path + "/" + (0, _dayjs2.default)().format("YYYYMMDD") + "/" + _shortid2.default.generate() + "." + file.type.split("/")[1];
83
-};
84
-
85
-var UploadToOss = function UploadToOss(oss, path, file) {
86
-  var url = uploadPath(path, file);
87
-  return new Promise(function (resolve, reject) {
88
-    client(oss).multipartUpload(url, file).then(function (data) {
89
-      resolve(data);
90
-    }).catch(function (error) {
91
-      reject(error);
92
-    });
93
-  });
94
-};
95
-
96 63
 var App = function (_React$Component) {
97 64
   _inherits(App, _React$Component);
98 65
 
@@ -163,7 +130,7 @@ var App = function (_React$Component) {
163 130
       reader.onloadend = function () {
164 131
         info.onProgress({ percent: 20 });
165 132
         // DRIVER_LICENSE_PATH oss 的存储路径位置
166
-        UploadToOss(_this2.props.app.oss, _constant.DRIVER_LICENSE_PATH, file).then(function (data) {
133
+        _this2.props.app.UploadToOss(_this2.props.app.oss, _constant.DRIVER_LICENSE_PATH, file).then(function (data) {
167 134
           info.onProgress({ percent: 100 });
168 135
           info.onSuccess(data);
169 136
           _this2.props.onUpload({ path: data.name, uid: file.uid });

+ 1
- 1
lib/components/Editor/Upload.js.map
Diff nebyl zobrazen, protože je příliš veliký
Zobrazit soubor


+ 1
- 35
lib/components/Editor/index.js Zobrazit soubor

@@ -36,14 +36,6 @@ require("antd/es/message/style");
36 36
 
37 37
 require("antd/es/input/style");
38 38
 
39
-var _dayjs = require("dayjs");
40
-
41
-var _dayjs2 = _interopRequireDefault(_dayjs);
42
-
43
-var _shortid = require("shortid");
44
-
45
-var _shortid2 = _interopRequireDefault(_shortid);
46
-
47 39
 var _propTypes = require("prop-types");
48 40
 
49 41
 var _propTypes2 = _interopRequireDefault(_propTypes);
@@ -90,32 +82,6 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function"
90 82
 
91 83
 var TextArea = _input2.default.TextArea;
92 84
 
93
-
94
-var client = function client(oss) {
95
-  return new window.OSS.Wrapper({
96
-    accessKeyId: oss.access_key_id,
97
-    accessKeySecret: oss.access_key_secret,
98
-    stsToken: oss.security_token,
99
-    endpoint: _constant.OSS_ENDPOINT, //常量,你可以自己定义
100
-    bucket: _constant.OSS_BUCKET
101
-  });
102
-};
103
-
104
-var uploadPath = function uploadPath(path, file) {
105
-  return path + "/" + (0, _dayjs2.default)().format("YYYYMMDD") + "/" + _shortid2.default.generate() + "." + file.type.split("/")[1];
106
-};
107
-
108
-var UploadToOss = function UploadToOss(oss, path, file) {
109
-  var url = uploadPath(path, file);
110
-  return new Promise(function (resolve, reject) {
111
-    client(oss).multipartUpload(url, file).then(function (data) {
112
-      resolve(data);
113
-    }).catch(function (error) {
114
-      reject(error);
115
-    });
116
-  });
117
-};
118
-
119 85
 var Editor = function (_React$Component) {
120 86
   _inherits(Editor, _React$Component);
121 87
 
@@ -313,7 +279,7 @@ var Editor = function (_React$Component) {
313 279
       reader.readAsDataURL(file);
314 280
       reader.onloadend = function () {
315 281
         // DRIVER_LICENSE_PATH oss 的存储路径位置
316
-        UploadToOss(_this2.props.app.oss, _constant.DRIVER_LICENSE_PATH, file).then(function (data) {
282
+        _this2.props.app.UploadToOss(_this2.props.app.oss, _constant.DRIVER_LICENSE_PATH, file).then(function (data) {
317 283
           var fileList = _this2.state.fileList.concat({
318 284
             url: _constant.OSS_LINK + data.name,
319 285
             thumbUrl: _constant.OSS_LINK + data.name,

+ 1
- 1
lib/components/Editor/index.js.map
Diff nebyl zobrazen, protože je příliš veliký
Zobrazit soubor


+ 0
- 2
lib/constant.js Zobrazit soubor

@@ -7,8 +7,6 @@ var ERROR_DEFAULT = exports.ERROR_DEFAULT = "出错了!";
7 7
 
8 8
 var LIMIT = exports.LIMIT = 10; // 默认 limit
9 9
 
10
-var OSS_ENDPOINT = exports.OSS_ENDPOINT = "oss-cn-beijing.aliyuncs.com";
11
-var OSS_BUCKET = exports.OSS_BUCKET = "links-comment";
12 10
 var DRIVER_LICENSE_PATH = exports.DRIVER_LICENSE_PATH = "/comment";
13 11
 
14 12
 var OSS_LINK = exports.OSS_LINK = "//links-comment.oss-cn-beijing.aliyuncs.com";

+ 1
- 1
lib/constant.js.map Zobrazit soubor

@@ -1 +1 @@
1
-{"version":3,"sources":["../src/constant.js"],"names":["ERROR_DEFAULT","LIMIT","OSS_ENDPOINT","OSS_BUCKET","DRIVER_LICENSE_PATH","OSS_LINK","MAX_UPLOAD_NUMBER","URL_REGEXP","REGEXP","AVATAR","IMAGE_SPLIT","IMAGE_PROCESS","IMAGE_PROCESS_SMALL","IMAGE_PROCESS_LARGE","COMMENT_TYPE","COMMENT","REPLY","LANGUAGE_LINK","process","env","NODE_ENV"],"mappings":";;;;;AAAO,IAAMA,wCAAgB,MAAtB;;AAEA,IAAMC,wBAAQ,EAAd,C,CAAkB;;AAElB,IAAMC,sCAAe,6BAArB;AACA,IAAMC,kCAAa,eAAnB;AACA,IAAMC,oDAAsB,UAA5B;;AAEA,IAAMC,8BAAW,6CAAjB;;AAEA,IAAMC,gDAAoB,CAA1B;;AAEA,IAAMC,kCAAa,oGAAnB;;AAEA,IAAMC,0BAAS,eAAf;;AAEA,IAAMC,0BAAS,EAAf;;AAEA,IAAMC,oCAAc,aAApB;;AAEA,IAAMC,wCAAgB,mCAAtB;AACA,IAAMC,oDAAsB,mCAA5B;AACA,IAAMC,oDAAsB,mCAA5B;;AAEA,IAAMC,sCAAe;AAC1BC,WAAS,SADiB;AAE1BC,SAAO;AAFmB,CAArB;;AAKP;AACO,IAAMC,wCACXC,QAAQC,GAAR,CAAYC,QAAZ,KAAyB,YAAzB,GACI,sBADJ,GAEI,uBAHC","file":"constant.js","sourcesContent":["export const ERROR_DEFAULT = \"出错了!\";\n\nexport const LIMIT = 10; // 默认 limit\n\nexport const OSS_ENDPOINT = \"oss-cn-beijing.aliyuncs.com\";\nexport const OSS_BUCKET = \"links-comment\";\nexport const DRIVER_LICENSE_PATH = \"/comment\";\n\nexport const OSS_LINK = \"//links-comment.oss-cn-beijing.aliyuncs.com\";\n\nexport const MAX_UPLOAD_NUMBER = 4;\n\nexport const URL_REGEXP = /((http(s)?:)?\\/\\/)?(www\\.)?[-a-zA-Z0-9@:%._+~#=]{2,256}\\.[a-z]{2,6}\\b([-a-zA-Z0-9@:%_+.~#?&//=]*)/g;\n\nexport const REGEXP = /\\[[^[\\]]+?\\]/g;\n\nexport const AVATAR = \"\";\n\nexport const IMAGE_SPLIT = \"IMAGE_SPLIT\";\n\nexport const IMAGE_PROCESS = \"?x-oss-process=image/resize,h_350\";\nexport const IMAGE_PROCESS_SMALL = \"?x-oss-process=image/resize,h_100\";\nexport const IMAGE_PROCESS_LARGE = \"?x-oss-process=image/resize,h_500\";\n\nexport const COMMENT_TYPE = {\n  COMMENT: \"comment\",\n  REPLY: \"reply\"\n};\n\n// 线上静态库地址\nexport const LANGUAGE_LINK =\n  process.env.NODE_ENV === \"production\"\n    ? \"//a.links123.cn/lang\"\n    : \"//a.links123.net/lang\";\n"]}
1
+{"version":3,"sources":["../src/constant.js"],"names":["ERROR_DEFAULT","LIMIT","DRIVER_LICENSE_PATH","OSS_LINK","MAX_UPLOAD_NUMBER","URL_REGEXP","REGEXP","AVATAR","IMAGE_SPLIT","IMAGE_PROCESS","IMAGE_PROCESS_SMALL","IMAGE_PROCESS_LARGE","COMMENT_TYPE","COMMENT","REPLY","LANGUAGE_LINK","process","env","NODE_ENV"],"mappings":";;;;;AAAO,IAAMA,wCAAgB,MAAtB;;AAEA,IAAMC,wBAAQ,EAAd,C,CAAkB;;AAElB,IAAMC,oDAAsB,UAA5B;;AAEA,IAAMC,8BAAW,6CAAjB;;AAEA,IAAMC,gDAAoB,CAA1B;;AAEA,IAAMC,kCAAa,oGAAnB;;AAEA,IAAMC,0BAAS,eAAf;;AAEA,IAAMC,0BAAS,EAAf;;AAEA,IAAMC,oCAAc,aAApB;;AAEA,IAAMC,wCAAgB,mCAAtB;AACA,IAAMC,oDAAsB,mCAA5B;AACA,IAAMC,oDAAsB,mCAA5B;;AAEA,IAAMC,sCAAe;AAC1BC,WAAS,SADiB;AAE1BC,SAAO;AAFmB,CAArB;;AAKP;AACO,IAAMC,wCACXC,QAAQC,GAAR,CAAYC,QAAZ,KAAyB,YAAzB,GACI,sBADJ,GAEI,uBAHC","file":"constant.js","sourcesContent":["export const ERROR_DEFAULT = \"出错了!\";\n\nexport const LIMIT = 10; // 默认 limit\n\nexport const DRIVER_LICENSE_PATH = \"/comment\";\n\nexport const OSS_LINK = \"//links-comment.oss-cn-beijing.aliyuncs.com\";\n\nexport const MAX_UPLOAD_NUMBER = 4;\n\nexport const URL_REGEXP = /((http(s)?:)?\\/\\/)?(www\\.)?[-a-zA-Z0-9@:%._+~#=]{2,256}\\.[a-z]{2,6}\\b([-a-zA-Z0-9@:%_+.~#?&//=]*)/g;\n\nexport const REGEXP = /\\[[^[\\]]+?\\]/g;\n\nexport const AVATAR = \"\";\n\nexport const IMAGE_SPLIT = \"IMAGE_SPLIT\";\n\nexport const IMAGE_PROCESS = \"?x-oss-process=image/resize,h_350\";\nexport const IMAGE_PROCESS_SMALL = \"?x-oss-process=image/resize,h_100\";\nexport const IMAGE_PROCESS_LARGE = \"?x-oss-process=image/resize,h_500\";\n\nexport const COMMENT_TYPE = {\n  COMMENT: \"comment\",\n  REPLY: \"reply\"\n};\n\n// 线上静态库地址\nexport const LANGUAGE_LINK =\n  process.env.NODE_ENV === \"production\"\n    ? \"//a.links123.cn/lang\"\n    : \"//a.links123.net/lang\";\n"]}

+ 4
- 4
lib/version.json Zobrazit soubor

@@ -1,8 +1,8 @@
1 1
 {
2 2
     "name":       "comment",
3
-    "buildDate":  1588435719936,
3
+    "buildDate":  1594135597777,
4 4
     "version":    "1.0.4",
5
-    "numCommits": 215,
6
-    "hash":       "7d03c9b",
7
-    "dirty":      true
5
+    "numCommits": 217,
6
+    "hash":       "e6f4c20",
7
+    "dirty":      false
8 8
 }

+ 1
- 2
package.json Zobrazit soubor

@@ -23,7 +23,6 @@
23 23
     "react-dom": "^16.4.1",
24 24
     "react-intl-universal": "^1.15.2",
25 25
     "react-scripts": "1.1.4",
26
-    "shortid": "^2.2.11",
27 26
     "webpack-version-file-plugin": "^0.3.3"
28 27
   },
29 28
   "lint-staged": {
@@ -42,13 +41,13 @@
42 41
     "lib": "babel ./src --out-dir ./lib --source-maps --copy-files"
43 42
   },
44 43
   "devDependencies": {
45
-    "cross-env": "^5.2.0",
46 44
     "babel-cli": "^6.26.0",
47 45
     "babel-plugin-import": "^1.8.0",
48 46
     "babel-plugin-transform-object-rest-spread": "^6.26.0",
49 47
     "babel-preset-env": "^1.7.0",
50 48
     "babel-preset-es2015": "^6.24.1",
51 49
     "babel-preset-react": "^6.24.1",
50
+    "cross-env": "^5.2.0",
52 51
     "husky": "^0.14.3",
53 52
     "lint-staged": "^7.2.0",
54 53
     "node-sass": "^4.9.4",

+ 3
- 39
src/components/Editor/Upload.js Zobrazit soubor

@@ -1,47 +1,10 @@
1 1
 import React from "react";
2 2
 import { Upload, Icon, Modal, message, Spin } from "antd";
3
-import dayjs from "dayjs";
4
-import shortid from "shortid";
5 3
 import intl from "react-intl-universal";
6
-import {
7
-  OSS_ENDPOINT,
8
-  OSS_BUCKET,
9
-  DRIVER_LICENSE_PATH,
10
-  ERROR_DEFAULT
11
-} from "../../constant";
4
+import { DRIVER_LICENSE_PATH, ERROR_DEFAULT } from "../../constant";
12 5
 import Comment from "../../Comment";
13 6
 import "./Upload.css";
14 7
 
15
-const client = oss => {
16
-  return new window.OSS.Wrapper({
17
-    accessKeyId: oss.access_key_id,
18
-    accessKeySecret: oss.access_key_secret,
19
-    stsToken: oss.security_token,
20
-    endpoint: OSS_ENDPOINT, //常量,你可以自己定义
21
-    bucket: OSS_BUCKET
22
-  });
23
-};
24
-
25
-const uploadPath = (path, file) => {
26
-  return `${path}/${dayjs().format("YYYYMMDD")}/${shortid.generate()}.${
27
-    file.type.split("/")[1]
28
-  }`;
29
-};
30
-
31
-const UploadToOss = (oss, path, file) => {
32
-  const url = uploadPath(path, file);
33
-  return new Promise((resolve, reject) => {
34
-    client(oss)
35
-      .multipartUpload(url, file)
36
-      .then(data => {
37
-        resolve(data);
38
-      })
39
-      .catch(error => {
40
-        reject(error);
41
-      });
42
-  });
43
-};
44
-
45 8
 class App extends React.Component {
46 9
   constructor(props) {
47 10
     super(props);
@@ -94,7 +57,8 @@ class App extends React.Component {
94 57
     reader.onloadend = () => {
95 58
       info.onProgress({ percent: 20 });
96 59
       // DRIVER_LICENSE_PATH oss 的存储路径位置
97
-      UploadToOss(this.props.app.oss, DRIVER_LICENSE_PATH, file)
60
+      this.props.app
61
+        .UploadToOss(this.props.app.oss, DRIVER_LICENSE_PATH, file)
98 62
         .then(data => {
99 63
           info.onProgress({ percent: 100 });
100 64
           info.onSuccess(data);

+ 3
- 39
src/components/Editor/index.js Zobrazit soubor

@@ -1,5 +1,3 @@
1
-import dayjs from "dayjs";
2
-import shortid from "shortid";
3 1
 import PropTypes from "prop-types";
4 2
 import classnames from "classnames";
5 3
 import React, { Fragment } from "react";
@@ -11,46 +9,11 @@ import Comment from "../../Comment";
11 9
 import { isMobile } from "./../../utils";
12 10
 import { OSS_LINK } from "../../constant";
13 11
 import { isFunction } from "../../helper";
14
-import {
15
-  OSS_ENDPOINT,
16
-  OSS_BUCKET,
17
-  DRIVER_LICENSE_PATH,
18
-  ERROR_DEFAULT
19
-} from "../../constant";
12
+import { DRIVER_LICENSE_PATH, ERROR_DEFAULT } from "../../constant";
20 13
 import "./index.css";
21 14
 
22 15
 const { TextArea } = Input;
23 16
 
24
-const client = oss => {
25
-  return new window.OSS.Wrapper({
26
-    accessKeyId: oss.access_key_id,
27
-    accessKeySecret: oss.access_key_secret,
28
-    stsToken: oss.security_token,
29
-    endpoint: OSS_ENDPOINT, //常量,你可以自己定义
30
-    bucket: OSS_BUCKET
31
-  });
32
-};
33
-
34
-const uploadPath = (path, file) => {
35
-  return `${path}/${dayjs().format("YYYYMMDD")}/${shortid.generate()}.${
36
-    file.type.split("/")[1]
37
-  }`;
38
-};
39
-
40
-const UploadToOss = (oss, path, file) => {
41
-  const url = uploadPath(path, file);
42
-  return new Promise((resolve, reject) => {
43
-    client(oss)
44
-      .multipartUpload(url, file)
45
-      .then(data => {
46
-        resolve(data);
47
-      })
48
-      .catch(error => {
49
-        reject(error);
50
-      });
51
-  });
52
-};
53
-
54 17
 class Editor extends React.Component {
55 18
   constructor(props) {
56 19
     super(props);
@@ -214,7 +177,8 @@ class Editor extends React.Component {
214 177
     reader.readAsDataURL(file);
215 178
     reader.onloadend = () => {
216 179
       // DRIVER_LICENSE_PATH oss 的存储路径位置
217
-      UploadToOss(this.props.app.oss, DRIVER_LICENSE_PATH, file)
180
+      this.props.app
181
+        .UploadToOss(this.props.app.oss, DRIVER_LICENSE_PATH, file)
218 182
         .then(data => {
219 183
           const fileList = this.state.fileList.concat({
220 184
             url: OSS_LINK + data.name,

+ 0
- 2
src/constant.js Zobrazit soubor

@@ -2,8 +2,6 @@ export const ERROR_DEFAULT = "出错了!";
2 2
 
3 3
 export const LIMIT = 10; // 默认 limit
4 4
 
5
-export const OSS_ENDPOINT = "oss-cn-beijing.aliyuncs.com";
6
-export const OSS_BUCKET = "links-comment";
7 5
 export const DRIVER_LICENSE_PATH = "/comment";
8 6
 
9 7
 export const OSS_LINK = "//links-comment.oss-cn-beijing.aliyuncs.com";