Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Here's how to fix the BAD_REQUEST error on the npm package #118

Open
Iru21 opened this issue Jul 5, 2021 · 1 comment
Open

Here's how to fix the BAD_REQUEST error on the npm package #118

Iru21 opened this issue Jul 5, 2021 · 1 comment

Comments

@Iru21
Copy link

Iru21 commented Jul 5, 2021

Find the google-translate-api in your node_modules folder and replace tk.js file content with this (it is literally this but I fixed the export)

var got = require("got"), Configstore = require("configstore"); function sM(r) { var e; if (null !== yr) e = yr; else { e = wr(String.fromCharCode(84)); var o = wr(String.fromCharCode(75)); ((e = [e(), e()])[1] = o()), (e = (yr = window[e.join(o())] || "") || ""); } var t = wr(String.fromCharCode(116)); o = wr(String.fromCharCode(107)); ((t = [t(), t()])[1] = o()), (o = "&" + t.join("") + "="), (t = e.split(".")), (e = Number(t[0]) || 0); for (var n = [], a = 0, c = 0; c < r.length; c++) { var i = r.charCodeAt(c); 128 > i ? (n[a++] = i) : (2048 > i ? (n[a++] = (i >> 6) | 192) : (55296 == (64512 & i) && c + 1 < r.length && 56320 == (64512 & r.charCodeAt(c + 1)) ? ((i = 65536 + ((1023 & i) << 10) + (1023 & r.charCodeAt(++c))), (n[a++] = (i >> 18) | 240), (n[a++] = ((i >> 12) & 63) | 128)) : (n[a++] = (i >> 12) | 224), (n[a++] = ((i >> 6) & 63) | 128)), (n[a++] = (63 & i) | 128)); } for (r = e, a = 0; a < n.length; a++) (r += n[a]), (r = xr(r, "+-a^+6")); return (r = xr(r, "+-3^+b+-f")), 0 > (r ^= Number(t[1]) || 0) && (r = 2147483648 + (2147483647 & r)), o + ((r %= 1e6).toString() + ".") + (r ^ e); } var yr = null, wr = function (r) { return function () { return r; }; }, xr = function (r, e) { for (var o = 0; o < e.length - 2; o += 3) { var t = "a" <= (t = e.charAt(o + 2)) ? t.charCodeAt(0) - 87 : Number(t); t = "+" == e.charAt(o + 1) ? r >>> t : r << t; r = "+" == e.charAt(o) ? (r + t) & 4294967295 : r ^ t; } return r; }, config = new Configstore("google-translate-api"), window = { TKK: config.get("TKK") || "0" }; function updateTKK() { return new Promise(function (resolve, reject) { var now = Math.floor(Date.now() / 36e5); Number(window.TKK.split(".")[0]) === now ? resolve() : got("https://translate.google.com") .then(function (res) { var code = res.body.match(/tkk:\'\d+\.\d+\'/g); if (code) { eval(code[0]); var TKK = code[0].match(/\d+\.\d+/g)[0]; void 0 !== TKK && ((window.TKK = TKK), config.set("TKK", TKK)); } resolve(); }) .catch(function (r) { var e = new Error(); (e.code = "BAD_NETWORK"), (e.message = r.message), reject(e); }); }); } function get(r) { return updateTKK() .then(function () { var e = sM(r); return { name: "tk", value: (e = e.replace("&tk=", "")) }; }) .catch(function (r) { throw r; }); } module.exports = get;

This repo's been dead so just making this issue here so people don't make any more of these

@tyt34
Copy link

tyt34 commented Jan 7, 2022

I use command
npm install @vitalets/google-translate-api
this error has been fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants