Skip to content

Commit

Permalink
add fallback sign server
Browse files Browse the repository at this point in the history
  • Loading branch information
zerodytrash committed Aug 19, 2023
1 parent 75ef60a commit c45dc5c
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/lib/tiktokSignatureProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const axios = require('axios').create({
let config = {
enabled: true,
signProviderHost: 'https://tiktok.eulerstream.com/',
signProviderFallbackHosts: ['https://tiktok-sign.zerody.one/'],
extraParams: {},
};

Expand All @@ -33,8 +34,26 @@ async function signRequest(providerPath, url, headers, cookieJar) {

params.uuc = getUuc();

let signHost;
let signResponse;
let signError;

try {
let signResponse = await axios.get(config.signProviderHost + providerPath, { params, responseType: 'json' });
for (signHost of [config.signProviderHost, ...config.signProviderFallbackHosts]) {
try {
signResponse = await axios.get(signHost + providerPath, { params, responseType: 'json' });

if (signResponse.status === 200 && typeof signResponse.data === 'object') {
break;
}
} catch (err) {
signError = err;
}
}

if (!signResponse) {
throw signError;
}

if (signResponse.status !== 200) {
throw new Error(`Status Code: ${signResponse.status}`);
Expand All @@ -53,6 +72,7 @@ async function signRequest(providerPath, url, headers, cookieJar) {
}

signEvents.emit('signSuccess', {
signHost,
originalUrl: url,
signedUrl: signResponse.data.signedUrl,
headers,
Expand All @@ -62,6 +82,7 @@ async function signRequest(providerPath, url, headers, cookieJar) {
return signResponse.data.signedUrl;
} catch (error) {
signEvents.emit('signError', {
signHost,
originalUrl: url,
headers,
cookieJar,
Expand Down

0 comments on commit c45dc5c

Please sign in to comment.