speedly 2.0.46 → 2.1.0
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/cjs/util/getConfig.d.ts +1 -1
- package/dist/cjs/util/getConfig.js +4 -4
- package/dist/cjs/util/translator.d.ts +2 -2
- package/dist/cjs/util/translator.js +21 -2
- package/dist/esm/util/getConfig.d.ts +1 -1
- package/dist/esm/util/getConfig.js +4 -4
- package/dist/esm/util/translator.d.ts +2 -2
- package/dist/esm/util/translator.js +21 -2
- package/package.json +1 -1
|
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const fs_1 = __importDefault(require("fs"));
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
|
-
const
|
|
8
|
+
const configs_default_1 = __importDefault(require("../configs.default"));
|
|
9
9
|
const find = (field, ...args) => {
|
|
10
10
|
const rel = path_1.default.join.apply(null, [].slice.call(args));
|
|
11
11
|
if (!require?.main?.filename)
|
|
@@ -35,10 +35,10 @@ const findStartingWith = (start, rel, field) => {
|
|
|
35
35
|
const configGetter = (configField) => {
|
|
36
36
|
const foundData = find(configField, "speedly.config");
|
|
37
37
|
let configValue = {};
|
|
38
|
-
if (
|
|
39
|
-
Object.entries(
|
|
38
|
+
if (configs_default_1.default[configField] &&
|
|
39
|
+
Object.entries(configs_default_1.default[configField]).length) {
|
|
40
40
|
configValue = {
|
|
41
|
-
...
|
|
41
|
+
...configs_default_1.default[configField]
|
|
42
42
|
};
|
|
43
43
|
}
|
|
44
44
|
if (foundData) {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const
|
|
2
|
-
export default
|
|
1
|
+
declare const main: (text?: string, lang?: string) => Promise<string>;
|
|
2
|
+
export default main;
|
|
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const axios_1 = __importDefault(require("axios"));
|
|
7
7
|
const translation_1 = __importDefault(require("./../model/translation"));
|
|
8
|
-
const TIMEOUT =
|
|
8
|
+
const TIMEOUT = 7000;
|
|
9
9
|
const getConfig_1 = __importDefault(require("./getConfig"));
|
|
10
10
|
const configs = (0, getConfig_1.default)("translate");
|
|
11
11
|
async function firstSuccessful(promises) {
|
|
@@ -24,7 +24,24 @@ async function firstSuccessful(promises) {
|
|
|
24
24
|
});
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
|
-
|
|
27
|
+
const bertinaTranslate = async (formattedText, lang) => {
|
|
28
|
+
console.log('translator', 25);
|
|
29
|
+
const res = await axios_1.default.post("https://translate.bertina.ir/api/translate", {
|
|
30
|
+
text: formattedText,
|
|
31
|
+
source: 'auto',
|
|
32
|
+
target: lang,
|
|
33
|
+
}, {
|
|
34
|
+
timeout: TIMEOUT,
|
|
35
|
+
});
|
|
36
|
+
console.log('translator', 81, res.status);
|
|
37
|
+
if (res.status === 200) {
|
|
38
|
+
return res.data.translatedText;
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
throw new Error(res.data.message);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
const main = async (text = "unspecified text", lang = "fa") => {
|
|
28
45
|
const formattedText = text
|
|
29
46
|
.replaceAll(/[\-\_]/g, " ")
|
|
30
47
|
.replaceAll(/[A-Z]/g, " $&");
|
|
@@ -58,6 +75,7 @@ exports.default = async (text = "unspecified text", lang = "fa") => {
|
|
|
58
75
|
throw new Error(res.data.message);
|
|
59
76
|
}
|
|
60
77
|
})());
|
|
78
|
+
translationPromises.push(bertinaTranslate(formattedText, lang));
|
|
61
79
|
try {
|
|
62
80
|
const result = await firstSuccessful(translationPromises);
|
|
63
81
|
await translation_1.default.create({
|
|
@@ -72,3 +90,4 @@ exports.default = async (text = "unspecified text", lang = "fa") => {
|
|
|
72
90
|
return formattedText;
|
|
73
91
|
}
|
|
74
92
|
};
|
|
93
|
+
exports.default = main;
|
|
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const fs_1 = __importDefault(require("fs"));
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
|
-
const
|
|
8
|
+
const configs_default_1 = __importDefault(require("../configs.default"));
|
|
9
9
|
const find = (field, ...args) => {
|
|
10
10
|
const rel = path_1.default.join.apply(null, [].slice.call(args));
|
|
11
11
|
if (!require?.main?.filename)
|
|
@@ -35,10 +35,10 @@ const findStartingWith = (start, rel, field) => {
|
|
|
35
35
|
const configGetter = (configField) => {
|
|
36
36
|
const foundData = find(configField, "speedly.config");
|
|
37
37
|
let configValue = {};
|
|
38
|
-
if (
|
|
39
|
-
Object.entries(
|
|
38
|
+
if (configs_default_1.default[configField] &&
|
|
39
|
+
Object.entries(configs_default_1.default[configField]).length) {
|
|
40
40
|
configValue = {
|
|
41
|
-
...
|
|
41
|
+
...configs_default_1.default[configField]
|
|
42
42
|
};
|
|
43
43
|
}
|
|
44
44
|
if (foundData) {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const
|
|
2
|
-
export default
|
|
1
|
+
declare const main: (text?: string, lang?: string) => Promise<string>;
|
|
2
|
+
export default main;
|
|
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const axios_1 = __importDefault(require("axios"));
|
|
7
7
|
const translation_1 = __importDefault(require("./../model/translation"));
|
|
8
|
-
const TIMEOUT =
|
|
8
|
+
const TIMEOUT = 7000;
|
|
9
9
|
const getConfig_1 = __importDefault(require("./getConfig"));
|
|
10
10
|
const configs = (0, getConfig_1.default)("translate");
|
|
11
11
|
async function firstSuccessful(promises) {
|
|
@@ -24,7 +24,24 @@ async function firstSuccessful(promises) {
|
|
|
24
24
|
});
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
|
-
|
|
27
|
+
const bertinaTranslate = async (formattedText, lang) => {
|
|
28
|
+
console.log('translator', 25);
|
|
29
|
+
const res = await axios_1.default.post("https://translate.bertina.ir/api/translate", {
|
|
30
|
+
text: formattedText,
|
|
31
|
+
source: 'auto',
|
|
32
|
+
target: lang,
|
|
33
|
+
}, {
|
|
34
|
+
timeout: TIMEOUT,
|
|
35
|
+
});
|
|
36
|
+
console.log('translator', 81, res.status);
|
|
37
|
+
if (res.status === 200) {
|
|
38
|
+
return res.data.translatedText;
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
throw new Error(res.data.message);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
const main = async (text = "unspecified text", lang = "fa") => {
|
|
28
45
|
const formattedText = text
|
|
29
46
|
.replaceAll(/[\-\_]/g, " ")
|
|
30
47
|
.replaceAll(/[A-Z]/g, " $&");
|
|
@@ -58,6 +75,7 @@ exports.default = async (text = "unspecified text", lang = "fa") => {
|
|
|
58
75
|
throw new Error(res.data.message);
|
|
59
76
|
}
|
|
60
77
|
})());
|
|
78
|
+
translationPromises.push(bertinaTranslate(formattedText, lang));
|
|
61
79
|
try {
|
|
62
80
|
const result = await firstSuccessful(translationPromises);
|
|
63
81
|
await translation_1.default.create({
|
|
@@ -72,3 +90,4 @@ exports.default = async (text = "unspecified text", lang = "fa") => {
|
|
|
72
90
|
return formattedText;
|
|
73
91
|
}
|
|
74
92
|
};
|
|
93
|
+
exports.default = main;
|