@freelog/tools-lib 0.1.108 → 0.1.109

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,12 @@
1
+ interface FileInfo {
2
+ sha1: string;
3
+ state: 'success' | 'fail' | 'nonentity';
4
+ info: {
5
+ [key: string]: any;
6
+ };
7
+ }
1
8
  interface GetFileInfosBySha1Params {
2
9
  sha1: string[];
3
- cdPartiallySuccess?: (s: any[]) => void;
4
- cdPartiallyFail?: (f: any[]) => void;
5
10
  }
6
- export declare function getFilesSha1Info({ sha1, cdPartiallySuccess, cdPartiallyFail }: GetFileInfosBySha1Params): Promise<void>;
11
+ export declare function getFilesSha1Info({ sha1 }: GetFileInfosBySha1Params, cdPartially?: (s: any[]) => void): Promise<FileInfo[]>;
7
12
  export {};
@@ -13,7 +13,7 @@ import * as Activity from './activities';
13
13
  import * as TestQualification from './testQualifications';
14
14
  import * as Statistic from './statistics';
15
15
  import * as I18n from './i18n';
16
- import * as C from './combinations';
16
+ import * as combination from './combinations';
17
17
  declare const FServiceAPI: {
18
18
  Node: typeof Node;
19
19
  Exhibit: typeof Exhibit;
@@ -30,6 +30,6 @@ declare const FServiceAPI: {
30
30
  TestQualification: typeof TestQualification;
31
31
  Statistic: typeof Statistic;
32
32
  I18n: typeof I18n;
33
- C: typeof C;
33
+ combination: typeof combination;
34
34
  };
35
35
  export default FServiceAPI;
@@ -2264,6 +2264,8 @@ function registerOrBind(params) {
2264
2264
  method: 'POST',
2265
2265
  url: "/v2/thirdParty/registerOrBind",
2266
2266
  data: params
2267
+ }, {
2268
+ noRedirect: true
2267
2269
  });
2268
2270
  }
2269
2271
 
@@ -2749,33 +2751,193 @@ var I18n = {
2749
2751
  configsList: configsList
2750
2752
  };
2751
2753
 
