@sc-voice/tools 2.18.0 → 2.19.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/package.json +1 -1
- package/src/defines.mjs +2 -0
- package/src/text/legacy-doc.mjs +21 -8
package/package.json
CHANGED
package/src/defines.mjs
CHANGED
|
@@ -8,5 +8,7 @@ export const DBG = {
|
|
|
8
8
|
DEEPL_MOCK_XLT: 0, // use mock translation
|
|
9
9
|
DEEPL_TEST_API: 0, // test with live DeepL API ($$$)
|
|
10
10
|
DEEPL_XLT: 0, // test live translation
|
|
11
|
+
L7C_FETCH_LEGACY: 0,
|
|
12
|
+
L7C_FETCH_LEGACY_SC: 0, // ignore test cache and use SC
|
|
11
13
|
WORD_MAP_TRANFORMER: 0,
|
|
12
14
|
};
|
package/src/text/legacy-doc.mjs
CHANGED
|
@@ -37,20 +37,33 @@ export class LegacyDoc {
|
|
|
37
37
|
return true;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
static
|
|
41
|
-
const msg = 'L7c.fetch:';
|
|
42
|
-
const dbg = DBG.FETCH_LEGACY;
|
|
40
|
+
static legacyUrl(opts={}) {
|
|
43
41
|
let {
|
|
44
|
-
endPoint = 'https://suttacentral.net/api/suttas',
|
|
42
|
+
endPoint = 'https://staging.suttacentral.net/api/suttas',
|
|
45
43
|
sutta_uid,
|
|
46
44
|
lang,
|
|
47
45
|
author,
|
|
46
|
+
} = opts;
|
|
47
|
+
|
|
48
|
+
return [endPoint, sutta_uid, `${author}?lang=${lang}`].join('/');
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
static async fetchLegacy(opts = {}) {
|
|
52
|
+
const msg = 'L7c.fetchLegacy:';
|
|
53
|
+
const dbg = DBG.L7C_FETCH_LEGACY;
|
|
54
|
+
let {
|
|
48
55
|
maxBuffer = 10 * 1024 * 1024,
|
|
56
|
+
cache,
|
|
49
57
|
} = opts;
|
|
50
|
-
let url =
|
|
51
|
-
|
|
52
|
-
)
|
|
53
|
-
|
|
58
|
+
let url = LegacyDoc.legacyUrl(opts);
|
|
59
|
+
let res;
|
|
60
|
+
if (cache) {
|
|
61
|
+
res = cache(url);
|
|
62
|
+
dbg && console.log(msg, '[1]cached', res.ok);
|
|
63
|
+
} else {
|
|
64
|
+
res = await fetch(url, {maxBuffer});
|
|
65
|
+
dbg && console.log(msg, '[2]scapi', res.ok);
|
|
66
|
+
}
|
|
54
67
|
if (!res.ok) {
|
|
55
68
|
throw new Error(`${msg} {res.status} ${url}`);
|
|
56
69
|
}
|