@zwa73/utils 1.0.19 → 1.0.21

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.
package/dist/UtilCom.js CHANGED
@@ -90,26 +90,26 @@ function shttpPost(json, options, timeLimit = -1) {
90
90
  let jsonStr = JSON.stringify(json);
91
91
  return new Promise(function (resolve, rejecte) {
92
92
  let req = http.request(options, function (res) {
93
- //请求超时
94
- if (hasTimeLimit) {
95
- res.setTimeout(timeLimit, function () {
96
- //res.abort();
97
- console.log("shttpPost 接收反馈超时: " + timeLimit + " ms");
98
- resolve(null);
93
+ try {
94
+ //请求超时
95
+ if (hasTimeLimit) {
96
+ res.setTimeout(timeLimit, () => {
97
+ //res.abort();
98
+ throw "shttpPost 接收反馈超时: " + timeLimit + " ms";
99
+ });
100
+ }
101
+ let resdata = "";
102
+ res.setEncoding('utf8');
103
+ res.on('data', (chunk) => {
104
+ //console.log(chunk);
105
+ resdata += chunk;
99
106
  });
100
- }
101
- let resdata = "";
102
- res.setEncoding('utf8');
103
- res.on('data', function (chunk) {
104
- //console.log(chunk);
105
- resdata += chunk;
106
- });
107
- res.on('error', function (e) {
108
- console.log("shttpPost 接收反馈错误:" + e);
109
- resolve(null);
110
- });
111
- res.on('end', function () {
112
- if (resdata != "") {
107
+ res.on('error', (e) => {
108
+ throw "shttpPost 接收反馈错误:" + e;
109
+ });
110
+ res.on('end', function () {
111
+ if (resdata == "")
112
+ throw "shttpPost 接收反馈错误: resdata 为空";
113
113
  try {
114
114
  let obj = JSON.parse(resdata);
115
115
  console.log("shttpPost 接受信息:\r\n" + JSON.stringify(obj));
@@ -118,16 +118,17 @@ function shttpPost(json, options, timeLimit = -1) {
118
118
  return;
119
119
  }
120
120
  catch (e) {
121
- console.log("shttpPost 接收反馈错误:" + e);
122
- console.log("原始字符串:" + resdata);
123
- resolve(null);
124
- return;
121
+ throw "shttpPost 接收反馈错误:" + e + "\n原始字符串:" + resdata;
125
122
  }
126
- }
127
- console.log("shttpPost 接收反馈错误: resdata 为空");
123
+ });
124
+ }
125
+ catch (err) {
126
+ if (typeof err != "string")
127
+ throw err;
128
+ console.log(err);
128
129
  resolve(null);
129
130
  return;
130
- });
131
+ }
131
132
  });
132
133
  //请求超时
133
134
  if (hasTimeLimit) {
@@ -8,6 +8,9 @@ export type IOMap = {
8
8
  /**ffmpeg工具类
9
9
  */
10
10
  declare class SFfmpegTool {
11
+ /**静态构造函数
12
+ */
13
+ static init(): void;
11
14
  /**设置ffmpeg路径
12
15
  */
13
16
  static setFfmpegPath(ffmpegPath: string): void;
@@ -8,6 +8,17 @@ const UtilClass_1 = require("./UtilClass");
8
8
  /**ffmpeg工具类
9
9
  */
10
10
  class SFfmpegTool {
11
+ /**静态构造函数
12
+ */
13
+ static init() {
14
+ let ffmpegPath = process.env.FFMPEG_PATH;
15
+ if (ffmpegPath != null) {
16
+ let exepath = path.join(ffmpegPath, "ffmpeg.exe");
17
+ //console.log("ffmpegPath")
18
+ //console.log(exepath)
19
+ SFfmpegTool.setFfmpegPath(exepath);
20
+ }
21
+ }
11
22
  /**设置ffmpeg路径
12
23
  */
13
24
  static setFfmpegPath(ffmpegPath) {
@@ -182,6 +193,7 @@ class SFfmpegTool {
182
193
  }
183
194
  }
184
195
  exports.SFfmpegTool = SFfmpegTool;
196
+ SFfmpegTool.init();
185
197
  /**多线程任务分割器
186
198
  * @param {IOMap} iomap - 输入输出路径映射
187
199
  * @param {number} cpCount - 并发数
@@ -17,3 +17,10 @@ export type MessageEntity = {
17
17
  role: string;
18
18
  content: string;
19
19
  };
20
+ export interface IJObjectData {
21
+ saveToJObject(): JObject;
22
+ }
23
+ export type JObjectData = {
24
+ [key: string]: JToken | JObjectData | IJObjectData;
25
+ };
26
+ export declare function parseJObjectData(): void;
@@ -1,2 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseJObjectData = void 0;
4
+ function parseJObjectData() { }
5
+ exports.parseJObjectData = parseJObjectData;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zwa73/utils",
3
- "version": "1.0.19",
3
+ "version": "1.0.21",
4
4
  "description": "my utils",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/src/UtilCom.ts CHANGED
@@ -101,29 +101,29 @@ export function shttpPost(json:JObject,options:Object,timeLimit:number=-1):Promi
101
101
 
102
102
  return new Promise(function(resolve, rejecte){
103
103
  let req = http.request(options, function(res){
104
- //请求超时
105
- if(hasTimeLimit){
106
- res.setTimeout(timeLimit, function() {
107
- //res.abort();
108
- console.log("shttpPost 接收反馈超时: "+timeLimit+" ms");
109
- resolve(null);
110
- });
111
- }
104
+ try{
105
+ //请求超时
106
+ if(hasTimeLimit){
107
+ res.setTimeout(timeLimit, ()=>{
108
+ //res.abort();
109
+ throw "shttpPost 接收反馈超时: "+timeLimit+" ms";
110
+ });
111
+ }
112
112
 
113
- let resdata = "";
114
- res.setEncoding('utf8');
115
- res.on('data',function(chunk){
116
- //console.log(chunk);
117
- resdata+=chunk;
118
- });
113
+ let resdata = "";
114
+ res.setEncoding('utf8');
115
+ res.on('data',(chunk)=>{
116
+ //console.log(chunk);
117
+ resdata+=chunk;
118
+ });
119
119
 
120
- res.on('error',function(e){
121
- console.log("shttpPost 接收反馈错误:"+e);
122
- resolve(null);
123
- });
120
+ res.on('error',(e)=>{
121
+ throw "shttpPost 接收反馈错误:"+e
122
+ });
124
123
 
125
- res.on('end',function(){
126
- if(resdata!=""){
124
+ res.on('end',function(){
125
+ if(resdata=="")
126
+ throw "shttpPost 接收反馈错误: resdata 为空";
127
127
  try{
128
128
  let obj = JSON.parse(resdata);
129
129
  console.log("shttpPost 接受信息:\r\n"+JSON.stringify(obj));
@@ -132,17 +132,16 @@ export function shttpPost(json:JObject,options:Object,timeLimit:number=-1):Promi
132
132
  return;
133
133
  }
134
134
  catch(e){
135
- console.log("shttpPost 接收反馈错误:"+e);
136
- console.log("原始字符串:"+resdata);
137
- resolve(null);
138
- return;
135
+ throw "shttpPost 接收反馈错误:"+e+"\n原始字符串:"+resdata;
139
136
  }
140
- }
141
- console.log("shttpPost 接收反馈错误: resdata 为空");
137
+ });
138
+ }catch(err){
139
+ if(typeof err != "string")
140
+ throw err;
141
+ console.log(err);
142
142
  resolve(null);
143
143
  return;
144
- });
145
-
144
+ }
146
145
  });
147
146
 
148
147
  //请求超时
@@ -12,6 +12,17 @@ export type IOMap = { [key: string]: string };
12
12
  /**ffmpeg工具类
13
13
  */
14
14
  class SFfmpegTool {
15
+ /**静态构造函数
16
+ */
17
+ static init() {
18
+ let ffmpegPath = process.env.FFMPEG_PATH;
19
+ if(ffmpegPath!=null){
20
+ let exepath = path.join(ffmpegPath,"ffmpeg.exe");
21
+ //console.log("ffmpegPath")
22
+ //console.log(exepath)
23
+ SFfmpegTool.setFfmpegPath(exepath);
24
+ }
25
+ }
15
26
  /**设置ffmpeg路径
16
27
  */
17
28
  static setFfmpegPath(ffmpegPath: string) {
@@ -221,6 +232,8 @@ class SFfmpegTool {
221
232
  .appendOperations();
222
233
  }
223
234
  }
235
+ SFfmpegTool.init();
236
+
224
237
 
225
238
  /**多线程任务分割器
226
239
  * @param {IOMap} iomap - 输入输出路径映射
@@ -21,4 +21,13 @@ export type AnyObject={
21
21
  export type MessageEntity={
22
22
  role: string;
23
23
  content:string;
24
- }
24
+ }
25
+
26
+ export interface IJObjectData{
27
+ saveToJObject():JObject;
28
+ }
29
+ export type JObjectData = {
30
+ [key:string]:JToken|JObjectData|IJObjectData;
31
+ }
32
+
33
+ export function parseJObjectData(){}
package/test.js CHANGED
@@ -1,4 +1,4 @@
1
- let {SList,SHashMap,SEntry,SFfmpegTool,fileSearch} = require('./dist');
1
+ let {SList,SHashMap,SEntry,SFfmpegTool,fileSearch,sleep} = require('./dist');
2
2
 
3
3
  let slist = new SList([1,2,3,3,4,5,6]);
4
4
  slist.each(val => console.log(val));
@@ -11,18 +11,23 @@ map.put("789",111)
11
11
  for(let {key,value} of map)
12
12
  console.log(key,value)
13
13
 
14
- SFfmpegTool.setFfmpegPath("E:/系统工具/ffmpeg-master-latest-win64-gpl/bin/ffmpeg.exe");
15
- (async function(){
14
+ //SFfmpegTool.setFfmpegPath("E:/系统工具/ffmpeg-master-latest-win64-gpl/bin/ffmpeg.exe");
15
+ async function main(){
16
+ //SFfmpegTool.setFfmpegPath("E:/系统工具/ffmpeg-master-latest-win64-gpl/bin/ffmpeg.exe");
17
+ //console.log(111111111111)
16
18
  let data = await SFfmpegTool.getAudioMetaData("input.wav");
19
+ //console.log(22)
17
20
  console.log(data);
18
-
19
- let fileMap = fileSearch("F:/Sosarciel/SoulTide-Collection-VITS-TrainingSet/TrainingSet/Akaset/sliced_audio",'.*\\.wav');
20
- let ioMap = {};
21
- for(let key in fileMap){
22
- let value = fileMap[key];
23
- ioMap[value] = "./test/"+key;
24
- }
21
+ //
22
+ //let fileMap = fileSearch("F:/Sosarciel/SoulTide-Collection-VITS-TrainingSet/TrainingSet/Akaset/sliced_audio",'.*\\.wav');
23
+ //let ioMap = {};
24
+ //for(let key in fileMap){
25
+ // let value = fileMap[key];
26
+ // ioMap[value] = "./test/"+key;
27
+ //}
25
28
  //console.log(ioMap)
26
- await SFfmpegTool.resampleMP(ioMap)
27
- }())
29
+ //await SFfmpegTool.resampleMP(ioMap)
30
+ }
31
+ main();
32
+
28
33