2752
- function getFilesSha1Info(_x) {
2754
+ /**
2755
+ * 根据 File 获取 SHA1 Hash 字符串
2756
+ * @param file
2757
+ * @return {Promise<string>}
2758
+ */
2759
+
2760
+ function getSHA1Hash(file) {
2761
+ return new Promise(function (resolve) {
2762
+ var reader = new FileReader();
2763
+
2764
+ reader.onload = function () {
2765
+ var wordArray = CryptoJS.lib.WordArray.create(reader.result);
2766
+ var hash = CryptoJS.SHA1(wordArray).toString();
2767
+ resolve(hash);
2768
+ };
2769
+
2770
+ reader.readAsArrayBuffer(file);
2771
+ });
2772
+ }
2773
+ /**
2774
+ * 生成随机码
2775
+ */
2776
+
2777
+ function generateRandomCode(strLen) {
2778
+ if (strLen === void 0) {
2779
+ strLen = 5;
2780
+ }
2781
+
2782
+ var allStr = 'ABCDEFGHIJKLMNPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890';
2783
+ var newStrArr = [];
2784
+
2785
+ for (var i = 0; i < strLen; i++) {
2786
+ newStrArr.push(allStr[Math.floor(Math.random() * 61)]);
2787
+ }
2788
+
2789
+ return newStrArr.join('');
2790
+ }
2791
+ /**
2792
+ * 通过读取 cookies 获取用户 ID
2793
+ */
2794
+
2795
+ function getUserIDByCookies() {
2796
+ var uid = document.cookie.split('; ').find(function (co) {
2797
+ return co.startsWith('uid=');
2798
+ });
2799
+
2800
+ if (!uid) {
2801
+ return -1;
2802
+ }
2803
+
2804
+ return Number(uid.replace('uid=', ''));
2805
+ }
2806
+ function transformServerAPIContractState(_ref) {
2807
+ var status = _ref.status,
2808
+ authStatus = _ref.authStatus;
2809
+
2810
+ if (status === 0) {
2811
+ if (authStatus === 1 || authStatus === 3) {
2812
+ return 'active';
2813
+ }
2814
+
2815
+ if (authStatus === 2) {
2816
+ return 'testActive';
2817
+ }
2818
+
2819
+ if (authStatus === 128) {
2820
+ return 'inactive';
2821
+ }
2822
+ }
2823
+
2824
+ if (status === 1) {
2825
+ return 'terminal';
2826
+ }
2827
+
2828
+ return 'exception';
2829
+ }
2830
+ /**
2831
+ * 暂时休眠
2832
+ * @param ms 休眠时常(毫秒)
2833
+ */
2834
+
2835
+ function promiseSleep(ms) {
2836
+ if (ms === void 0) {
2837
+ ms = 300;
2838
+ }
2839
+
2840
+ return new Promise(function (resolve) {
2841
+ setTimeout(function () {
2842
+ resolve();
2843
+ }, ms);
2844
+ });
2845
+ }
2846
+
2847
+ var Tool = {
2848
+ __proto__: null,
2849
+ getSHA1Hash: getSHA1Hash,
2850
+ generateRandomCode: generateRandomCode,
2851
+ getUserIDByCookies: getUserIDByCookies,
2852
+ transformServerAPIContractState: transformServerAPIContractState,
2853
+ promiseSleep: promiseSleep
2854
+ };
2855
+
2856
+ function getFilesSha1Info(_x, _x2) {
2753
2857
  return _getFilesSha1Info.apply(this, arguments);
2754
2858
  }
2755
2859
 
2756
2860
  function _getFilesSha1Info() {
2757
- _getFilesSha1Info = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(_ref) {
2758
- var sha1, cdPartiallySuccess, cdPartiallyFail, _yield$Storage$filesL, data, all, success, fail;
2861
+ _getFilesSha1Info = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(_ref, cdPartially) {
2862
+ var sha1, needHandleSha1, allData, _yield$Storage$filesL, data, finishedInfo;
2759
2863
 
2760
2864
  return runtime_1.wrap(function _callee$(_context) {
2761
2865
  while (1) {
2762
2866
  switch (_context.prev = _context.next) {
2763
2867
  case 0:
2764
- sha1 = _ref.sha1, cdPartiallySuccess = _ref.cdPartiallySuccess, cdPartiallyFail = _ref.cdPartiallyFail;
2765
- _context.next = 3;
2868
+ sha1 = _ref.sha1;
2869
+
2870
+ if (cdPartially === void 0) {
2871
+ cdPartially = function cdPartially() {
2872
+ return undefined;
2873
+ };
2874
+ }
2875
+
2876
+ if (!(sha1.length === 0)) {
2877
+ _context.next = 4;
2878
+ break;
2879
+ }
2880
+
2881
+ return _context.abrupt("return", []);
2882
+
2883
+ case 4:
2884
+ needHandleSha1 = [].concat(sha1);
2885
+ allData = [];
2886
+
2887
+ case 6:
2888
+
2889
+ _context.next = 9;
2766
2890
  return filesListInfo({
2767
- sha1: sha1
2891
+ sha1: needHandleSha1
2768
2892
  });
2769
2893
 
2770
- case 3:
2894
+ case 9:
2771
2895
  _yield$Storage$filesL = _context.sent;
2772
2896
  data = _yield$Storage$filesL.data;
2773
- all = [];
2774
- success = [];
2775
- fail = [];
2776
- console.log(data, all, success, fail, cdPartiallySuccess, cdPartiallyFail, '093oijsdlkfsjdl');
2897
+ needHandleSha1 = data.filter(function (d) {
2898
+ return d.metaAnalyzeStatus && d.metaAnalyzeStatus === 1;
2899
+ }).map(function (d) {
2900
+ return d.sha1;
2901
+ });
2902
+ finishedInfo = data.filter(function (d) {
2903
+ return !d.metaAnalyzeStatus || d.metaAnalyzeStatus !== 1;
2904
+ }).map(function (d) {
2905
+ var state = 'fail';
2906
+
2907
+ if (!d.metaAnalyzeStatus) {
2908
+ state = 'nonentity';
2909
+ } else if (d.metaAnalyzeStatus === 2) {
2910
+ state = 'success';
2911
+ }
2777
2912
 
2778
- case 9:
2913
+ return {
2914
+ sha1: d.sha1,
2915
+ state: state,
2916
+ info: d
2917
+ };
2918
+ });
2919
+ cdPartially && cdPartially(finishedInfo);
2920
+ allData = [].concat(allData, finishedInfo);
2921
+
2922
+ if (!(needHandleSha1.length === 0)) {
2923
+ _context.next = 17;
2924
+ break;
2925
+ }
2926
+
2927
+ return _context.abrupt("break", 21);
2928
+
2929
+ case 17:
2930
+ _context.next = 19;
2931
+ return promiseSleep(3000);
2932
+
2933
+ case 19:
2934
+ _context.next = 6;
2935
+ break;
2936
+
2937
+ case 21:
2938
+ return _context.abrupt("return", allData);
2939
+
2940
+ case 22:
2779
2941
  case "end":
2780
2942
  return _context.stop();
2781
2943
  }
@@ -2785,7 +2947,7 @@ function _getFilesSha1Info() {
2785
2947
  return _getFilesSha1Info.apply(this, arguments);
2786
2948
  }
2787
2949
 
2788
- var C = {
2950
+ var combination = {
2789
2951
  __proto__: null,
2790
2952
  getFilesSha1Info: getFilesSha1Info
2791
2953
  };
@@ -2806,7 +2968,7 @@ var FServiceAPI = {
2806
2968
  TestQualification: TestQualification,
2807
2969
  Statistic: Statistic,
2808
2970
  I18n: I18n,
2809
- C: C
2971
+ combination: combination
2810
2972
  };
2811
2973
 
2812
2974
  var codeMessage = {
@@ -2964,91 +3126,6 @@ function _request() {
2964
3126
  return _request.apply(this, arguments);
2965
3127
  }
2966
3128
 
2967
- /**
2968
- * 根据 File 获取 SHA1 Hash 字符串
2969
- * @param file
2970
- * @return {Promise<string>}
2971
- */
2972
-
2973
- function getSHA1Hash(file) {
2974
- return new Promise(function (resolve) {
2975
- var reader = new FileReader();
2976
-
2977
- reader.onload = function () {
2978
- var wordArray = CryptoJS.lib.WordArray.create(reader.result);
2979
- var hash = CryptoJS.SHA1(wordArray).toString();
2980
- resolve(hash);
2981
- };
2982
-
2983
- reader.readAsArrayBuffer(file);
2984
- });
2985
- }
2986
- /**
2987
- * 生成随机码
2988
- */
2989
-
2990
- function generateRandomCode(strLen) {
2991
- if (strLen === void 0) {
2992
- strLen = 5;
2993
- }
2994
-
2995
- var allStr = 'ABCDEFGHIJKLMNPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890';
2996
- var newStrArr = [];
2997
-
2998
- for (var i = 0; i < strLen; i++) {
2999
- newStrArr.push(allStr[Math.floor(Math.random() * 61)]);
3000
- }
3001
-
3002
- return newStrArr.join('');
3003
- }
3004
- /**
3005
- * 通过读取 cookies 获取用户 ID
3006
- */
3007
-
3008
- function getUserIDByCookies() {
3009
- var uid = document.cookie.split('; ').find(function (co) {
3010
- return co.startsWith('uid=');
3011
- });
3012
-
3013
- if (!uid) {
3014
- return -1;
3015
- }
3016
-
3017
- return Number(uid.replace('uid=', ''));
3018
- }
3019
- function transformServerAPIContractState(_ref) {
3020
- var status = _ref.status,
3021
- authStatus = _ref.authStatus;
3022
-
3023
- if (status === 0) {
3024
- if (authStatus === 1 || authStatus === 3) {
3025
- return 'active';
3026
- }
3027
-
3028
- if (authStatus === 2) {
3029
- return 'testActive';
3030
- }
3031
-
3032
- if (authStatus === 128) {
3033
- return 'inactive';
3034
- }
3035
- }
3036
-
3037
- if (status === 1) {
3038
- return 'terminal';
3039
- }
3040
-
3041
- return 'exception';
3042
- }
3043
-
3044
- var Tool = {
3045
- __proto__: null,
3046
- getSHA1Hash: getSHA1Hash,
3047
- generateRandomCode: generateRandomCode,
3048
- getUserIDByCookies: getUserIDByCookies,
3049
- transformServerAPIContractState: transformServerAPIContractState
3050
- };
3051
-
3052
3129
  var FUtil = {
3053
3130
  Format: Format,
3054
3131
  Regexp: Regexp,